Thursday, October 12, 2017

Automate your iOS mobile application tests in 10 minutes

The Automate It! Test Automation Framework open source project literally enables your test developers to automate your entire application or parts of your application screen in merely 10 minutes.

As a demonstration, I have put together a simple Login Screen login on a demo iOS mobile application, similar to what most applications present to a user upon entering their product or service.



This app is simple: The user enters a username and password and then clicks on the Login button to login.

There are several use cases we can drive using data to completely test this authentication feature within 10 minutes - development and test time COMBINED!

So here are some of the test obvious test cases:


  • User logs in successfully with a valid username and password.
  • The user tries different combinations of incorrect username and password - perhaps forgetting either the username or password for their account.
  • The user tries backdoor hacking with blank username and password combinations hoping to find a flaw in the system.


AutomateIt! Test Automation has you covered.

All you need to do is map the application using Appium Desktop application for v1.7.1 server and embed them in a simple java class indicating the resource id's (or perhaps obtain an Xpath element locator via Appium Desktop) and away you will go.

Here is a screenshot of rendering the App in Appium Desktop and letting it tell you what the element locators are:



So now we embed them in a very elegant class structure: a base class and an iOS-specific class. Why not just one single class? Because then we can map our iOS app and use the existing base classes to drive those tests also with 10% of the effort to create the framework and iOS-specific screen classes (which only took us 10 minutes anyways!).

The test classes use the screen interactivity capability of these Login screen classes to drive tests using a data file - no hard coding!

Ok, here are the steps to run these tests on your system;
  1.  Download (free and open-source) AutomateIt! Test Automation Framework here (this example is included): https://github.com/SWAutoTester/automateit
  2. Make sure that the latest Java and Ant is installed on your system
  3. Install Xcode 9 (no actual device required!)
  4. Install appium as a service and start it: http:// appium.io
  5. Open the file for edit: /conf/configuration.properties.ios.properties and change the "app_location" property to the directory where you downloaded the AutomateItIOSDempApp.ipa file (included in the download as a demo application) in "resources/ios/" directory.
  6. Navigate to the directory that you downloaded the framework, and open up a terminal window command prompt.
  7. Change directory to <download_directory>. Then type "ant ios".
  8. The test will run and finish in 5 minutes.
  9. Navigate to "results/html/index.html" to see the results and additional information included in the report: framework/webdriver commands list, screenshots, video's in AVI and MOV format that recorded the tests for you.


Give it a try, and contact me if you any problems.

The code resides here:

/automateit/src/org/automateit/example/screen
/automateit/src/org/automateit/example/test
/automateit/conf/configuration.properties.ios.properties
/automateit/data/login.csv

Here is some code to show you how easy it is using a data-driven input file:

    /**
     * Try to login
     * 
     * @param usernameDataSetId
     * @param passwordDataSetId
     * 
     * @throws Exception 
     */
    public void executeLoginAttempt(String usernameDataSetId, String passwordDataSetId) throws Exception {
      
        try { 
            
            if(usernameDataSetId != null) loginScreen.enterUsername(testData.returnInputDataForDataIdAndColumnNumber(usernameDataSetId, 1));
            else loginScreen.enterUsername("");
            
            if(passwordDataSetId != null) loginScreen.enterPassword(testData.returnInputDataForDataIdAndColumnNumber(passwordDataSetId, 1));
            else loginScreen.enterPassword("");
            
            loginScreen.clickLoginButton();
            
        }
        catch(Exception e) { throw e; }
    
    }

This does the actual interaction with the login screen:

    /**
     * Enter text into the Username text field.
     * 
     * @param username The username
     * 
     * @throws Exception 
     */
    public void enterUsername(String username) throws Exception {
        
        try {
            
            clearWebElementByResourceId(resourceId_textfield_username);
            
            enterDataIntoWebElementByResourceId(resourceId_textfield_username, username);
           
        }
        catch(Exception e) { throw e; }
        
    }
    
    /**
     * Enter text into the Password text field.
     * 
     * @param password The password
     * 
     * @throws Exception 
     */
    public void enterPassword(String password) throws Exception {
        
        try {
            
            clearWebElementByResourceId(resourceId_textfield_password);
            
            enterDataIntoWebElementByResourceId(resourceId_textfield_password, password);
            
        }
        catch(Exception e) { throw e; }
    }
    
    /**
     * Click/Tap on the "Sign In" button.
     * 
     * @throws Exception 
     */
    public void clickLoginButton() throws Exception {
        
        try { clickUsingResourceId(resourceId_button_login); }
        catch(Exception e) { throw e; }
        
    }



Notice in this code snippet that you dont have to have any knowledge of WebDriver because the framework handles all of that for you so you can focus only our your application.

No comments:

Post a Comment