iOS Testing using Automation of Instruments

Quality is very important for us, for that reason we are fond of automation testing. This post is going to be focused on how to automated iOS testing.

Things to take into account before starting are:

  • validating that the tests finish as expected.
  • leaving the app in the initial state, which assures that each test can be run independently.

How can you get started automating iOS testing?

Automation of Instruments is a great test automation tool for iOS. It is simple. The only thing needed is to have Xcode (the IDE to develop on iOS) installed, and nothing else. In Xcode, click on “Open Develop Tools”, then click on “Instruments” and afterwards select “automation”.

The first step is to choose the target (device and app). Simulator or a real device could be chosen.

iOS Testing

Then, click “add” to create or to import a script (javaScript file). Now it is possible to click on the red button and the program will generate a code which replicates what we are doing in the selected device. Or also you can write the script yourself. The best thing, is to record the steps you would like to test and, once it is done, modify what is needed.

And remember to record the steps including those needed to put the app in its initial state.

 

What code should be added?

As mentioned above, one thing to be added is the validation of the test: whether the test finishes as expected or not. You should check if some element is enabled or visible, for example, to determine if the test has ended correctly.

These functions could help us:

  • isVisible() : determines if the element is visible
  • isEnabled() : determines if an element is enabled
  • isValid() or checkIsvalid() : determines if the element exists

Beside, another thing that needs to be added is the log commands. A test should begin with “logStart” and, finish using a command that shows the result of the test. These are the commands that can be used:

  • logStart : Logs a message and indicates a test has started.
  • logFail : Logs a message and indicates a test has completed unsuccessfully.
  • logIssue : Logs a message and indicates a test has terminated abnormally.
  • logPass : Logs a message and indicates a test has completed successfully.

Example


var testName= ‘My First Test’
UIALogger.logStart(testName);
...
if(element.isValid()){
    UIALogger.logPass(testName);
}else{
    UIALogger.logFail(testName);
}

Also, a good trick is, if the test does not work after recording several actions, first of all, add UIATarget.delay(1) between commands. In most of the cases, only a small delay is needed to solve the problem.

Once the script is done, we could save it as .trace or also by clicking with right button to export to javaScript.
It is very important to export to javaScript, because it will be needed to keep going on Continuous Integration.

Moreover, other useful functions and how to integrate these tests with jenkins (to improve continuous integration) will be posted soon.

What do you think about mobile applications testing?

2 thoughts on “iOS Testing using Automation of Instruments”

  1. Hello, I need to automate iOS tests written in Appium (Python) and integrate them with jenkins. Is it possible to run the tests without simulator (headlessly) on jenkins?

    Reply
  2. Hello,
    To run automate test for iOS, there are several option: use a simulator or a real device or even using a device farm.
    Thank you for your comment

    Reply

Leave a Comment

¿Necesitas una estimación?

Calcula ahora

Privacy Preference Center

Own cookies

__unam, gdpr 1P_JAR, DV, NID, _icl_current_language

Analytics Cookies

This cookies help us to understand how users interact with our site

_ga, _gat_UA-42883984-1, _gid, _hjIncludedInSample,

Subscription Cookies

These cookies are used to execute functions of the Web, such as not displaying the advertising banner and / or remembering the user's settings within the session.

tl_3832_3832_2 tl_5886_5886_12 tve_leads_unique

Other