下面列出了怎么用org.openqa.selenium.net.UrlChecker的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public synchronized void start() {
if (isRunning) {
return;
}
int port = PortProvider.getAppiumServerAvailablePort();
String startCmd;
if (StringUtils.isEmpty(APPIUM_JS)) {
startCmd = String.format("appium -p %d --session-override", port);
} else {
startCmd = String.format("node %s -p %d --session-override", APPIUM_JS, port);
}
try {
watchdog = Terminal.executeAsyncAndGetWatchdog(startCmd);
String url = String.format("http://localhost:%d/wd/hub", port);
this.url = new URL(url);
new UrlChecker().waitUntilAvailable(60, TimeUnit.SECONDS, new URL(url + "/status"));
isRunning = true;
} catch (Exception e) {
throw new RuntimeException("启动appium server失败", e);
}
}
public boolean isAvailable(int checkTimeoutInSeconds) {
try {
new UrlChecker()
.waitUntilAvailable(checkTimeoutInSeconds, TimeUnit.SECONDS, new URL(url.toString() + "/status"));
return true;
} catch (Exception e) {
log.warn("{} is not availabe, check timeout: {} s", url, checkTimeoutInSeconds);
return false;
}
}
void start() {
try {
server.start();
new UrlChecker().waitUntilAvailable(10, TimeUnit.SECONDS, new URL(getBaseUrl()));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private void ping(long time, TimeUnit timeUnit) throws UrlChecker.TimeoutException, MalformedURLException {
// The operating system might block direct access to the universal broadcast IP address
URL status = new URL(url.toString().replace(BROADCAST_IP_ADDRESS, "127.0.0.1") + "/status");
new UrlChecker().waitUntilAvailable(time, timeUnit, status);
}