Skip to content

Commit 543190f

Browse files
Zdravko BranzovZdravko Branzov
authored andcommitted
Use one test for all platforms
1 parent 848e1f0 commit 543190f

File tree

8 files changed

+92
-81
lines changed

8 files changed

+92
-81
lines changed

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: 44 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ describe("facebook tests", function () {
55
this.timeout(100000);
66
var driver;
77
const FACEBOOK_BUTTON = "fbLogin";
8-
const USERNAME = "open_qgonlya_user@tfbnw.net";
8+
const USERNAME = "nativescript_gctpjih_user@tfbnw.net";
99
const PASSWORD = "P@ssw0rd";
1010
const CUSTOM_LOGOUT_BUTTON = "customLogOut";
11-
const USER_ID = "UserId: 132396757312450";
11+
const USER_NAME = "Nativescript User";
12+
var timeout = 10000;
1213

1314
before(function () {
1415
driver = nsAppium.createDriver();
@@ -21,78 +22,48 @@ describe("facebook tests", function () {
2122
console.log("Driver quit successfully");
2223
});
2324
});
24-
//=============================== ANDROID TESTS ==========================
25-
if(isAndroid){
26-
describe("android tests", function () {
2725

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-
});
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+
}
4540

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-
});
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+
});
8460

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-
}
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+
});
9869
});

demo/package.json

Lines changed: 4 additions & 4 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": {
@@ -30,7 +30,7 @@
3030
"karma-nativescript-launcher": "^0.4.0",
3131
"lazy": "1.0.11",
3232
"nativescript-css-loader": "~0.26.0",
33-
"nativescript-dev-appium": "^0.3.0",
33+
"nativescript-dev-appium": "~0",
3434
"nativescript-dev-typescript": "^0.4.0",
3535
"nativescript-dev-webpack": "^0.4.0",
3636
"raw-loader": "~0.5.1",
@@ -48,4 +48,4 @@
4848
"build-android-bundle": "npm run ns-bundle --android --build-app",
4949
"build-ios-bundle": "npm run ns-bundle --ios --build-app"
5050
}
51-
}
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)