Last active
February 16, 2021 08:28
-
-
Save henrikhaugboelle/82a652961057d24a96579054b19f589c to your computer and use it in GitHub Desktop.
Example of running appium locally on android device with jest and async/await.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Example of running BrowserStacks Appium WikipediaSample test app locally | |
* using jest and async/await instead of promise chains. | |
* | |
* Before running, you should install appium and make sure that all dependencies | |
* are met with appium-doctor. Get started at: | |
* | |
* http://appium.io/docs/en/about-appium/getting-started/?lang=en | |
*/ | |
const wd = require('wd') | |
jest.setTimeout(30000) | |
describe('android', () => { | |
let driver = null | |
const desiredCapabilities = { | |
'browserName': '', | |
'appium-version': '1.7.2', | |
'platformName': 'Android', | |
'platformVersion': '8.0.0', | |
'deviceName': 'OnePlus 3', | |
'app': `${__dirname}/binaries/WikipediaSample.apk` | |
} | |
beforeAll(async () => { | |
driver = wd.promiseRemote({ | |
host: 'localhost', | |
port: 4723 | |
}) | |
driver.on('status', console.log) | |
driver.on('command', console.log) | |
driver.on('http', console.log) | |
await driver.init(desiredCapabilities) | |
}) | |
afterAll(async () => { | |
await driver.quit() | |
}) | |
it('should do something', async () => { | |
const searchElement = await driver.waitForElementById('Search Wikipedia', wd.asserters.isDisplayed && wd.asserters.isEnabled, 30000) | |
await searchElement.click() | |
const searchInput = await driver.waitForElementById('org.wikipedia.alpha:id/search_src_text', wd.asserters.isDisplayed && wd.asserters.isEnabled, 30000) | |
await searchInput.sendKeys("BrowserStack") | |
const search_results = await driver.elementsByClassName('android.widget.TextView') | |
expect(search_results.length > 0) | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "test-appium", | |
"version": "1.0.0", | |
"devDependencies": { | |
"appium": "^1.7.2", | |
"jest": "^22.4.3", | |
"wd": "^1.6.2" | |
}, | |
"scripts": { | |
"test": "jest" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment