The platform does not produce granular recording for each test case by default. In order to enable it, you have to configure it from the test script side. Here are some examples how it might be accomplished:
Java (TestNG)
import org.testng.ITestContext;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
import io.appium.java_client.android.AndroidStartScreenRecordingOptions;
import io.appium.java_client.ios.IOSStartScreenRecordingOptions;
import io.appium.java_client.screenrecording.CanRecordScreen;
import io.qameta.allure.Allure;
import org.apache.commons.lang3.StringUtils;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Base64;
public class ExampleTest {
@BeforeTest
public void beforeTest() {
if (/** Is Android execution? **/) {
driver.startRecordingScreen(new AndroidStartScreenRecordingOptions());
} else if (/** Is IOS execution? **/) {
driver.startRecordingScreen(new IOSStartScreenRecordingOptions());
}
}
@AfterTest
public void afterTest(final ITestContext testContext) {
String video = driver.stopRecordingScreen();
if(StringUtils.isNotEmpty(video)) {
byte[] decode = Base64.getDecoder().decode(video);
InputStream is = new ByteArrayInputStream(decode);
Allure.addAttachment(testContext.getName(), "video/mp4", is, "mp4");
}
}
}
Node (WebdriverIO, Mockito)
With WebdriverIO the recommended package to generate granular videos is wdio-video-reporter.
In order to install this package run
npm install wdio-video-reporter
If your project uses Typescript a types declaration file is needed. At the time of writing this article no typings are not available for this package.
// types.d.ts
declare module 'wdio-video-reporter';
Once the package is installed in your project, you will need to configure webdriverio. In your project config file, for example wdio.conf.js
:
Import the package:
import videoReporter from 'wdio-video-reporter';
2. In the reporters section add your configuration:
reporters: [
[
videoReporter,
{
saveAllVideos: true,
videoSlowdownMultiplier: 10,
outputDir: <allureResultsDir>
}
],
[
'allure',
{
// allure options
}
]
],
Configuration
Field | Type | Comment |
saveAllVideos | boolean | true: generates a video for every test |
outputDir | string | needs to point to the allure results folder in order for the videos to be found and properly processed |
videoSlowdownMultiplier | number | the higher the number the slower the video play (assigns more duration to every screenshot in the video) |
Further configuration details can be found in WebdriverIO documentation page.
Note: Be aware that wdio-video-reporter
takes screenshots which are displayed together to create the video. By default a screenshot is grabbed after every action.