Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #325 from sbtqa/mobile-android
Browse files Browse the repository at this point in the history
Record video on android
  • Loading branch information
kosteman authored Nov 30, 2020
2 parents 9ae3d5e + 71a27a3 commit f30da4d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ public interface MobileConfiguration extends Configuration {
@DefaultValue("10")
int getAppiumVideoFps();

@Key("appium.video.bitrate")
@DefaultValue("200000000")
int getAppiumVideoBitRate();

@Key("appium.video.videoSize")
@DefaultValue("1280x720")
String getAppiumVideoSize();

@Key("appium.video.bugReport")
@DefaultValue("false")
boolean getAppiumVideoBugReport();

@Key("appium.xcodeOrgId")
@DefaultValue("")
String getAppiumXcodeOrgId();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ru.sbtqa.tag.pagefactory.mobile.utils;

import cucumber.api.Scenario;
import io.appium.java_client.android.AndroidDriver;
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.IOSStartScreenRecordingOptions.VideoQuality;
Expand Down Expand Up @@ -38,15 +40,27 @@ public void startRecord() {
return;
}

IOSStartScreenRecordingOptions startOptions = new IOSStartScreenRecordingOptions()
.withVideoType(PROPERTIES.getAppiumVideoType())
.withVideoScale(PROPERTIES.getAppiumVideoScale())
.withTimeLimit(Duration.ofSeconds(PROPERTIES.getAppiumTimeLimit()))
.withVideoQuality(VideoQuality.valueOf(PROPERTIES.getAppiumVideoQuality()))
.withFps(PROPERTIES.getAppiumVideoFps())
.enableForcedRestart();
if (PROPERTIES.getAppiumPlatformName() == PlatformName.IOS) {
IOSStartScreenRecordingOptions startOptions = new IOSStartScreenRecordingOptions()
.withVideoType(PROPERTIES.getAppiumVideoType())
.withVideoScale(PROPERTIES.getAppiumVideoScale())
.withTimeLimit(Duration.ofSeconds(PROPERTIES.getAppiumTimeLimit()))
.withVideoQuality(VideoQuality.valueOf(PROPERTIES.getAppiumVideoQuality()))
.withFps(PROPERTIES.getAppiumVideoFps())
.enableForcedRestart();
((IOSDriver) Environment.getDriverService().getDriver()).startRecordingScreen(startOptions);
} else {
AndroidStartScreenRecordingOptions startOptions = new AndroidStartScreenRecordingOptions()
.withBitRate(PROPERTIES.getAppiumVideoBitRate())
.withVideoSize(PROPERTIES.getAppiumVideoSize())
.withTimeLimit(Duration.ofSeconds(PROPERTIES.getAppiumTimeLimit()))
.enableForcedRestart();
if (PROPERTIES.getAppiumVideoBugReport()) {
startOptions.enableBugReport();
}
((AndroidDriver) Environment.getDriverService().getDriver()).startRecordingScreen(startOptions);
}

((IOSDriver) Environment.getDriverService().getDriver()).startRecordingScreen(startOptions);
isRecording = true;
}

Expand All @@ -57,7 +71,9 @@ public byte[] stopRecord() {
}

// get Base64 encoded video content
String encodedString = ((IOSDriver) Environment.getDriverService().getDriver()).stopRecordingScreen();
String encodedString = PROPERTIES.getAppiumPlatformName() == PlatformName.IOS
? ((IOSDriver) Environment.getDriverService().getDriver()).stopRecordingScreen()
: ((AndroidDriver) Environment.getDriverService().getDriver()).stopRecordingScreen();

// convert to byte array
byte[] decodedBytes = Base64.getDecoder().decode(encodedString.getBytes());
Expand Down

0 comments on commit f30da4d

Please sign in to comment.