Look this code. I am doing selenium tests. I have to open an url where the String url is retrieved from a CSV file. Once the page reached, i check wether the title and the breadcrumb are correct by two different methods and those checks work fine: means url are always opened correctly.
But to open urls selenium takes 90 seconds. Why ? I know that the problem is happened in the "open(path)" method (already confirmed by the debug mode). In unit tests there is no problem (all url are opened quickly) but on hudson it takes so much time.
Note: My server answers quickly to the browser request.
private void checkPages(Locale locale) {
for (String page : pages.keySet()) {
Map<String, String> attributes = pages.get(page);
String url = attributes.get(CsvFileReader.URL);
System.out.println(" Check page: "+url); //TODO Remove
if (attributes.get(CsvFileReader.TYPE).equals(
CsvFileReader.TYPE_POPUP)) {
// TODO : comment vérifier que la bonne redirection est faite
// après l'ouverture d'une popup ?
} else if (attributes.get(CsvFileReader.TYPE).equals(
CsvFileReader.TYPE_MENU)) {
// TODO : comment vérifier que la bonne redirection est faite
// après l'ouverture d'un link to page ?
} else {
open(url);
if (Locale.FRENCH.equals(locale)) {
checkBreadcrumb(attributes.get(CsvFileReader.FRENCH_NAME));
checkTitlePage(attributes.get(CsvFileReader.HTML_TITLE_FRENCH));
}
else {
checkBreadcrumb(attributes.get(CsvFileReader.NAME));
checkTitlePage(attributes.get(CsvFileReader.HTML_TITLE));
}
}
}
}
long t2, t1;
protected void open(String path) {
String ctx = "Open " + path;
t1 = System.currentTimeMillis();
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
System.out.println("\n" + "dans open " + dateFormat.format(date));
try {
testContext.put(ctx, STATUS_START);
driver.get(path);
//driver.navigate().to(path);
//driver.navigate().to("http://rns059lv:8080/winportal/group/mssportal/set-upchangenotificationrules");
System.out.println("logout link is displayed: " + driver.findElement(By.xpath("//*[@id='logoutLink']")).isDisplayed());
testContext.put(ctx, STATUS_OK);
t2 = System.currentTimeMillis() - t1;
ctx = ctx + " -- duration = " + t2 + "ms";
System.out.println(ctx);
} catch (Throwable e) {
ctx = ctx + e.getMessage();
testContext.put(ctx, throwableToString(e));
}
}
private void checkBreadcrumb(String breadcrumbName) {
String ctx = "";
t1 = System.currentTimeMillis();
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
System.out.println("\n" + " dans checkbreadcrumb " + dateFormat.format(date));
checkTextPortalPages(breadcrumbName);
t2 = System.currentTimeMillis() - t1;
ctx = "check breadcrumb --" + breadcrumbName + "-- duration = " + t2 + "ms";
System.out.println(ctx);
}
protected void checkTitlePage(String title) {
String ctx = "Check if title is correct (" + title + ")";
String ctx1 = "";
t1 = System.currentTimeMillis();
try {
testContext.put(ctx, STATUS_START);
waitPageLoad();
if (!driver.getTitle().equals(title)) {
testContext.put(ctx, STATUS_ERROR);
testContext.put("Title received = " + driver.getTitle(), STATUS_ERROR);
} else {
testContext.put(ctx, STATUS_OK);
}
}
catch (Throwable e) {
testContext.put(ctx, throwableToString(e));
}
t2 = System.currentTimeMillis() - t1;
ctx1 = "Check title --" + title + "-- duration = " + t2 + "ms";
System.out.println(ctx1);
}