Skip to content

Commit 8a6503e

Browse files
author
Zdravko
authored
Merge pull request #38 from NativeScript/zbranzov/ui-tests
ui tests
2 parents d3f1784 + 543190f commit 8a6503e

File tree

9 files changed

+123
-8
lines changed

9 files changed

+123
-8
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/*

CONTRIBUTING.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Contributing
2+
3+
Third-party patches are essential for keeping nativescript-facebook plugin great so we welcome all pull requests from everyone.
4+
5+
## Making Changes
6+
7+
* Fork the repository on GitHub
8+
* Clone the repo:
9+
10+
git clone git@github.com:<your-username>/nativescript-facebook.git
11+
12+
* Make commits of logical units.
13+
* Make sure your commit messages are in the proper format.
14+
* Add tests for your changes and make them pass. How to run tests you can find in [Testing section](#Testing)
15+
* Push your changes to a topic branch in your fork of the repository.
16+
* Submit a pull request to the **nativescript-facebook** repository.
17+
18+
## <a name='Testing'> Testing </a>
19+
20+
There are three main points in order to get nativescript-facebook e2e UI tests running locally on iOS 10 Simulator and Android api 23 Emulator. Before that if you want to take a look at the tests and make some changes find them located in `demo/e2e-tests` folder.
21+
22+
Note, that all commands below assume you have installed npm packages in /src and /demo folders (`$ npm i`) and you are using OS X in order to use both iOS Simulator and Android emulator.
23+
24+
* Install Appium. Test execution depends on [nativescript-dev-appium](https://github.com/NativeScript/nativescript-dev-appium) plugin which is added as dev dependency in `demo` app folder and first command satisfies its requirement to have appium installed.
25+
26+
$ npm install -g appium@1.6.3
27+
28+
* Run Android emulator or/and iOS Simulator. For iOS appium will run simulator if such is not running. It is a requirement for appium that Android emulator has device name 'Android Emulator' and uses Android '6.0' version. For iOS Simulator you will need similator with device name 'iPhone 7 100' which is using iOS '10.0' version. These requirements come from the nativescript-dev-appium plugin and are still hardcoded in it, but notice that plugin itself is in development and the future plans are to become the ultimate testing tool for NativeScript plugins.
29+
30+
* Navigate to /src folder and execute:
31+
32+
$ npm run ci.uitest.android
33+
34+
or
35+
36+
$ npm run ci.uitest.ios
37+
38+
That's it. You should have running UI tests in your Simulator/Emulator.

demo/app/app.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.login-buttons {
33
margin-left: 30;
44
margin-right: 30;
5-
margin-top: 80%;
5+
margin-top: 70%;
66
}
77

88
.label {
@@ -14,7 +14,7 @@
1414
.home {
1515
margin-left: 30;
1616
margin-right: 30;
17-
margin-top: 20%;
17+
margin-top: 10%;
1818
}
1919

2020
.home .buttons {

demo/app/home-page.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</StackLayout>
1212
<StackLayout class="buttons">
1313
<Facebook:LoginButton logout="{{ onLogout }}"></Facebook:LoginButton>
14-
<Button tap="{{ logout }}" text="Log out (custom)"></Button>
14+
<Button automationText="customLogOut" tap="{{ logout }}" text="Log out (custom)"></Button>
1515
</StackLayout>
1616
</StackLayout>
1717
</Page>

demo/app/login-page.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
xmlns:Facebook="nativescript-facebook"
33
loaded="pageLoaded" class="page">
44
<StackLayout class="login-buttons">
5-
<Facebook:LoginButton login="{{ onLogin }}"></Facebook:LoginButton>
5+
<Facebook:LoginButton automationText="fbLogin" login="{{ onLogin }}"></Facebook:LoginButton>
66
<Button tap="{{ login }}" text="Continue with Facebook (custom)"></Button>
77
</StackLayout>
88
</Page>

demo/e2e-tests/tests.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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 = "nativescript_gctpjih_user@tfbnw.net";
9+
const PASSWORD = "P@ssw0rd";
10+
const CUSTOM_LOGOUT_BUTTON = "customLogOut";
11+
const USER_NAME = "Nativescript User";
12+
var timeout = 10000;
13+
14+
before(function () {
15+
driver = nsAppium.createDriver();
16+
});
17+
18+
after(function () {
19+
return driver
20+
.quit()
21+
.finally(function () {
22+
console.log("Driver quit successfully");
23+
});
24+
});
25+
26+
it("should log in via original button", function () {
27+
if(isAndroid){
28+
var usernameFieldElement = "//" + nsAppium.getXPathElement("textfield") + "[@content-desc='Email or Phone']";
29+
var passwordFieldElement = "//" + nsAppium.getXPathElement("textfield") + "[@NAF='true']";
30+
var loginButtonElement = "//" + nsAppium.getXPathElement("button") + "[@text='']";
31+
var okButtonElement = "//" + nsAppium.getXPathElement("button") + "[@text='' and @instance='1']";
32+
var userNameLabelElement = "//" + nsAppium.getXPathElement("label") + "[@text='Nativescript User']";
33+
} else {
34+
var usernameFieldElement = "//" + nsAppium.getXPathElement("textfield") + "[@value='Email or Phone']";
35+
var passwordFieldElement = "//" + nsAppium.getXPathElement("securetextfield") + "[@value='Facebook Password']";
36+
var loginButtonElement = "//" + nsAppium.getXPathElement("button") + "[@name='Log In']";
37+
var okButtonElement = "//" + nsAppium.getXPathElement("button") + "[@name='OK']";
38+
var userNameLabelElement = "//" + nsAppium.getXPathElement("label") + "[@name='Nativescript User']";
39+
}
40+
41+
var step1 = driver
42+
.waitForElementByAccessibilityId(FACEBOOK_BUTTON, timeout)
43+
.should.eventually.exist
44+
.click()
45+
.waitForElementByXPath(usernameFieldElement, timeout)
46+
.sendKeys(USERNAME)
47+
.waitForElementByXPath(passwordFieldElement, timeout) //Password field
48+
.sendKeys(PASSWORD)
49+
.waitForElementByXPath(loginButtonElement, timeout) //Log in button
50+
.click();
51+
var step2 = isAndroid ? step1.sleep(6000) : step1.sleep(2000);
52+
step2
53+
.waitForElementByXPath(okButtonElement, timeout) // OK button
54+
.click();
55+
var step3 = isAndroid ? step2 : step2.sleep(5000);
56+
return step3
57+
.waitForElementByXPath(userNameLabelElement, timeout) //TODO use wait for element by text USER_ID
58+
.text().should.eventually.equal(USER_NAME);
59+
});
60+
61+
it("should log out via custom button", function () {
62+
return driver
63+
.waitForElementByAccessibilityId(CUSTOM_LOGOUT_BUTTON, timeout)
64+
.should.eventually.exist
65+
.click()
66+
.waitForElementByAccessibilityId(FACEBOOK_BUTTON, timeout)
67+
.should.eventually.exist
68+
});
69+
});

demo/package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"nativescript": {
33
"id": "org.nativescript.demo",
44
"tns-android": {
5-
"version": "3.0.0"
5+
"version": "3.0.1"
66
},
77
"tns-ios": {
8-
"version": "3.0.0"
8+
"version": "3.0.1"
99
}
1010
},
1111
"dependencies": {
@@ -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,19 +30,22 @@
2830
"karma-nativescript-launcher": "^0.4.0",
2931
"lazy": "1.0.11",
3032
"nativescript-css-loader": "~0.26.0",
33+
"nativescript-dev-appium": "~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",
4449
"build-ios-bundle": "npm run ns-bundle --ios --build-app"
4550
}
46-
}
51+
}

src/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
"ci.test.android": "cd ../demo && tns platform remove android && tns test android",
1818
"ci.test.ios.angular": "cd ../demo-angular && tns platform remove ios && tns test ios",
1919
"ci.test.android.angular": "cd ../demo-angular && tns platform remove android",
20+
"ci.uitest.ios": "cd ../demo && npm run appium --runtype=ios-simulator10",
21+
"ci.uitest.android": "cd ../demo && npm run appium --runtype=android23",
2022
"prepublish": "npm run build"
2123
},
2224
"repository": {
File renamed without changes.

0 commit comments

Comments
 (0)