Skip to content

Commit 848e1f0

Browse files
Zdravko BranzovZdravko Branzov
authored andcommitted
Add UI tests
1 parent d3f1784 commit 848e1f0

File tree

3 files changed

+105
-1
lines changed

3 files changed

+105
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ demo/*.d.ts
1212
demo/platforms/
1313
demo-angular/app/*.js
1414
demo-angular/*.d.ts
15-
demo-angular/platforms/
15+
demo-angular/platforms/
16+
!demo/e2e-tests/*

demo/e2e-tests/tests.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
"use strict";
2+
var nsAppium = require("nativescript-dev-appium");
3+
var isAndroid = process.env.npm_config_runtype.includes("android");
4+
describe("facebook tests", function () {
5+
this.timeout(100000);
6+
var driver;
7+
const FACEBOOK_BUTTON = "fbLogin";
8+
const USERNAME = "open_qgonlya_user@tfbnw.net";
9+
const PASSWORD = "P@ssw0rd";
10+
const CUSTOM_LOGOUT_BUTTON = "customLogOut";
11+
const USER_ID = "UserId: 132396757312450";
12+
13+
before(function () {
14+
driver = nsAppium.createDriver();
15+
});
16+
17+
after(function () {
18+
return driver
19+
.quit()
20+
.finally(function () {
21+
console.log("Driver quit successfully");
22+
});
23+
});
24+
//=============================== ANDROID TESTS ==========================
25+
if(isAndroid){
26+
describe("android tests", function () {
27+
28+
it("should log in via original button", function () {
29+
return driver
30+
.elementByAccessibilityId(FACEBOOK_BUTTON)
31+
.should.eventually.exist
32+
.click()
33+
.waitForElementsByClassName(nsAppium.getXPathElement("textfield"), 10000).first()
34+
.setText(USERNAME)
35+
.elementsByClassName(nsAppium.getXPathElement("textfield")).last() //Password field
36+
.setText(PASSWORD)
37+
.elementsByClassName(nsAppium.getXPathElement("button")).first() //Log in button
38+
.click()
39+
.sleep(3000)
40+
.waitForElementsByClassName(nsAppium.getXPathElement("button"), 10000).last() // OK button
41+
.click()
42+
.waitForElementsByClassName(nsAppium.getXPathElement("label"), 10000).last()
43+
.text().should.eventually.equal(USER_ID)
44+
});
45+
46+
it("should log out via custom button", function () {
47+
return driver
48+
.elementByAccessibilityId(CUSTOM_LOGOUT_BUTTON)
49+
.should.eventually.exist
50+
.tap()
51+
.waitForElementByAccessibilityId(FACEBOOK_BUTTON)
52+
.text().should.eventually.equal("Log in with Facebook")
53+
});
54+
});
55+
} else {
56+
//=========================================== IOS TESTS ======================================
57+
describe("ios tests", function(){
58+
59+
it("should log in via original button", function () {
60+
return driver
61+
.elementByAccessibilityId(FACEBOOK_BUTTON)
62+
.should.eventually.exist
63+
.click()
64+
// Needed for IOS because IfExists does not have timeout
65+
.sleep(5000)
66+
.elementByClassNameIfExists(nsAppium.getXPathElement("textfield"))
67+
.then(function(el){
68+
if(el){
69+
return driver
70+
.elementsByClassName(nsAppium.getXPathElement("textfield")).first()
71+
.sendKeys(USERNAME)
72+
.elementsByClassName(nsAppium.getXPathElement("securetextfield")).last() // Password field
73+
.sendKeys(PASSWORD)
74+
.elementsByClassName(nsAppium.getXPathElement("button")).nth(4) //Log in button
75+
.click()
76+
}
77+
})
78+
.waitForElementsByClassName(nsAppium.getXPathElement("button"), 10000).nth(5) // OK button
79+
.click()
80+
.sleep(2000) // Take time to change label value
81+
.elementByClassName(nsAppium.getXPathElement("label"))
82+
.text().should.eventually.equal(USER_ID)
83+
});
84+
85+
it("should log out via original button", function () {
86+
return driver
87+
.elementByAccessibilityId(FACEBOOK_BUTTON)
88+
.should.eventually.exist
89+
.click()
90+
.elementsByClassName(nsAppium.getXPathElement("button")).first() //Log out confirmation button
91+
.click()
92+
.sleep(2000) // Take time to change label value
93+
.elementByClassName(nsAppium.getXPathElement("label"))
94+
.text().should.eventually.equal("not logged in")
95+
});
96+
})
97+
}
98+
});

demo/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
"babel-traverse": "6.12.0",
2020
"babel-types": "6.11.1",
2121
"babylon": "6.8.4",
22+
"chai": "~3.5.0",
23+
"chai-as-promised": "~5.3.0",
2224
"copy-webpack-plugin": "~4.0.1",
2325
"extract-text-webpack-plugin": "~2.1.0",
2426
"filewalker": "0.1.2",
@@ -28,16 +30,19 @@
2830
"karma-nativescript-launcher": "^0.4.0",
2931
"lazy": "1.0.11",
3032
"nativescript-css-loader": "~0.26.0",
33+
"nativescript-dev-appium": "^0.3.0",
3134
"nativescript-dev-typescript": "^0.4.0",
3235
"nativescript-dev-webpack": "^0.4.0",
3336
"raw-loader": "~0.5.1",
3437
"resolve-url-loader": "~2.0.2",
3538
"typescript": "~2.2.2",
39+
"wd": "~1.1.1",
3640
"webpack": "~2.3.3",
3741
"webpack-sources": "~0.2.3"
3842
},
3943
"scripts": {
4044
"ns-bundle": "ns-bundle",
45+
"appium": "nativescript-dev-appium",
4146
"start-android-bundle": "npm run ns-bundle --android --start-app",
4247
"start-ios-bundle": "npm run ns-bundle --ios --start-app",
4348
"build-android-bundle": "npm run ns-bundle --android --build-app",

0 commit comments

Comments
 (0)