2013-06-05 4 views
0

나는 여기 초보자입니다. P 아마도 매우 기본적인 질문이지만, 질문하거나 묻는 법을 모르겠습니다.Selenium WebDriver 세션

그래서 셀레늄을 사용하여 Java에서 웹 페이지 크롤러를 만들려고 결정했는데 세션을 충분히 빨리 종료하지 않는 것으로 나타났습니다. = 그게 종종 .quit()를 호출해야한다는 것을 의미합니다. 새로운 웹 드라이브를 열어 두거나 웹 사이트와 계속 상호 작용할 수있는 방법이 있습니까?

예 : Google을 열어보고 싶습니다. "파이"를 입력하고 검색을 클릭하면 결과가 마음에 들지 않았을 것입니다. "사과 파이"를 검색하고 오랜 기간 동안 그 일을 계속 하시겠습니까?

+0

당신은 오랜 기간 동안 그것을 할 수 있지만이를 수동으로 스크립트 릴 비트를 변경해야합니다. – Smit

+0

그것은 단지 예일 뿐이므로 다른 작업을 위해 드라이버를 계속 사용하고 싶습니다. –

+0

어떤 브라우저입니까? 해당 브라우저의 버전은 무엇입니까? – Arran

답변

1

이것은 제가 연극 연습을 위해했던 것입니다. 사용하실 수 있습니다.

String[] location = new String[] { 
            "Los Angeles", 
            "Santa Barbara", 
            "San Jose" 
           }; 

// Some code 

@Test 
public void testSelServerDiceTest() throws Exception { 
    for (int i = 0; i < location.length; i++) { // manually added for loop 
     selenium.open("/"); 
     selenium.type("id=FREE_TEXT", "selenium RC JUnit"); 
     selenium.type("id=WHERE", location[i].concat(" CA")); 
     selenium.click("xpath=//*[@id=\"searchSubmit\"]"); 
     selenium.waitForPageToLoad("30000"); 
     verifyTrue(selenium.isTextPresent("Search results:")); 
     verifyTrue(selenium.isTextPresent("Search job title only")); 
     verifyEquals("JUnit", selenium.getText("css=div.undoLabel")); 
     verifyTrue(selenium.isTextPresent("selenium")); 
     verifyTrue(selenium.isTextPresent("Search results: 1 - 1 of 1")); 
     assertTrue(selenium.isTextPresent("Search results:")); 
    } 
} 
//Some more code 

편집

// webdriver code snippet 

@Test 
public void testRemoteWebDriverDiceTest() throws Exception { 
    for (int i = 0; i < location.length; i++) { 
     driver.get(baseUrl + "/"); 
     driver.findElement(By.id("FREE_TEXT")).clear(); 
     driver.findElement(By.id("FREE_TEXT")) 
       .sendKeys("selenium RC JUnit"); 
     driver.findElement(By.id("WHERE")).clear(); 
     driver.findElement(By.id("WHERE")).sendKeys(
       location[i].concat(" CA")); 
     driver.findElement(By.xpath("//*[@id=\"searchSubmit\"]")).click(); 

     try { 
      assertEquals("JUnit", 
        driver.findElement(By.cssSelector("div.undoLabel")) 
          .getText()); 
     } catch (Error e) { 
      verificationErrors.append(e.toString()); 
     } 

    } 
} 
+0

Selenium의 이전 버전입니까? 나는 그들이 지금 WebDriver 클래스를 사용하고 있다고 생각했다. 드라이버를 종료하지 않으면 메모리 누수를 방지하는 방법을 알고 싶습니다. –

+0

'webdriver'대신'selenium'을 게시하는 것에 대해 죄송합니다. 여하튼 기본 개념은 그대로 유지됩니다. 메모리 누수에 관해서는 [여기] (http://selenium.10932.n7.nabble.com/WebDriver-and-IE9-memory-leak-td22307.html)를 볼 수 있습니다. – Smit