ios - 使用node appium-xcuitest-driver测试ios应用程序

标签 ios node.js react-native appium functional-testing

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/

相关文章:

ios - iPhone 上的 CoreMotion Bump 与 Shake

ios - 这些闭包中的保留周期有什么区别?标准闭包与对象初始化闭包

node.js - 如何在 NodeJS/ExpressJS 中连接两个数组

javascript - 具有独立状态的动态生成的复选框 React-Native

React-Native ListView onPress - 未定义不是对象

ios - 从概念上讲,子类化 UIView 是否正确?

ios - 在不规则形状图像上添加相机图层 IOS

node.js - ESLint 规则在用户模块和标准 Node 模块之间插入一个空行

javascript - Nodejs 请求返回行为不当

android - 将一个组件替换为另一个组件,构建失败并出现错误 "Could not resolve project <old component name>"