2010-12-02 18 views
0

모든 예제를 살펴본 결과 waitForCondition을 사용하여 문제가 발생했습니다. 여기 내 코드가있다.waitForCondition은 누락을 나타냅니다. before 문 오류

WebDriverBackedSelenium seleniumWD = new WebDriverBackedSelenium(driver, "http://www.x.com"); 

seleniumWD.waitForCondition("seleniumWD.isElementPresent(\"fullname\");", "5000"); 

셀레늄 WD가 정의되지 않았습니다. 그래서 다음과 같이 변경했습니다.

WebDriverBackedSelenium seleniumWD = new WebDriverBackedSelenium(driver, "http://www.x.com"); 

seleniumWD.waitForCondition("boolean ok = seleniumWD.isElementPresent(\"fullname\");", "5000"); 

이제 오류가 발생합니다. 누락되었습니다. before 문

답변

1

Selenium 2/WebDriver 기반 테스트에서 Selenium JS 개체를 사용하고있는 것으로 보입니다. WebDriverBackedSelenium을 사용하는 대신 WebDriver에서 제공하는 ExpectedCondition 및 Wait 클래스를 사용해야합니다.

WebElement element; 
ExpectedCondition<Boolean> e = new ExpectedCondition<Boolean>() { 
    public Boolean apply(WebDriver d) { 
     element = d.findElement(By.id("fullname")); 
     return Boolean.TRUE; 
    } 
}; 

Wait<WebDriver> w = new WebDriverWait(driver, timeOutInSeconds); 
w.until(e); 

이 코드의 정말 큰 작품이다, 당신은 Page Objects pattern를 사용하는 것이 좋습니다 그래서 : 귀하의 경우, 코드는 다음과 같아야의 fullname 당신이 기다리고있는 요소의 ID입니다 가정 이는 셀렌 테스트를 작성하기위한 우수 사례 중 하나입니다. 귀하의 필드를 포함하는 예제 페이지는 다음과 같습니다 :

public class MyPage { 
    @FindBy(id="fullname") 
    private WebElement fullName; 

    public MyPage(WebDriver driver) { 
     PageFactory.initElements(new AjaxElementLocatorFactory(driver, 15), this); 
    } 

    public void setFullName(String value) { 
     fullName.clear(); 
     fullName.sendKeys(value); 
    } 
} 
+0

나는 당신의 코드를 이해하지만 그것이 오류가 발생하지 않고 waitForCondition을 사용할 수없는 이유를 설명하지 못합니다. – John

+0

WebDriverBackedSelenium에는 원래 Selenium 인터페이스의 모든 메소드가 구현되지 않았습니다. 하나의 가능성은 waitForCondition이 아직 완료되지 않았거나 WebDriver에서 동일한 목적을 처리 할 수있는 API가 있기 때문에 구현되지 않을 수도 있습니다. 다른 질문은 실행하려는 JavaScript가 무엇입니까? Selenium 1에서 제공하는 JS를 호출하려고하는 것처럼'seleniumWD.isElementPresent'가 보이며 Se 2에서는 사용할 수 없습니다 –