Recording iOS Appium Tests

Rich Downie
2 min readDec 29, 2023

*** Code is available on Github ***

You will need Homebrew installed to record an iOS appium test.

Tools: Homebrew

Install Homebrew from the command line.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Install FFmpeg using Homebrew by running the command:

brew install ffmpeg

FFmpeg, a robust open-source software project, offers a suite of libraries and programs for comprehensive multimedia data management. Renowned for its capabilities, FFmpeg is extensively utilized in audio and video processing tasks.

Let's use the appium startup code from the previous Story => Crafting a Simple Ruby Appium iOS Test.

require 'appium_lib'

# Set your desired capabilities
caps = {
"platformName": "iOS",
"appium:platformVersion": "17.2",
"appium:deviceName": "iPhone 15 Pro Max",
"appium:automationName": "XCUITest",
"appium:app": "com.apple.Preferences"
}

# Instantiate and start a new Appium Driver
driver = Appium::Driver.new(caps:, appium_lib: { server_url: 'http://127.0.0.1:4723/' }).start_driver

# Record Test

Start Recording Screen:

  • driver.start_recording_screen: Begins recording the screen with the specified video quality ('high' in this case).
# Record Test
driver.start_recording_screen video_quality: 'high'

Perform Actions on the App:

  • The script interacts with the app by finding elements with specific names and clicking on them. In this case, it clicks “General” and “About.”
# Perform actions on the app
driver.find_element(name: "General").click
sleep 1
driver.find_element(name: "About").click

Stop Recording Screen:

  • driver.driver.stop_recording_screen: Stops the screen recording.
# Stop recording screen
recording = driver.stop_recording_screen

Save Recording to a File:

  • The recorded screen data is received as a Base64-encoded string (recording). This data is then decoded and saved to a file named 'video.mp4.'
# Save recording to a file
File.open('video.mp4', 'wb') do |file|
file.write(Base64.decode64(recording))
end

Easy Peasy 👌

Let’s remove that hard sleep 1 with some fancy wait logic => Click Here

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Rich Downie
Rich Downie

No responses yet

Write a response