Hi,
I’m working on native Android app automation using appium. I trying to write tests using appium-android-driver
module. I can successfully find element using ID, but got error when I trying to use XPATH.
exports.mycapabilities = {
platformName: ‘Android’,
deviceName: ‘mydevice’,
app: “/Users/dmle1/Downloads/app-pakistan-staging-debug_l.apk”,
appWaitActivity: “com.frontiercargroup.dealer.login.view.LoginActivity”,
appWaitPackage: “com.carfirst.dealer.dev”,
androidInstallTimeout: 90000
};
androidMain = require(“appium-android-driver”);
serverConfigs = require(’./…/helpers/appiumserver’);
DEFAULT_CAPS = require(’./…/helpers/caps’)
module.exports = class Application {
constructor () {
this.serverConfig = serverConfigs.local
this.desired = DEFAULT_CAPS.mycapabilities
this.driver = new androidMain.AndroidDriver();
}
async quit () {
await this.driver.deleteSession();
}
}
test itself:
const path = require(‘path’)
const test = require(‘selenium-webdriver/testing’)
const Application = require(path.resolve(‘app’, ‘Application’))
let app
test.before(async () => {
app = await new Application()
await app.driver.createSession(app.desired);
})
test.after(async () => {
await app.quit()
})
test.it(‘Login to the app’, async () => {
let loginTxb = await app.driver.findElOrEls(‘id’, ‘com.carfirst.dealer.dev:id/email’, false);
await app.driver.setValue(, loginTxb.ELEMENT);
let pswTxb = await app.driver.findElOrEls(‘id’, ‘com.carfirst.dealer.dev:id/password’, false);
await app.driver.setValue(“2017fcgtest”, pswTxb.ELEMENT);
let btn = await app.driver.findElOrEls(‘id’, ‘com.carfirst.dealer.dev:id/login’, false);
await app.driver.click(btn.ELEMENT);
let homeText = await app.driver.findElOrEls(‘xpath’, //android.widget.TextView[contains(@text, 'Home')]
, false);
})
I get error that couldn’t element. What I did wrong in this case?