What are small hacks to run your appium tests faster?

Please share if you have made small modifications to run your tests faster.

2 Likes

Don’t use implicit waits.

3 Likes
  • minimize Xpath usage. search elements by Id(Android) or AccessibilityID(iOS).
  • minimize use of “verify X element NOT FOUND” or if it is really needed set min timeout for this operation
  • iOS: do test on simulator (4 times faster any real device. NOT valid any more in 2020)
  • Android: do test with real device (faster even Genymotion)
  • use different strategy to load driver for testcases when needed client reset and not (no-reset flag). consider mostly use cases when no reset needed (starting faster)
  • consider add variable when any similar operation needed e.g.: log el_1 text, check el_1 text is not empty, check el_1 text contains something, check el_1 text size is another something ->replace with-> String tmp = el_1 and compare later only “tmp”.
  • use Google pageObjects ( https://code.google.com/p/selenium/wiki/PageObjects ) + FindBy ( example: https://github.com/appium/java-client/blob/master/src/test/java/io/appium/java_client/pagefactory_tests/AndroidPageObjectTest.java)
8 Likes

Turn off animations in Android device/emulator

2 Likes

Remove unnecessary steps/checks - every command sent to appium costs valuable time as it’s a server.

2 Likes

Cache WebElement (well, more specifically MobileElement) results if you’re checking multiple things on a single screen. This would allow you to cut out redundant element search queries to Appium. WebElements do not become invalid if you do not transition your screen.

@awang Can you provide an example scenario or code.(I’m new to selenium/Appium)

Case in point for this:

I have a list of 36 UIATableCell each with 6 UIAStaticText children. I need to extract the text from each of the 36 cells, extract just the portion of the text I want, and store it in a nested list.

At first I was executing separate Appium find_element_by_xpath(xpath_to_UIAStaticText).get_attribute("value") for each individual UIAStaticText. That’s 6 Appium calls per cell. This took 270 seconds to complete.

I then extracted all UIAStaticText from the cell using one Appium call using find_elements_by_class_name("UIAStaticText") and stored it in a list. Then performed my text extraction against the list in memory. This is just 1 Appium call per cell. This takes 67 seconds to complete.

4 Likes

Hi @pr4bh4sh,

@Christopher_Graham’s example scenario above is precisely the sort of caching you can use to speed up your tests. My situation is very similar to his. I wanted to verify some text on the screen, section-by-section. During the implementation phase of my code, I made an Appium call for each section. Although this worked, I was able to speed up the process by making just one Appium call to retrieve the elements I needed, and then I just scanned elements through the list as I verified them.

Caching your results is more important for iOS and Android, IMO. I’m not sure if it’s just me, but Instruments responds much more slowly than Uiautomator (even when I’m not using the native Instruments library).

1 Like

Thanks @Christopher_Graham and @awang Now i got it.

@Christopher_Graham Could you please explain why implicit waits are not considered good to be used with selenium/appium?

In the context of “…run your Appium tests faster…” implicit waits are bad in that they blindly apply to everything, including implicitly waiting for elements when you are testing / verifying elements that should NOT be present (login button should not be present after successful login routine). If you set a high implicit wait, such as 30, 60, or 120 seconds it’s going to wait that long before finally returning the exception you are expecting in that test. Thus the whole test is slowed down. This is why implicit wait times are usually set to a low value so as not to needlessly slow down your tests, which then negates their usefulness when you need to wait for longer periods of time.

Thanks for explaining it in detail @Christopher_Graham :relaxed: Like you explained a scenario to verify element not present. Test would wait for mentioned implicit wait time before getting failed. Can we use explicit wait in these cases? So test will consider explicit wait time over implicit wait time.

Can u let me know how to search elements using AccessibilityId in IOS of NAtive App.

Thanks

if NativeApp do not have AccessibilityId = can’t. AccessibilityId adding in code of client.
and this is possible only in Simulator.

@amedvedev Not able to launch the app in my Simulator 8.1… It crashes repeatedly.

what crashing: your client or simulator?
tried:

  • reset 8.1 simulator ?
  • test your app on real device with 8.1 ?

Let me be very clear

“Appium 1.3.5
Java client”

Im have installed my app in iOS 8.1 simulator and the app is running fine,but when invoked from appium via script it crashes repeatedly( like opens and closes in seconds).

In real device it works so fine no issues.

Basically let me know onething can i install .ipa in my iOS Simulator ???

Thanks

ipa = real device. app = simulator.

is their any ways to extract .app from .ipa ???

1 Like