Skip to content

Instantly share code, notes, and snippets.

@henrikhaugboelle
Last active February 16, 2021 08:28
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henrikhaugboelle/82a652961057d24a96579054b19f589c to your computer and use it in GitHub Desktop.
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.
/**
* 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)
})
})
{
"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