Skip to content

Commit 9e498ea

Browse files
authored
Bugfix: add another method to verify the status of windows driver (#505)
* Bugfix: add another method to verify the status of windows driver * Update TestTaskService.java * Update AppiumRunner.java * Update TestTaskService.java
1 parent d27e699 commit 9e498ea

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

agent/src/main/java/com/microsoft/hydralab/agent/runner/appium/AppiumRunner.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public boolean startJunit(File appiumJarFile, String appiumCommand, AppiumListen
148148
myClass = urlClassLoader.loadClass(appiumCommand);
149149
junit.run(myClass);
150150
return true;
151-
} catch (ClassNotFoundException e) {
151+
} catch (Exception e) {
152152
e.printStackTrace();
153153
return false;
154154
}
@@ -176,7 +176,7 @@ public boolean startJunit5(File appiumJarFile, String appiumCommand, TestExecuti
176176
launcher.registerTestExecutionListeners(listener);
177177
launcher.execute(request);
178178
return true;
179-
} catch (ClassNotFoundException e) {
179+
} catch (Exception e) {
180180
e.printStackTrace();
181181
return false;
182182
}

center/src/main/java/com/microsoft/hydralab/center/service/TestTaskService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public Boolean isDeviceFree(String deviceIdentifier) {
8080

8181
@Scheduled(cron = "0 */3 * * * *")
8282
public void runTask() {
83+
logger.info("Start to run queued test task. the value of isRunning is: " + isRunning.get() + "the size of taskQueue is: " + taskQueue.size());
8384
//only run one task at the same time
8485
if (isRunning.get()) {
8586
return;

center/src/main/java/com/microsoft/hydralab/center/socket/CenterDeviceSocketEndpoint.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55

66
import com.microsoft.hydralab.center.config.SpringApplicationListener;
77
import com.microsoft.hydralab.center.service.DeviceAgentManagementService;
8+
import com.microsoft.hydralab.common.entity.common.Message;
89
import com.microsoft.hydralab.common.util.SerializeUtil;
910
import org.springframework.context.annotation.DependsOn;
1011
import org.springframework.stereotype.Component;
1112

1213
import javax.annotation.Resource;
14+
import javax.websocket.CloseReason;
1315
import javax.websocket.OnClose;
1416
import javax.websocket.OnError;
1517
import javax.websocket.OnMessage;
@@ -47,8 +49,19 @@ public void onClose(Session session) {
4749

4850
@OnMessage
4951
public void onMessage(ByteBuffer message, Session session) {
52+
Message formattedMessage;
5053
try {
51-
deviceAgentManagementService.onMessage(SerializeUtil.byteArrToMessage(message.array()), session);
54+
formattedMessage = SerializeUtil.byteArrToMessage(message.array());
55+
} catch (Exception e) {
56+
try {
57+
session.close(new CloseReason(CloseReason.CloseCodes.CANNOT_ACCEPT, "Message format error"));
58+
} catch (IOException ex) {
59+
throw new RuntimeException(ex);
60+
}
61+
throw new RuntimeException(e);
62+
}
63+
try {
64+
deviceAgentManagementService.onMessage(formattedMessage, session);
5265
} catch (IOException e) {
5366
throw new RuntimeException(e);
5467
}

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@
2525
import org.openqa.selenium.net.UrlChecker;
2626
import org.openqa.selenium.remote.DesiredCapabilities;
2727
import org.slf4j.Logger;
28-
import org.springframework.stereotype.Service;
2928

3029
import javax.annotation.Nonnull;
31-
import java.io.*;
30+
import java.io.File;
31+
import java.io.FileOutputStream;
32+
import java.io.IOException;
33+
import java.io.InputStream;
34+
import java.io.OutputStream;
3235
import java.net.MalformedURLException;
3336
import java.net.URL;
3437
import java.time.Duration;
@@ -279,6 +282,14 @@ public WindowsDriver getWindowsRootDriver(Logger logger) {
279282
public Boolean isDriverAlive(AppiumDriver driver) {
280283
try {
281284
driver.getStatus();
285+
return true;
286+
} catch (WebDriverException e) {
287+
return false;
288+
}
289+
}
290+
291+
public Boolean isDriverAlive(WindowsDriver driver) {
292+
try {
282293
driver.getScreenshotAs(OutputType.FILE);
283294
return true;
284295
} catch (WebDriverException e) {

0 commit comments

Comments
 (0)