The latest release of the Robot Framework's Appium Library introduces keywords for recording a video of the Appium test execution in iOS and Android phones.
Instructions for use:
- If test is run in iPhone, install ffmpeg in the Mac where Appium is running:
brew install ffmpeg
-
Simple use case: Use Appium Library's keyword
Start Screen Recording
in the Test Setup andStop Screen Recording
in the Test Teardown. Recording is stored in the same place where Robot test case reports are. Video file is not stored permanently to the storage of the phone. -
Error-proof use case: Some Android phones (for example Huawei models) are not capable of recording the screen and the test case will fail (in the latest Appium library 1.5.0.4 - this might change in the future). It is a good idea to start and stop recording using a keyword
Run Keyword And Ignore Error
(remember also import BuiltIn library for the Robot Framework code). Here's an example of this error-proof case:This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters*** Settings *** Library BuiltIn Library AppiumLibrary *** Keywords *** Capture Screen Recording Run Keyword And Ignore Error Start Screen Recording End Screen Recording Run Keyword And Ignore Error Stop Screen Recording -
Storing recording only for failed tests: Here's an example code that stores screen recording only when a test case fails:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
*** Settings *** Documentation Saves screen recording for failing tests. ... iPhone: requires ffmpeg installed on Mac where phones are conneted. Run: brew install ffmpeg ... Android: recording is not working in all phones (does not cause test failures if recording is not supported) Library BuiltIn Library OperatingSystem Library AppiumLibrary *** Keywords *** Capture Screen Recording ${pass} Run Keyword And Return Status Start Screen Recording Run Keyword Unless ${pass} Log Could not start screen recording End Screen Recording Run Keyword And Ignore Error Remove Screen Recording If Pass Remove Screen Recording If Pass ${filename} Stop Screen Recording Run Keyword If Test Passed Remove File ${filename} Run Keyword If Test Passed Log Screen recording not saved because test execution passed.
Viewing videos
For Android recordings, file format is .mp4
that is easy to open with many tools. For iOS, file format is .ffmpeg
. To view ffmpeg videos, use ffplay
in the command line (in a computer where ffmpeg is installed):
ffplay appium-screenrecord-10.ffmpeg
Free word
In my opinion, this example showcases nicely how the use of readily available Robot Framework libraries reduces the amount of test automation code (and thus less maintenance and bugs in it!). Capturing video of the screen is now only a few simple lines of code, whereas file handling using native Appium would require more logic.
Top comments (4)
Hi Laura,
Your post is simple and easy. I'm working with appium library and robot framework to automate a windows application. I'm facing problems with file browsing window. I'm trying to upload a file from local directory to the windows application which is also on the same machine. I used Input text and the file name, this does nothing . Do you have an idea how I can upload a file to the windows application?
Hi! I have no idea if Appium can access those dialogs (in other words, it might be possible). If you can not do file upload using Appium, this library should be able to do it: github.com/nokia/robotframework-au...
Thanks Laura, I've tried AutoIT, it works like a charm. May I ask your advice related to appium/robot framework in case I have questions in the future?
Feel free to! Also (Robot Framework Slack)[robotframework-slack-invite.heroku...] is a very good place for questions :-)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.