Home Appium Environment Setup Android Emulators iOS Simulators Appium Architecture Android chrome app automation Safari browser automation Appium Capabilities Inspecting android apps Native Android app automation Inspecting iOS app Native iOS app Automation Real Android Phone automation Real iPhone automation Element Identification Pressing button FaceId and TouchId Fingerprint automation Drag and Drop Tap and press Swipe gestures Hybrid app automation Execute script Synchronization in Appium Screenshots Page Object Models Cucumber and Appium Appium integration with azure Appium and Selenium Grid Running tests in browserstack Parallel testing Recording tests Mobile automation framework Errors and Exceptions in Appium Mobile automation test strategy Mobile automation challenges Appium QnA
Recording live automation using appium
Some important points
- We can record a session of Appium
- Recorded files can be saved to local drive
- Sometimes developers may restrict recording the screen so You will not be able to record certain apps
- startRecordingScreen method of AppiumDriver is used to record the screen
- Video size of 1280x720 needs to be passed for certain emulators otherwise recording will fail
package org.softpost.android.simulator;
import io.appium.java_client.MultiTouchAction;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.android.AndroidStartScreenRecordingOptions;
import io.appium.java_client.screenrecording.BaseStartScreenRecordingOptions;
import io.appium.java_client.touch.WaitOptions;
import io.appium.java_client.touch.offset.PointOption;
import org.apache.commons.io.FileUtils;
import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.io.File;
import java.net.URL;
import java.time.Duration;
import java.util.Base64;
import java.util.concurrent.TimeUnit;
/**
* Created by Sagar on 10-07-2016.
*/
public class RecordSessionTest {
AndroidDriver driver;
@Test
public void test1() throws Exception{
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("platformName", "android");
caps.setCapability("deviceName", "Pixel 9");
caps.setCapability("appPackage", "com.android.settings");
caps.setCapability("appActivity","com.android.settings.Settings");
caps.setCapability("automationName","uiautomator2");
try {
driver = new AndroidDriver<AndroidElement>(new URL("http://0.0.0.0:4723/wd/hub"), caps);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.startRecordingScreen(
new AndroidStartScreenRecordingOptions()
.withVideoSize("1280x720")
.withTimeLimit(Duration.ofSeconds(200)));
WebElement battery = driver.findElement(By.xpath("//android.widget.TextView[contains(@text,'Battery')]"));
WebElement sound = driver.findElement(By.xpath("//android.widget.TextView[contains(@text,'Sound')]"));
battery.click();
Thread.sleep(5000);
}catch (Exception ex) {
ex.printStackTrace();
System.out.println(driver.getPageSource());
}finally {
String video =driver.stopRecordingScreen();
byte[] decode = Base64.getDecoder().decode(video);
FileUtils.writeByteArrayToFile(new File("androidclip.mp4"), decode);
driver.quit();
}
}
}
Recording iPhone Simulators in Appium
Below example shows how to do recording of iPhone Simulators.
package org.softpost.ios.simulator;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.android.AndroidStartScreenRecordingOptions;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.ios.IOSStartScreenRecordingOptions;
import io.appium.java_client.ios.IOSStopScreenRecordingOptions;
import org.apache.commons.io.FileUtils;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.io.File;
import java.net.URL;
import java.time.Duration;
import java.util.Base64;
import java.util.concurrent.TimeUnit;
/**
* Created by Sagar on 10-07-2016.
*/
public class RecordSessionTest {
IOSDriver driver;
@Test
public void test1() throws Exception{
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("platformName", "iOS");
caps.setCapability("platformVersion", "11.0");
caps.setCapability("deviceName", "iPhone 8");
caps.setCapability("AutomationName" , "XCUITest");
caps.setCapability("bundleId", "com.apple.MobileAddressBook");
try {
driver = new IOSDriver(new URL("http://0.0.0.0:4723/wd/hub"), caps);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.startRecordingScreen(new IOSStartScreenRecordingOptions()
.withVideoScale("1280x720")
.withTimeLimit(Duration.ofSeconds(100)));
WebElement e = driver.findElement(By.xpath("//XCUIElementTypeButton[@name="Add"]"));
e.click();
}catch (Exception ex) {
ex.printStackTrace();
System.out.println(driver.getPageSource());
}finally {
String video =driver.stopRecordingScreen();
byte[] decode = Base64.getDecoder().decode(video);
String fileName = "ios.mp4";
FileUtils.writeByteArrayToFile(new File(fileName), decode);
driver.quit();
}
}
}
Web development and Automation testing
solutions delivered!!