I have a URL in the form
http://www.mywebsite.com/util/conv?a=1&from=%s&to=%s
And want to check if it is available.
The lin
As mentioned by 'eridal', that should be faster, open the socket; however, it only tells you that a server is listening on the host and port but to be sure, you need to write HTTP or alternately a bad request (junk), you should get HTTP/1.1 400 Bad Request. By reading the first line returned, if it contains HTTP, then you are sure that the server is a HTTP server. This way you are sure that the server is available as well as a HTTP server.
This is in extension to the above answer by eridal.
Below code waits until webpage is available:
public void waitForWebavailability() throws Exception {
boolean success = false;
long waitTime = 0;
while (!success) {
try {
waitTest(30000);
waitTime += 30000;
if (waitTime > 600000) {
System.out.println("Web page is not available");
}
webDriver.get("http://www.google.com");
if (webDriver.getTitle().toLowerCase().contains("sometitle")) {
success = true;
}
} catch (Exception e) {
success = false;
}
}
}
// Code related to waittest
public void waitTest(long millis) throws Exception {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
throw new Exception(e);
}
}