如何让 appium 测试在 iOS 上运行得更快? [英] How to make appium tests run faster on iOS?

查看:36
本文介绍了如何让 appium 测试在 iOS 上运行得更快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在使用 appium 进行 iOS 应用测试,并且我已经在 mac mini 机器上用 Java 编写了测试.我正在使用 Jenkins CI 来运行我的测试.我想更快地运行我的测试,因为目前它在 iOS 模拟器上相当慢.例如,如果我通过 sendkeys() 函数(如testdata")在文本字段中输入任何值,那么在模拟器中打字速度会很慢.它首先从模拟器的键盘写入字符 't' 然后是 'e' 然后是 's' 等等.

Currently, I am using appium for iOS app testing and I have written tests in Java on mac mini machine. I’m using Jenkins CI to run my tests. I want to run my tests faster as currently its quite slow on iOS simulator. For example, if I enter any value in textfield via sendkeys() function like ’testdata’ then typing speed in emulator is slow. It first write character ’t’ then ‘e’ then ’s’ and so on from simulator’s keyboard.

以下是我的问题,

  1. 有什么方法可以让我在模拟器上更快地执行测试通过 sendkeys() 函数输入文本字段时?
  2. 有没有什么办法可以在没有模拟器的情况下以无头方式运行我的测试?

推荐答案

不要在 iOS 上使用发送键

您实际上不应该在 iOS 上使用 sendKeys,因为它很慢而且很不稳定.

Don't use send keys on iOS

You're actually not supposed to use sendKeys on iOS because it's slow and flakey.

您应该将 setValue 用于 Java 库,type 用于 ruby​​ 库

You're supposed to use setValue for the Java lib and type for the ruby lib

setValue 定义在 Java 库 此处.

setValue is defined in Java library here.

它旨在在 WebElement 上调用.

It is meant to be called on a WebElement.

driver.find_element(By.locator(value)).setValue("foo")

使用 iOS 模拟器是运行测试的最佳选择

仪器与您的应用程序交互需要实时模拟器或真实设备*.您可以遵循一些最佳实践来改进测试代码,这可能会使测试更快.

Using the iOS Simulator is the best option for running tests

A live simulator or real device* is required for Instruments to interact with your application. There are some best practices you can follow to improve your test code which will likely make the tests quicker.

  1. 不要使用睡眠"来尝试等待一个元素——而是不断轮询驱动程序,以确定该元素是否显示和可点击.
  2. 使用setValue代替sendKeys
  3. 停止使用 Xpath 定位器策略.它在 iOS 上很糟糕而且很慢.使用 UIAutomation 或 AccessibilityId 定位器策略.
  4. 仅在需要与元素交互时获取元素

*不建议使用适用于 iOS 的真实设备(当性能很重要时)

自动化真实设备在每次操作之间具有一秒的内置延迟.

*Using Real Devices for iOS is not suggested (when performance matters)

Automating a real device has a builtin delay of one second between every action.

无论 Appium 服务器有多快,或者您的测试脚本有多快,Appium 将执行"命令推送到仪器工作队列与在设备上执行之间存在延迟.

No matter how quick the Appium server is, or your test script is, there is a delay between when Appium pushes the "execute" command to the instruments work queue and when it is executed on the device.

这篇关于如何让 appium 测试在 iOS 上运行得更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆