Mobile Automation Testing with Robot Framework and Appium for iOS
Mobile Automation Testing on iOS
In this blogpost, we will discuss Mobile Automation testing with Robot Framework and Appium Library using PyCharm IDE.
I have put this article as simple as possible into 3 points as mentioned below. Let's start!
App under test : com.apple.reminders
- Set Up
- Open Appium GUI Server and Appium Inspector
- Test Automation Framework
1. Set Up: The setup is a bit tedious but it's worthwhile to see running the automation tests.
We need to install the following step by step.
- Install Java : Download Java from Oracle from the link below. Install from this link Java8-Mac-Download
- Set up your bash profile or .zshrc file : Once you've installed Java now set your environment variables
nano ~/.zshrc
(OR)
open ~/.zshrc
and Add the below to your .zshrc file:
export JAVA_HOME=/usr/libexec/java_home
export PATH=${JAVA_HOME}/bin:$PATH
After this run this command on Terminal "source ~/.zshrc"
- Install Homebrew : Go to the page Homebrew for reference. Run the command below on your terminal to install Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Install Node: Run the command "brew install node" on your terminal
- Install Appium : npm install -g appium
Download Appium Inspector from the link : Appium-Inspector
Alternatively, you can run "brew install --cask appium" on your terminal.
You install both ways that is from the UI and CLI so that sometimes it will be handy running appium server from terminal and inspecting elements with Appium Inspector.
Run command "appium -v" on your terminal to check the version installed.
Note: In earlier versions of appium both Appium Server and Appium Inspector are in one GUI but now it is changed and both Server and Appium Inspector are separated.
From the UI once downloaded, Open the Appium Server and it looks like this
Open Appium Inspector which is downloaded from above.
Right click and 'open'
- Install Python: Use this link: Python to download the latest version of Python
Once downloaded, Run the below commands on your terminal
python3 --version
pip3 --version
- Install Robot Framework: Run the command "pip3 install robotframework" on your terminal
- Install Robot Framework Appium Library: Run the command "pip3 install robotframework-appiumlibrary" on your terminal
- Install Pycharm IDE: Go to the page PyCharm and install the community version unless you have a specific need of Professional version
Set your Project Interpreter by adding necessary Libraries as shown below by clicking on PyCharm > Preferences > Project:Your Project Name > Python Interpreter
Also, Install Intellibot plugin from PyCharm > Preferences > Plugins
For parallelisation of your tests, Install pabot: Run the command "pip3 install -U robotframework-pabot". This is not necessary for this blogpost. You can ignore this for now!
- Install Xcode from Apple Store: You will need an apple id for installation. Go here Create Your Apple ID to sign up if you don't have one!
Note: This may take a bit more time to install so have a little patience :)!
Once Xcode is Installed, Run this command "sudo xcode-select -s /Applications/Xcode.app" on your terminal to see your installation is good.
Open the Xcode and it should open the default Simulator for you.
Click on Simulator and select iOS version and select a device as shown below. In my case default simulator was iPhone SE but I have changed it to iPhone 12
- Install Carthage: Run the command "brew install carthage"
- Install appium-xcuitest-driver: Run the command "sudo npm i appium-xcuitest-driver"
- Install ios-deploy: Run the command "sudo npm install -g ios-deploy"
- Install idevice-installer: Run the command "brew install ideviceinstaller"
- Install appium-doctor: Run the command "npm install appium-doctor -g"
Run the command "appium-doctor --ios" to check your configurations are correct
To see list of devices in your system:
Run the command "instruments -s devices" for iOS 12 or below versions.
For iOS 13 and later, Run the command "xcrun xctrace list devices" it will list your list of devices that you can test with.
For example: iPhone 12 Simulator (15.5) (A05B3D2C-B7CE-41A2-BD62-C1F09E35761A)
To see the list of Libraries installed:
Run the command "pip3 list | grep robot"
On your terminal, run the command "appium"
Now open "Appium Inspector"
Make sure you set your capabilities as shown below. Put the value "/wd/hub" in the Remote Path field otherwise you will face an issue of connecting to the app.
{
"deviceName": "iPhone 12",
"platformName": "iOS",
"automationName": "XCUITest",
"app": "com.apple.reminders",
"udid": "A05B3D2C-B7CE-41A2-BD62-C1F09E35761A",
"platformVersion": "15.5"
}
For reference you can check this link for capabilities : Capabilities
Now click on "Start Session"
If you get an error like below, Just re-start your Appium Server and Appium Inspector close and start them again.
3. Test Automation Framework : I have created the Test Automation Framework using Screen Object Design Pattern.
I say screen object design because this is not actually different from typical page object design pattern on Web. It's just we are testing the screens on mobile, so the page from web is replaced by screen for mobile but the functionality remains the same.
Folder Structure:
Test Setup:
ScreenObjects/Locators:
While grabbing locators from Appium Inspector make sure your first priority would be "Accessibility ID" and then ID, name and xpath.
Sometimes, it's hard for you to find elements. So please ask your developer to add the Accessibility ID's or ID's for your automation testing.
*** Settings ***
Documentation Screen Objects for Landing Screen
*** Variables ***
${MY_LISTS_TITLE} xpath=//*[@label='My Lists']
${REMINDERS_LABEL} xpath=//*[@label='Reminders']
${NEW_REMINDER_LABEL} xpath=(//*[@label='New Reminder'])[1]
${ADD_LIST_LABEL} Add List
${REMINDER_COUNT_AS_ONE} xpath=//XCUIElementTypeStaticText[@name="1"]
${REMINDER_COUNT_AS_ZERO} xpath=//XCUIElementTypeStaticText[@name="0"]
*** Settings ***
Documentation Screen Objects for New Reminder Screen
*** Variables ***
${NEW_REMINDER_BUTTON} xpath=(//*[@label='New Reminder'])[1]
${TITLE_TEXT_INPUT} name=Quick Entry Title Field
${NOTES_TEXT_INPUT} name=Quick Entry Note Field
${ADD_BUTTON} xpath=//XCUIElementTypeButton[@name="Add"]
*** Settings ***
Documentation Screen Objects for Reminders List Screen
*** Variables ***
${LISTS_LABEL} xpath=(//*[@label='Lists'])[1]
${REMINDERS_SCREEN_TITLE} xpath=//*[@label='Reminders']
${TEST_TITLE} xpath=//*[contains(@value,'TEST_')]
${TEST_NOTES} name=This is for Test Demo
${EMPTY_LIST} name=Empty list
${NO_REMINDERS_LABEL} name=No Reminders
Pages/Screens: Create Screens instead of Pages which is similar to page object design.
The Screens will have the Screen Objects, necessary Libraries and Keywords required for each individual screen. The keywords are defined as for example "NewReminderScreen.ElementsVisible" which tells about the actions to be done on that particular screen.
Test Setup and Test Teardown for opening and closing the application using the appium server.
Import the necessary Libraries and Resources in the settings section.
Write all your keywords with a prefix of screen names in the Test Cases section so that the test identifies the keywords written down in different screens.
Now time to execute your test :) !
Execute your test with the command : "robot -d Report Tests/iOS*.robot"
You will get a report and log html file in case on any failures to log them for you.
Test Output: Adds a reminder for the user
Please, Also see the GitHub repo for reference : Robot-Framework
Happy Automation Testing Guys :) !
Comments
Post a Comment