问题
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.
Following are my questions,
- Is there any way I execute my tests faster on simulator specially when entering in textfields through sendkeys() function?
- Is there any way I can run my tests without simulator in headless fashion?
回答1:
Don't use send keys on iOS
You're actually not supposed to use sendKeys
on iOS because it's slow and flakey.
You're supposed to use setValue
for the Java lib and type
for the ruby lib
Set Value usage
setValue
is defined in Java library here.
It is meant to be called on a WebElement.
driver.find_element(By.locator(value)).setValue("foo")
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.
Other best practices for optimization
- Do not use "sleeps" to try and wait for an element -- instead constantly poll the driver for if the element is displayed and clickable.
- Use
setValue
instead of sendKeys - Stop using Xpath locator strategy. It is flakey and slow on iOS. Use UIAutomation or AccessibilityId locator strategy.
- Only get the elements when you need to interact with them
*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.
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.
回答2:
where can I find more info on this suggestion (I'm using ruby instead of java) and I xpath a lot which I guess might be one of the reasons scripts take too long to execute.
"Stop using Xpath locator strategy. It is flakey and slow on iOS. Use UIAutomation or AccessibilityId locator strategy."
回答3:
You can set the iOS capability of sendKeyStrategy to setValue instead of the default of OneByOne.
来源:https://stackoverflow.com/questions/25915967/how-to-make-appium-tests-run-faster-on-ios