2016-06-02 5 views
-1

Посмотрите этот код. Я делаю тесты на селен. Мне нужно открыть URL-адрес, где URL-адрес String извлекается из файла CSV. Как только страница будет достигнута, я проверю, чтобы название и палитра были правильными двумя разными способами, и эти проверки работают нормально: означает, что URL-адрес всегда открыт правильно.java selenium webdriver driver.get (url) занимает 9000ms перед открытием url

Но для открытия URL-адресов селен занимает 90 секунд. Почему? Я знаю, что проблема возникает в методе «open (path)» (уже подтвержденном режимом отладки). В модульных тестах нет проблем (все URL-адреса открыты быстро), но на hudson требуется столько времени.

Примечание. Мой сервер быстро отвечает на запрос браузера.

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); 
} 

ответ

0

Я наконец-то нашел мой ответ здесь: Selenium WebDriver works but SLOW (Java)

FirefoxProfile profile = new FirefoxProfile(); 
profile.setPreference("browser.cache.disk.enable", true); 
profile.setPreference("browser.cache.memory.enable", true); 
profile.setPreference("browser.cache.offline.enable", true); 
profile.setPreference("network.http.use-cache", true); 
**profile.setPreference("webdriver.load.strategy", "unstable");** // the most important 
this.driver = new FirefoxDriver(profile); 

 Смежные вопросы

  • Нет связанных вопросов^_^