Appium — Mobile App Automation | Android & iOS | Running Appium Server & Emulators Systematically
Getting Spark Extent HTML & PDF report
Content
- How to run Appium server systematically?
- How to run Emulators & Simulators programmatically?
- How to run unit tests before starting automation?
- How to get different kind of reports | Html and Pdf?
- Conclusion
1. How to run Appium server systematically?
As all we know, whenever we want to execute automated tests, we have to make sure first that Appium server have already started. As an automation engineer, you may think that “I can do it just by clicking start server button, why do we need that kind of complexity to make it programmatically”.
If we run our tests only locally and only work on one specific computer, then it might seem unnecessary at the beginning, however, if we apply just a simple line of codes to our project framework, which can be seen below, then we don’t need to worry about anymore whether the server has started or not. Only then we can realize how useful it is. Additionally, if you are an automation engineer, then you should try to automate everything as much as possible :)
Because I am on macOS, Appium Driver Local Service server is equal to Mac Appium Service.
For Windows users, we just need to change Appium Driver Local Service server to Windows Appium Service.
Now, you just need to apply it in hooks class, if you are using cucumber framework. Alternatively, you can also apply it in runner class as described in my previous article. The same logic can also be applied if you are using different frameworks.
Ultimately, to stop the server, we are applying two lines of codes in our hooks class.
2. How to run Emulators & Simulators programmatically?
First, we need to create two files on project root folder. If you are on windowsOS you can also create “.bat” executable file.
Inside this folder, we just need to add two lines. The first line is path to SDK folder, and the second one is to run Android emulator. We can even click on run button to launch our emulator manually.
The same logic also applies for iOS Simulators. We have to note first the “udid” by just running “instruments -s devices” command from the command line. It gives us the whole list with platform version- and udid numbers.
After getting udid numbers we can apply it to our code. We need to boot it first with udid number, to be able to open it.
Next, we need to create one folder, in my case I named it “EmulatorManager”. Inside the folder, we create one method to apply our java logic, so that the code can be executed at run time.
Finally, we are just adding one more line to our either @BeforeClass in runner class or @Before in hooks class. Whenever we execute “mvn run” command, our emulator/simulator will automatically launch. We don’t need to care anymore whether the emulator have already launched before.
3. How to run unit tests before starting automation?
It doesn’t make sense actually to run the automation suit, if the unit tests have already failed. Especially if we are already working locally on our test scripts. So we can apply the similar algorithm which we applied for the emulators.
In my case, it is flutter project, and in order to run the unit tests, I need to go to project folder and execute “flutter test” command. I apply this logic inside startUnitTest.sh executable file as seen above. Next is actually same — just create one more method inside “EmulatorManager” class.
And add one more line inside hooks class.
4. How to get different kind of reports | Html and PDF?
To get beautiful spark extent HTML and PDF reports, we need to apply some certain steps.
First, add required dependency to “pom.xml” file.
Second, we need to create one “extent.properties” file and one “extent-config.xml” file under resources' directory.
Inside extent.properties file you need to define the path of HTML report and PDF report that you want to get your test results. The view order such as dashboard, test or device and the system information such as operating system, user or build version number can also be managed from this file.
As we see on the second line, we need to create one extent-config.xml file on the specified directory. We can manage some details such as changing theme protocol, or report name in this file. See below one example.
The final step is to add one adapter to “runner” file.
When we run now our tests, the report will be created in the defined directory — in our case under output folder. In case there is a failure, the screenshot also will be automatically created.
We can now open our HTML report with desired browser to analyze our results.
Once we click on the PDF report, it is automatically downloaded — now we can easily share our test results with our team immediately.
5. Conclusion
The most important advantages of Appium are undoubtedly its cross-platform and open-source nature. Carrying out automated tests of mobile applications as well as web applications significantly improves the software development process. When we also combine it with cucumber framework and with Java programming language, it gives us more flexibility to apply such details on the project. I hope above explained details help you in your project. Stay tuned! :)
Happy Automation !!!