2014-09-12 1 views
0

I "내 페이지를로드 처음 셀레늄 'LoadableComponent'에 대한 사용하려고 m 내 간단한 코드에 의해 여기왜 'LoadableComponent'가 load() 메소드에서 건너 뛸까요?

:.

import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.testng.annotations.BeforeClass; 
import org.testng.annotations.Test; 

public class NavigateTo { 
    private WebDriver driver; 

    @BeforeClass 
    public void setup() { 
     driver = new FirefoxDriver(); 
    } 

    @Test 
    public void NavigateToMain() { 
     @SuppressWarnings("unused") 
     Login login = new Login(driver).get(); 
    } 
} 

============ =======

import static org.testng.AssertJUnit.assertEquals; 
import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.support.ui.LoadableComponent; 

public class Login extends LoadableComponent<Login> { 

    private WebDriver driver; 

    private By title = By.cssSelector(".anim-btn.green span"); 

    public Login(WebDriver driver) { 
     this.driver = driver; 
    } 

    @Override 
    protected void load() { 
     System.out.println("Navigating to Bizzabo home page"); 
     driver.get("int-www.bizzabo.com"); 

    } 

    @Override 
    protected void isLoaded() throws Error { 
     assertEquals("Get started", driver.findElement(title).getText()); 
    } 
} 

이유에 호출 할 때 : 그것은 load() 메서드를 통해 처음가는 아니지만, 바로 'IsLoaded 표시를 통해'로그인 로그인 = 새 로그인 (드라이버) 갔지를()() '방법?

내가 뭘 놓치고 있니?

답변

0

이것은이라는 디자인으로 입니다. Is는 로드 번만 실행하므로 테스트 성능이 향상됩니다.

당신은 public (하위 클래스에서 재정의 load() 기능이 정확하기 위하여) 당신이 단순히 무시 load() 함수를 선언 할 수강제로 다시로드해야하는 경우. 그럼 그냥 경우에 당신이 get() 대신 load()를 호출 할 수

public class Login extends LoadableComponent<Login> { 
    ... 

    /** 
    * Load the web page. 
    */ 
    @Override 
    public final void load() { 
     driver.get(...); 
    } 

    ... 
} 

당신이 publicprotected 수정을 확장하여 디자인을 약간 깨는 것에 익숙하지 않다면, 당신은 LoadableComponent 클래스를 확장하고 public을 추가 할 수 있습니다 reload() 기능 : 그것은 실패했을 때

public class LoadablePO extends LoadableComponent<LoadablePO> { 
    ... 

    /** 
    * Force a reload (by circumventing the call of isLoaded()). 
    */ 
    public final void reload() { 
     this.load(); 
    } 

    /** 
    * Load the web page. 
    */ 
    @Override 
    protected final void load() { 
     driver.get(...); 
    } 

    ... 
} 
0

당신은 먼저 IsLoaded 표시 기능을 구현해야 자동로드 기능

를 호출합니다
관련 문제