const { XCUITestDriver } = require('appium-xcuitest-driver');
const automationConfig = {
platformName: 'iOS',
platformVersion: '11.2',
deviceName: 'iPhone 7',
app: __dirname + '/cameo.app',
bundleId: 'com.app.myapp',
};
const driver = new XCUITestDriver();
driver.createSession(automationConfig)
.then(() => {
//WHAT DO I DO NOW??
})
上面的代码打开一个 iOS 模拟器,下载我的应用程序,然后打开它。如何找到一个元素并单击它?
如果我这样做 driver.findElement(By.xpath("//whatever-xpath"))
它告诉我 By
未定义。但 By
不包含在 driver
中。我查看了 appium 文档,但 API 指南仍然是其中的 TODO >: |
我需要导入另一个模块来帮助解决这个问题吗?
经过大量谷歌搜索后,我也未能找到任何有用的代码示例。
最佳答案
如果你想使用appium-xcuitest-driver
进行e2e测试,使用 wd.js 更好更简单。围绕它的包装:
const wd = require('wd')
desired = {
platformName: 'iOS',
platformVersion: '11.1',
deviceName: 'iPhone SE',
automationName: 'XCUITest',
app: <path to app>
}
const server = {
host: 'localhost',
port: 4723
}
const driver = wd.promiseChainRemote(server)
await driver.init(desired)
const el1 = await driver.elementByAccessibilityId(<Valid Accessibility Identifier>)
const el2 = await driver.elementsByXPath(<Valid Xpath>)
还有一点:appium-xcuitest-driver repo中用于功能测试
在运行测试之前启动appium服务很重要:
- 安装appium:
npm install -g appium
- 使用简单命令
appium
启动服务
关于ios - 使用node appium-xcuitest-driver测试ios应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49544826/