【问题标题】:Set a firefoxWebDriver.get(...) timeout设置 firefoxWebDriver.get(...) 超时
【发布时间】:2012-08-15 20:37:23
【问题描述】:

我喜欢访问一些不受我控制的页面。可能是该页面执行了一些缓慢的获取请求,但主 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();
    }
}

感谢您的帮助。

【问题讨论】:

    标签: java selenium webdriver selenium-firefoxdriver


    【解决方案1】:
    <driver>.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS); 
    

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

    从 Webdriver 版本 2.20.0 开始支持 API。

    Refer API Reference for new Timeout API's

    【讨论】:

    • 嗨 Ashwin Prabhu,这不会解决问题。如您所见,此选项已在构造函数中进行了测试(当前已注释掉)。遗憾的是,UnitTest 仍然会因我们的建议而失败。
    猜你喜欢
    • 1970-01-01
    • 2015-07-04
    • 2023-03-03
    • 2011-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多