Skip to content

Commit 35882b2

Browse files
Zdravko BranzovZdravko Branzov
authored andcommitted
Rewrite ui tests
1 parent 27fe2a4 commit 35882b2

File tree

8 files changed

+164
-112
lines changed

8 files changed

+164
-112
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ matrix:
6363
script:
6464
- npm i -g appium
6565
- cd demo && npm i
66-
- travis_retry npm run appium --runType=android23 --sauceLab=true --appLocation=$ANDROID_PACKAGE
66+
- travis_retry npm run e2e -- --runType android23 --sauceLab --reuseDevice --appPath $ANDROID_PACKAGE
6767
- os: linux
6868
env:
6969
- iOS="10"
@@ -72,7 +72,7 @@ matrix:
7272
script:
7373
- npm i -g appium
7474
- cd demo && npm i
75-
- travis_wait travis_retry npm run appium --runType=ios-simulator103iPhone6 --sauceLab=true --appLocation=$IOS_PACKAGE
75+
- travis_wait travis_retry npm run e2e -- --runType sim103iPhone6 --sauceLab --reuseDevice --appPath $IOS_PACKAGE
7676

7777
android:
7878
components:

appium.capabilities.json

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,45 @@
11
{
2-
"android23": {
3-
"browserName": "",
4-
"appium-version": "1.6.5",
5-
"platformName": "Android",
6-
"platformVersion": "6.0",
7-
"deviceName": "Android Emulator",
8-
"noReset": false,
9-
"app": ""
10-
11-
},
12-
"ios-simulator10iPhone6": {
13-
"browserName": "",
14-
"appium-version": "1.6.5",
15-
"platformName": "iOS",
16-
"platformVersion": "10.0",
17-
"deviceName": "iPhone 6 Simulator",
18-
"app": ""
19-
20-
},
21-
"ios-simulator103iPhone6": {
22-
"browserName": "",
23-
"appium-version": "1.6.5",
24-
"platformName": "iOS",
25-
"platformVersion": "10.3",
26-
"deviceName": "iPhone 6 Simulator",
27-
"app": ""
28-
29-
}
2+
"android23.local": {
3+
"platformName": "Android",
4+
"platformVersion": "6.0",
5+
"deviceName": "Emulator_Api23_Default",
6+
"avd": "Emulator_Api23_Default",
7+
"noReset": true
8+
},
9+
"android23": {
10+
"platformName": "Android",
11+
"platformVersion": "6.0",
12+
"deviceName": "Android Emulator",
13+
"appium-version": "1.7.1",
14+
"noReset": true
15+
},
16+
"android25": {
17+
"platformName": "Android",
18+
"platformVersion": "7.1",
19+
"deviceName": "Android GoogleAPI Emulator",
20+
"appium-version": "1.7.1",
21+
"noReset": true
22+
},
23+
"sim11iPhone6": {
24+
"platformName": "iOS",
25+
"platformVersion": "11.0",
26+
"deviceName": "iPhone 6",
27+
"appium-version": "1.7.1",
28+
"app": ""
29+
},
30+
"sim103iPhone6": {
31+
"browserName": "",
32+
"appium-version": "1.7.1",
33+
"platformName": "iOS",
34+
"platformVersion": "10.3",
35+
"deviceName": "iPhone 6",
36+
"app": ""
37+
},
38+
"sim10iPhone6": {
39+
"platformName": "iOS",
40+
"platformVersion": "10.0",
41+
"deviceName": "iPhone 6",
42+
"appium-version": "1.7.1",
43+
"app": ""
44+
}
3045
}

demo/e2e-tests/tests.js

Lines changed: 0 additions & 76 deletions
This file was deleted.

demo/e2e/config/mocha.opts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--timeout 800000
2+
--recursive e2e

demo/e2e/setup.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { startServer, stopServer } from "nativescript-dev-appium";
2+
3+
before("start server", async () => {
4+
await startServer();
5+
});
6+
7+
after("stop server", async () => {
8+
await stopServer();
9+
});

demo/e2e/test.e2e.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { AppiumDriver, createDriver, SearchOptions } from "nativescript-dev-appium";
2+
import { isSauceLab, runType } from "nativescript-dev-appium/lib/parser";
3+
import { expect } from "chai";
4+
import "mocha";
5+
6+
const isSauceRun = isSauceLab;
7+
const isAndroid: string = runType.includes("android");
8+
9+
describe("Facebook tests", async function () {
10+
const FACEBOOK_BUTTON = "fbLogin";
11+
const USERNAME = "nativescript_gctpjih_user@tfbnw.net";
12+
const PASSWORD = "P@ssw0rd";
13+
const CUSTOM_LOGOUT_BUTTON = "customLogOut";
14+
const USER_NAME = "Nativescript User";
15+
let driver: AppiumDriver;
16+
17+
before(async () => {
18+
driver = await createDriver();
19+
driver.defaultWaitTime = 15000;
20+
});
21+
22+
after(async () => {
23+
if (isSauceRun) {
24+
driver.sessionId().then(function (sessionId) {
25+
console.log("Report: https://saucelabs.com/beta/tests/" + sessionId);
26+
});
27+
}
28+
await driver.quit();
29+
console.log("Driver successfully quit");
30+
});
31+
32+
it("should log in via original button", async function () {
33+
if (isAndroid) {
34+
var userNameLabelElement = "[@text='Nativescript User']";
35+
} else {
36+
var loginButtonElement = "[@name='Log In']";
37+
var continueButtonAttribute = "[@name='Continue']";
38+
var userNameLabelElement = "[@name='Nativescript User']";
39+
}
40+
41+
const facebookButton = await driver.findElementByAccessibilityId(FACEBOOK_BUTTON);
42+
await facebookButton.click();
43+
44+
if (isAndroid) {
45+
const allFields = await driver.driver.waitForElementsByClassName(driver.locators.getElementByName("textfield"), 10000);
46+
await allFields[1].click().sendKeys(PASSWORD);
47+
await allFields[0].click().sendKeys(USERNAME);
48+
} else {
49+
const passField = await driver.driver.waitForElementByClassName(driver.locators.getElementByName("securetextfield"), 10000);
50+
await passField.click().sendKeys(PASSWORD);
51+
const usernameField = await driver.driver.waitForElementByClassName(driver.locators.getElementByName("textfield"), 10000);
52+
await usernameField.click().sendKeys(USERNAME);
53+
}
54+
await driver.driver.hideDeviceKeyboard("Done");
55+
if (isAndroid) {
56+
const logInButton = await driver.findElementByClassName(driver.locators.button);
57+
await logInButton.click();
58+
const okButton = await driver.findElementByClassName(driver.locators.button);
59+
await okButton.click();
60+
} else {
61+
const logInButton = await driver.findElementByXPath("//" + driver.locators.button + loginButtonElement);
62+
await logInButton.click();
63+
const continueButton = await driver.findElementByXPath("//" + driver.locators.button + continueButtonAttribute);
64+
await continueButton.click();
65+
}
66+
const userNameLabel = await driver.findElementByXPath("//" + driver.locators.getElementByName("label") + userNameLabelElement);
67+
const userName = await userNameLabel.text();
68+
expect(userName).to.equal(USER_NAME, "Not logged with the same user");
69+
70+
});
71+
72+
it("should log out via custom button", async function () {
73+
const facebookLogoutButton = await driver.findElementByAccessibilityId(CUSTOM_LOGOUT_BUTTON);
74+
await facebookLogoutButton.click();
75+
const facebookButton = await driver.findElementByAccessibilityId(FACEBOOK_BUTTON);
76+
expect(facebookButton).to.exist;
77+
});
78+
});

demo/e2e/tsconfig.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"target": "es6",
5+
"experimentalDecorators": true,
6+
"emitDecoratorMetadata": true,
7+
"importHelpers": false,
8+
"sourceMap":true,
9+
"types": [
10+
"node",
11+
"mocha",
12+
"chai"
13+
],
14+
"lib": [
15+
"dom",
16+
"es2015.core",
17+
"es2015.iterable",
18+
"es2016.array.include",
19+
"es2015"
20+
]
21+
}
22+
}

demo/package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,23 @@
2929
"karma-jasmine": "^1.0.2",
3030
"karma-nativescript-launcher": "^0.4.0",
3131
"lazy": "1.0.11",
32+
"mocha": "~3.5.0",
3233
"nativescript-css-loader": "~0.26.0",
33-
"nativescript-dev-appium": "^1.0.0",
34+
"nativescript-dev-appium": "^3.1.0",
3435
"nativescript-dev-typescript": "^0.4.0",
3536
"nativescript-dev-webpack": "^0.8.0",
37+
"nativescript-worker-loader": "~0.8.1",
3638
"raw-loader": "~0.5.1",
3739
"resolve-url-loader": "~2.0.2",
38-
"typescript": "~2.2.2",
3940
"tslint": "~5.4.3",
41+
"typescript": "~2.2.2",
4042
"wd": "~1.1.1",
4143
"webpack": "~2.6.1",
42-
"webpack-sources": "~1.0.1",
4344
"webpack-bundle-analyzer": "^2.8.2",
44-
"nativescript-worker-loader": "~0.8.1"
45+
"webpack-sources": "~1.0.1"
4546
},
4647
"scripts": {
4748
"ns-bundle": "ns-bundle",
48-
"appium": "nativescript-dev-appium",
4949
"build.plugin": "cd ../src && npm run build",
5050
"ci.tslint": "npm i && tslint --config '../tslint.json' 'app/**/*.ts' --exclude '**/node_modules/**'",
5151
"ci.android.build": "npm run build.plugin && tns build android",
@@ -57,6 +57,8 @@
5757
"start-android-bundle": "npm run ns-bundle --android --run-app --uglify --snapshot",
5858
"start-ios-bundle": "npm run ns-bundle --ios --run-app --uglify",
5959
"build-android-bundle": "npm run ns-bundle --android --build-app --uglify --snapshot",
60-
"build-ios-bundle": "npm run ns-bundle --ios --build-app --uglify"
60+
"build-ios-bundle": "npm run ns-bundle --ios --build-app --uglify",
61+
"e2e": "tsc -p e2e && mocha --opts ./e2e/config/mocha.opts",
62+
"compile-tests": "tsc -p e2e --watch"
6163
}
6264
}

0 commit comments

Comments
 (0)