Skip to content

Commit e07acec

Browse files
authored
Bugfix: isDriverAlive method can't verify the staus of iosDriver (#511)
* Bugfix: isDriverAlive method can't verify the staus of iosDriver * Update TestRunDeviceOrchestrator.java
1 parent ed7e388 commit e07acec

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

agent/src/main/java/com/microsoft/hydralab/agent/runner/TestRunDeviceOrchestrator.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,20 @@ public void addGifFrameAsyncDelay(@NotNull TestRunDevice testRunDevice, @NotNull
272272
});
273273
}
274274

275+
private void addGifFrameSyncDelay(@NotNull TestRunDevice testRunDevice, @NotNull File screenshotDir, int delaySeconds, @NotNull Logger logger) {
276+
ThreadUtils.safeSleep(TimeUnit.SECONDS.toMillis(delaySeconds));
277+
File imageFile = getScreenShot(testRunDevice, screenshotDir, logger);
278+
if (imageFile == null || !testRunDevice.getGifEncoder().isStarted()) {
279+
return;
280+
}
281+
try {
282+
testRunDevice.getGifEncoder().addFrame(ImgUtil.toBufferedImage(ImgUtil.scale(ImageIO.read(imageFile), 0.3f)));
283+
testRunDevice.setGifFrameCount(testRunDevice.getGifFrameCount() + 1);
284+
} catch (IOException e) {
285+
logger.error("Failed to add frame to gif", e);
286+
}
287+
}
288+
275289
public void grantAllTaskNeededPermissions(@NotNull TestRunDevice testRunDevice, @NotNull TestTask testTask, @Nullable Logger logger) {
276290
if (testRunDevice instanceof TestRunDeviceCombo) {
277291
((TestRunDeviceCombo) testRunDevice).getDevices()
@@ -294,7 +308,7 @@ public void stopGitEncoder(@NotNull TestRunDevice testRunDevice, @NotNull File s
294308
return;
295309
}
296310
if (testRunDevice.getGifFrameCount() < 2) {
297-
addGifFrameAsyncDelay(testRunDevice, screenshotDir, 0, logger);
311+
addGifFrameSyncDelay(testRunDevice, screenshotDir, 0, logger);
298312
}
299313
testRunDevice.getGifEncoder().finish();
300314
}

common/src/main/java/com/microsoft/hydralab/common/management/AppiumServerManager.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,6 @@ public IOSDriver getIOSDriver(DeviceInfo deviceInfo, Logger logger) {
140140
int tryTimes = 3;
141141
boolean sessionCreated = false;
142142
while (tryTimes > 0 && !sessionCreated) {
143-
if (iosDriver != null) {
144-
iosDriver.quit();
145-
}
146143
tryTimes--;
147144
try {
148145
iosDriver = new IOSDriver(new URL(String.format("http://%s:%d/wd/hub", appiumServerHost, appiumServerPort)), caps);
@@ -288,6 +285,15 @@ public Boolean isDriverAlive(AppiumDriver driver) {
288285
}
289286
}
290287

288+
public Boolean isDriverAlive(IOSDriver driver) {
289+
try {
290+
driver.unlockDevice();
291+
return true;
292+
} catch (WebDriverException e) {
293+
return false;
294+
}
295+
}
296+
291297
public Boolean isDriverAlive(WindowsDriver driver) {
292298
try {
293299
driver.getScreenshotAs(OutputType.FILE);

common/src/main/java/com/microsoft/hydralab/common/screen/IOSAppiumScreenRecorderForMac.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.microsoft.hydralab.common.entity.common.DeviceInfo;
66
import com.microsoft.hydralab.common.management.device.DeviceDriver;
77
import com.microsoft.hydralab.common.util.Const;
8+
import com.microsoft.hydralab.common.util.FlowUtil;
89
import com.microsoft.hydralab.common.util.ThreadUtils;
910
import io.appium.java_client.ios.IOSStartScreenRecordingOptions;
1011

@@ -26,14 +27,17 @@ public IOSAppiumScreenRecorderForMac(DeviceDriver deviceDriver, DeviceInfo info,
2627
public void startRecord(int maxTimeInSecond) {
2728
int timeout = maxTimeInSecond > 0 ? maxTimeInSecond : DEFAULT_TIMEOUT_IN_SECOND;
2829
try {
29-
iosDriver.startRecordingScreen(new IOSStartScreenRecordingOptions()
30-
.enableForcedRestart()
31-
.withFps(24)
32-
.withVideoType("h264")
33-
.withVideoScale("720:360")
34-
.withTimeLimit(Duration.ofSeconds(timeout)));
30+
FlowUtil.retryAndSleepWhenFalse(3, 1000, () -> {
31+
iosDriver.startRecordingScreen(new IOSStartScreenRecordingOptions()
32+
.enableForcedRestart()
33+
.withFps(24)
34+
.withVideoType("h264")
35+
.withVideoScale("720:360")
36+
.withTimeLimit(Duration.ofSeconds(timeout)));
37+
return true;
38+
});
3539
isStarted = true;
36-
} catch (Throwable e) {
40+
} catch (Exception e) {
3741
System.out.println("-------------------------------Fail to Start recording, Ignore it to unblocking the following tests----------------------------");
3842
e.printStackTrace();
3943
System.out.println("-------------------------------------------------------Ignore End--------------------------------------------------------------");

0 commit comments

Comments
 (0)