|
1 | 1 | var path = require('path'); |
2 | 2 | var assert = require('assert'); |
3 | 3 |
|
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(); |
9 | 9 |
|
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 }); |
15 | 12 |
|
16 | 13 | var testElement = null; |
17 | 14 |
|
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 { |
26 | 21 | var screenshotPath = path.resolve(__dirname, 'screenshot.png'); |
27 | | - browser.saveScreenshot(screenshotPath); |
| 22 | + await browser.saveScreenshot(screenshotPath); |
28 | 23 | console.log('Screenshot stored at ' + screenshotPath); |
29 | 24 | throw new Error('Cannot find the needed TextView element from app'); |
30 | 25 | } |
31 | 26 |
|
32 | | - var matchedString = testElement.getText(); |
| 27 | + var matchedString = await testElement.getText(); |
33 | 28 | console.log(matchedString); |
34 | 29 | assert(matchedString.indexOf('The active connection is wifi') !== -1); |
35 | 30 | assert(matchedString.indexOf('Up and running') !== -1); |
|
0 commit comments