Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add frame to XCTest gif #390

Merged
merged 1 commit into from
Mar 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -18,17 +18,22 @@
import org.slf4j.Logger;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import javax.imageio.ImageIO;

import cn.hutool.core.img.ImgUtil;
import cn.hutool.core.img.gif.AnimatedGifEncoder;

public class XCTestRunner extends TestRunner {
private static String folderPath = "";
private File gifFile;
private final AnimatedGifEncoder gitEncoder = new AnimatedGifEncoder();
private final AnimatedGifEncoder gifEncoder = new AnimatedGifEncoder();
private ScreenRecorder deviceScreenRecorder;
private Logger reportLogger;
private long recordingStartTimeMillis;
@@ -59,9 +64,9 @@ private void initializeTest(DeviceInfo deviceInfo, TestTask testTask, TestRun te
testRun.setTestStartTimeMillis(System.currentTimeMillis());
reportLogger.info("Start gif frames collection");
gifFile = new File(testRun.getResultFolder(), testTask.getPkgName() + ".gif");
gitEncoder.start(gifFile.getAbsolutePath());
gitEncoder.setDelay(1000);
gitEncoder.setRepeat(0);
gifEncoder.start(gifFile.getAbsolutePath());
gifEncoder.setDelay(1000);
gifEncoder.setRepeat(0);
}

@Override
@@ -82,6 +87,7 @@ private ArrayList<String> runXctest(DeviceInfo deviceInfo, Logger logger,
if (deviceInfo == null) {
throw new RuntimeException("No such device: " + deviceInfo);
}
addFrame(deviceInfo, logger);
StringBuilder argString = new StringBuilder();
Map<String, String> instrumentationArgs = testTask.getInstrumentationArgs();
if (instrumentationArgs != null && !instrumentationArgs.isEmpty()) {
@@ -116,6 +122,7 @@ private ArrayList<String> runXctest(DeviceInfo deviceInfo, Logger logger,
out.start();
proc.waitFor();
result = out.getResult();
addFrame(deviceInfo, logger);
} catch (Exception e) {
throw new RuntimeException("Execute XCTest failed");
}
@@ -165,6 +172,20 @@ private void analysisXctestResult(List<String> resultList, TestRun testRun) {
testRun.setTotalCount(totalCases);
}

private void addFrame(DeviceInfo deviceInfo, Logger logger){
testDeviceManager.updateScreenshotImageAsyncDelay(deviceInfo, TimeUnit.SECONDS.toMillis(0),
(imagePNGFile -> {
if (imagePNGFile == null || !gifEncoder.isStarted()) {
return;
}
try {
gifEncoder.addFrame(ImgUtil.toBufferedImage(ImgUtil.scale(ImageIO.read(imagePNGFile), 0.3f)));
} catch (IOException ioException) {
ioException.printStackTrace();
}
}), logger);
}

private void finishTest(TestRun testRun) {
testRun.addNewTimeTag("testRunEnded", System.currentTimeMillis() - recordingStartTimeMillis);
testRun.onTestEnded();
@@ -174,7 +195,7 @@ private void finishTest(TestRun testRun) {
if (gifFile.exists() && gifFile.length() > 0) {
testRun.setTestGifPath(agentManagementService.getTestBaseRelPathInUrl(gifFile));
}
gitEncoder.finish();
gifEncoder.finish();
deviceScreenRecorder.finishRecording();
}
}