Mobile test automation using Robot Framework with Python
Robot framework can be used for both web automation and mobile test automation. It can be used for both web and native mobile app automation. We use `AppiumLibrary` to handle the mobile app test automation.The beauty of the Robot Framework is that all the common activities/methods/functions are predefined as keywords in the supporting libraries like AppiumLibrary and SeleniumLibrary. Which helps to avoid writing all these common functions from scratch. So you can write you test automation faster and simpler way.
I have written a blog on How to setup Robot framework with Python on Mac, which helps to do the required installation. I suggest to go through the article here.
Okay, Now I assume you have the required setup.
My first Mobile app test automation using Python and Robot Framework on emulator
Here is the sample code for opening an app that is running on am emulator or a real device.
Lets get in to details of the above code,
Settings Section:
- I have imported the AppiumLibrary using `Library` command
Variables section:
- Variables section has all the required parameters to open the application
- APPIUM_SERVER is where the appium is running. It could be either on local machine or on remote machine
- PLATFORM_NAME is the OS of the mobile. It could be Android or IOS or …
- PLATFORM_VERSION is the version of the operating system version. If platform is Android then version can be 8.0
- DEVICE_NAME : You should know the device name. In command prompt you can run `adb devices` to know the name of the connected device for android
- APP : The absolute path of the app (.apk file in case of Android)
- PACKAGE_NAME, ACTIVITY_NAME and APP_WAIT_ACTIVITY are the app package name, main activity and wait activity of the app. App wait activity is optional
Keywords:
- I have defined one user define keyword `Open my fav app` which will invoke the app using the predefined keyword `open application`.
- The three dots (…) are used for continuation
Test cases:
- The test case is to open the app, click on some element.
- I have used one user defined keyword `Open my fav app` and predefined keyword `Click Element`
There are many useful keywords are predefined in appium library. You can refer here to know more about the keywords. Super useful guide for writing mobile app test automation using Python Robot framework.
How to run robot framework test:
Just use the simple command to run from command prompt or terminal :
pybot folder/filename.robot
I suggest first go through the keywords available in different libraries, so that you will get a clear idea, while writing Test automation using Robot Framework, on keywords. If the existing keywords are not satisfying all your tests then you can write your own keywords.
This is based on my personal learning experience. Thanks for reading, Happy learning.
Comments
Post a Comment