Skip to content

Commit 21f0653

Browse files
committed
switch to async mode and fix local tunnel closing error
1 parent cff6f6b commit 21f0653

File tree

16 files changed

+176
-168
lines changed

16 files changed

+176
-168
lines changed

android/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"description": "Selenium examples for WebdriverIO and BrowserStack App Automate",
66
"scripts": {
77
"test": "npm run single && npm run local && npm run parallel",
8-
"single": "./node_modules/.bin/wdio run_first_test/first.conf.js",
8+
"first": "./node_modules/.bin/wdio run_first_test/first.conf.js",
99
"parallel": "./node_modules/.bin/wdio run_parallel_test/parallel.conf.js",
1010
"local": "./node_modules/.bin/wdio run_local_test/local.conf.js",
1111
"multiple": "./node_modules/.bin/wdio run_multiple_test/multiple.conf.js"
@@ -28,7 +28,6 @@
2828
"@wdio/cli": "^5.20.1",
2929
"@wdio/local-runner": "^5.20.1",
3030
"@wdio/mocha-framework": "^5.18.7",
31-
"@wdio/sync": "^5.20.1",
3231
"browserstack-local": "^1.4.5"
3332
}
3433
}
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
var assert = require('assert');
22

3-
describe('Search Wikipedia Functionality', function () {
4-
it('can find search results', function () {
5-
var searchSelector = $(`~Search Wikipedia`);
6-
searchSelector.waitForDisplayed({ timeout: 30000 });
7-
searchSelector.click();
3+
describe('Search Wikipedia Functionality', () => {
4+
it('can find search results', async () => {
5+
var searchSelector = await $(`~Search Wikipedia`);
6+
await searchSelector.waitForDisplayed({ timeout: 30000 });
7+
await searchSelector.click();
88

9-
var insertTextSelector = $('android=new UiSelector().resourceId("org.wikipedia.alpha:id/search_src_text")');
10-
insertTextSelector.waitForDisplayed({ timeout: 30000 });
9+
var insertTextSelector = await $('android=new UiSelector().resourceId("org.wikipedia.alpha:id/search_src_text")');
10+
await insertTextSelector.waitForDisplayed({ timeout: 30000 });
1111

12-
insertTextSelector.addValue("Browsertack");
13-
browser.pause(5000);
12+
await insertTextSelector.addValue("Browsertack");
13+
await browser.pause(5000);
1414

15-
var allProductsName = $$(`android.widget.TextView`);
15+
var allProductsName = await $$(`android.widget.TextView`);
1616
assert(allProductsName.length > 0);
1717
});
1818
});

android/run_local_test/local.conf.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ exports.config = {
3636
},
3737

3838
// Code to start browserstack local before start of test
39-
onPrepare: function (config, capabilities) {
39+
onPrepare: (config, capabilities) => {
4040
console.log("Connecting local");
41-
return new Promise(function(resolve, reject){
41+
return new Promise( (resolve, reject) => {
4242
exports.bs_local = new browserstack.Local();
43-
exports.bs_local.start({'key': exports.config.key }, function(error) {
43+
exports.bs_local.start({'key': exports.config.key }, (error) => {
4444
if (error) return reject(error);
4545
console.log('Connected. Now testing...');
4646

@@ -50,7 +50,15 @@ exports.config = {
5050
},
5151

5252
// Code to stop browserstack local after end of test
53-
onComplete: function (capabilties, specs) {
54-
exports.bs_local.stop(function() {});
53+
onComplete: (capabilties, specs) => {
54+
console.log("Closing local tunnel");
55+
return new Promise( (resolve, reject) => {
56+
exports.bs_local.stop( (error) => {
57+
if (error) return reject(error);
58+
console.log("Stopped BrowserStackLocal");
59+
60+
resolve();
61+
});
62+
});
5563
}
5664
};

android/run_local_test/specs/local_test.js

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,30 @@
11
var path = require('path');
22
var assert = require('assert');
33

4-
describe('BrowserStack Local Testing', function () {
5-
it('can check tunnel working', function () {
6-
var searchSelector = $('android=new UiSelector().resourceId("com.example.android.basicnetworking:id/test_action")');
7-
searchSelector.waitForDisplayed({ timeout: 30000 });
8-
searchSelector.click();
4+
describe('BrowserStack Local Testing', () => {
5+
it('can check tunnel working', async () => {
6+
var searchSelector = await $('android=new UiSelector().resourceId("com.example.android.basicnetworking:id/test_action")');
7+
await searchSelector.waitForDisplayed({ timeout: 30000 });
8+
await searchSelector.click();
99

10-
var insertTextSelector = $(`android.widget.TextView`);
11-
insertTextSelector.waitForDisplayed({ timeout: 30000 });
12-
13-
var allTextElements = $$(`android.widget.TextView`);
14-
browser.pause(10000);
10+
var insertTextSelector = await $(`android.widget.TextView`);
11+
await insertTextSelector.waitForDisplayed({ timeout: 30000 });
1512

1613
var testElement = null;
1714

18-
allTextElements.forEach(function (textElement) {
19-
var textContent = textElement.getText();
20-
if (textContent.indexOf('The active connection is') !== -1) {
21-
testElement = textElement;
22-
}
23-
});
24-
25-
if (testElement === null) {
15+
try {
16+
var textElement = await $('android=new UiSelector().textContains("active connection is")');
17+
await textElement.waitForDisplayed({ timeout: 30000 });
18+
testElement = textElement;
19+
}
20+
catch {
2621
var screenshotPath = path.resolve(__dirname, 'screenshot.png');
27-
browser.saveScreenshot(screenshotPath);
22+
await browser.saveScreenshot(screenshotPath);
2823
console.log('Screenshot stored at ' + screenshotPath);
2924
throw new Error('Cannot find the needed TextView element from app');
3025
}
3126

32-
var matchedString = testElement.getText();
27+
var matchedString = await testElement.getText();
3328
console.log(matchedString);
3429
assert(matchedString.indexOf('The active connection is wifi') !== -1);
3530
assert(matchedString.indexOf('Up and running') !== -1);
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
var assert = require('assert');
22

3-
describe('Search Wikipedia Functionality', function () {
4-
it('can find search results', function () {
5-
var searchSelector = $(`~Search Wikipedia`);
6-
searchSelector.waitForDisplayed({ timeout: 30000 });
7-
searchSelector.click();
3+
describe('Search Wikipedia Functionality', () => {
4+
it('can find search results', async () => {
5+
var searchSelector = await $(`~Search Wikipedia`);
6+
await searchSelector.waitForDisplayed({ timeout: 30000 });
7+
await searchSelector.click();
88

9-
var insertTextSelector = $('android=new UiSelector().resourceId("org.wikipedia.alpha:id/search_src_text")');
10-
insertTextSelector.waitForDisplayed({ timeout: 30000 });
9+
var insertTextSelector = await $('android=new UiSelector().resourceId("org.wikipedia.alpha:id/search_src_text")');
10+
await insertTextSelector.waitForDisplayed({ timeout: 30000 });
1111

12-
insertTextSelector.addValue("Browsertack 01");
13-
browser.pause(5000);
12+
await insertTextSelector.addValue("Browsertack01");
13+
await browser.pause(5000);
1414

15-
var allProductsName = $$(`android.widget.TextView`);
15+
var allProductsName = await $$(`android.widget.TextView`);
1616
assert(allProductsName.length > 0);
1717
});
1818
});
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
var assert = require('assert');
22

3-
describe('Search Wikipedia Functionality', function () {
4-
it('can find search results', function () {
5-
var searchSelector = $(`~Search Wikipedia`);
6-
searchSelector.waitForDisplayed({ timeout: 30000 });
7-
searchSelector.click();
3+
describe('Search Wikipedia Functionality', () => {
4+
it('can find search results', async () => {
5+
var searchSelector = await $(`~Search Wikipedia`);
6+
await searchSelector.waitForDisplayed({ timeout: 30000 });
7+
await searchSelector.click();
88

9-
var insertTextSelector = $('android=new UiSelector().resourceId("org.wikipedia.alpha:id/search_src_text")');
10-
insertTextSelector.waitForDisplayed({ timeout: 30000 });
9+
var insertTextSelector = await $('android=new UiSelector().resourceId("org.wikipedia.alpha:id/search_src_text")');
10+
await insertTextSelector.waitForDisplayed({ timeout: 30000 });
1111

12-
insertTextSelector.addValue("Browsertack 02");
13-
browser.pause(5000);
12+
await insertTextSelector.addValue("Browsertack02");
13+
await browser.pause(5000);
1414

15-
var allProductsName = $$(`android.widget.TextView`);
15+
var allProductsName = await $$(`android.widget.TextView`);
1616
assert(allProductsName.length > 0);
1717
});
1818
});
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
var assert = require('assert');
22

3-
describe('Search Wikipedia Functionality', function () {
4-
it('can find search results', function () {
5-
var searchSelector = $(`~Search Wikipedia`);
6-
searchSelector.waitForDisplayed({ timeout: 30000 });
7-
searchSelector.click();
3+
describe('Search Wikipedia Functionality', () => {
4+
it('can find search results', async () => {
5+
var searchSelector = await $(`~Search Wikipedia`);
6+
await searchSelector.waitForDisplayed({ timeout: 30000 });
7+
await searchSelector.click();
88

9-
var insertTextSelector = $('android=new UiSelector().resourceId("org.wikipedia.alpha:id/search_src_text")');
10-
insertTextSelector.waitForDisplayed({ timeout: 30000 });
9+
var insertTextSelector = await $('android=new UiSelector().resourceId("org.wikipedia.alpha:id/search_src_text")');
10+
await insertTextSelector.waitForDisplayed({ timeout: 30000 });
1111

12-
insertTextSelector.addValue("Browsertack 03");
13-
browser.pause(5000);
12+
await insertTextSelector.addValue("Browsertack03");
13+
await browser.pause(5000);
1414

15-
var allProductsName = $$(`android.widget.TextView`);
15+
var allProductsName = await $$(`android.widget.TextView`);
1616
assert(allProductsName.length > 0);
1717
});
1818
});
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
var assert = require('assert');
22

3-
describe('Search Wikipedia Functionality', function () {
4-
it('can find search results', function () {
5-
var searchSelector = $(`~Search Wikipedia`);
6-
searchSelector.waitForDisplayed({ timeout: 30000 });
7-
searchSelector.click();
3+
describe('Search Wikipedia Functionality', () => {
4+
it('can find search results', async () => {
5+
var searchSelector = await $(`~Search Wikipedia`);
6+
await searchSelector.waitForDisplayed({ timeout: 30000 });
7+
await searchSelector.click();
88

9-
var insertTextSelector = $('android=new UiSelector().resourceId("org.wikipedia.alpha:id/search_src_text")');
10-
insertTextSelector.waitForDisplayed({ timeout: 30000 });
9+
var insertTextSelector = await $('android=new UiSelector().resourceId("org.wikipedia.alpha:id/search_src_text")');
10+
await insertTextSelector.waitForDisplayed({ timeout: 30000 });
1111

12-
insertTextSelector.addValue("Browsertack");
13-
browser.pause(5000);
12+
await insertTextSelector.addValue("Browsertack");
13+
await browser.pause(5000);
1414

15-
var allProductsName = $$(`android.widget.TextView`);
15+
var allProductsName = await $$(`android.widget.TextView`);
1616
assert(allProductsName.length > 0);
1717
});
1818
});

ios/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"description": "Selenium examples for WebdriverIO and BrowserStack App Automate",
66
"scripts": {
77
"test": "npm run single && npm run local && npm run parallel",
8-
"single": "./node_modules/.bin/wdio run_first_test/first.conf.js",
8+
"first": "./node_modules/.bin/wdio run_first_test/first.conf.js",
99
"parallel": "./node_modules/.bin/wdio run_parallel_test/parallel.conf.js",
1010
"local": "./node_modules/.bin/wdio run_local_test/local.conf.js",
1111
"multiple": "./node_modules/.bin/wdio run_multiple_test/multiple.conf.js"
@@ -25,10 +25,9 @@
2525
},
2626
"homepage": "https://github.com/browserstack/webdriverio-appium-app-browserstack#readme",
2727
"dependencies": {
28+
"browserstack-local": "^1.4.5",
2829
"@wdio/cli": "^5.20.1",
2930
"@wdio/local-runner": "^5.20.1",
30-
"@wdio/mocha-framework": "^5.18.7",
31-
"@wdio/sync": "^5.20.1",
32-
"browserstack-local": "^1.4.5"
31+
"@wdio/mocha-framework": "^5.18.7"
3332
}
3433
}

ios/run_first_test/specs/first_test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
var assert = require('assert');
22

3-
describe('Text Verification', function () {
4-
it('should match displayed text with input text', function () {
5-
var textButton = $(`~Text Button`);
6-
textButton.waitForDisplayed({ timeout: 30000 });
7-
textButton.click();
3+
describe('Text Verification', () => {
4+
it('should match displayed text with input text', async () => {
5+
var textButton = await $(`~Text Button`);
6+
await textButton.waitForDisplayed({ timeout: 30000 });
7+
await textButton.click();
88

9-
var textInput = $(`~Text Input`);
10-
textInput.waitForDisplayed({ timeout: 30000 });
11-
textInput.click()
12-
textInput.addValue("[email protected]"+"\n");
9+
var textInput = await $(`~Text Input`);
10+
await textInput.waitForDisplayed({ timeout: 30000 });
11+
await textInput.click()
12+
await textInput.addValue("[email protected]"+"\n");
1313

14-
var textOutput = $(`~Text Output`);
15-
textOutput.waitForDisplayed({ timeout: 30000 });
16-
var value = textOutput.getText();
14+
var textOutput = await $(`~Text Output`);
15+
await textOutput.waitForDisplayed({ timeout: 30000 });
16+
var value = await textOutput.getText();
1717

1818
if (value === "[email protected]")
1919
assert(true)

0 commit comments

Comments
 (0)