3

我喜欢访问一些不受我控制的页面。可能是该页面执行了一些缓慢的获取请求,但主 html 已完全加载并显示。我尝试了很多选择,但我可以做到。firefoxWebDriver.get(...)不会在现实时间内在某些站点上终止。

为了重现问题,我写了这个小单元测试来显示问题:

public class Timeout  {

    private FirefoxDriver   driver;

    @Before
    public void setup() {
        final FirefoxProfile profile = new FirefoxProfile();
        profile.setPreference("dom.max_script_run_time", 0);
        profile.setPreference("webdriver.load.strategy", "fast");

        this.driver = new FirefoxDriver(profile);

//      this.driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
//      this.driver.manage().timeouts().setScriptTimeout(10, TimeUnit.SECONDS);

    }

    @Test(timeout = 15000)
    public void shouldRetriveREDCAFEPageQuiteFast() {
        this.driver.get("http://redcafe.vn/Home/su-kien-binh-luan/kagawa-tu-choi-mac-ao-so-7");
    }

    @Test(timeout = 15000)
    public void shouldRetriveMUFCPageQuiteFast() {
        this.driver.get("http://news.mufc.vn/detail/172-hoan-tat-giay-phep-lao-dong-m-u-chinh-thuc-so-huu-kagawa.html");
    }

    @After
    public void tearDown() {
        this.driver.close();
    }
}

谢谢你的帮助。

4

1 回答 1

3
<driver>.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS); 

将页面加载超时设置为 60 秒,之后它将引发错误。您需要在第一次get()通话之前进行设置。

从 Webdriver 版本 2.20.0 开始支持 API。

请参阅 API 参考以获取新的超时 API

于 2012-08-21T10:52:15.570 回答