Question

i like to access some pages that are not under my control. It could be that this pages execute some slow get requests but the main html is fully loaded and displayed. I tried many options but i could make it. The firefoxWebDriver.get(...) doesn't terminate on some sites in a realistic time.

To reproduice the problem, I wrote this small UnitTest showing the problem:

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();
    }
}

Thanks for you help.

Was it helpful?

Solution

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

will set the page load timeout to 60 seconds, after which it will throw an error. You need to set this up before your first get() call.

The API is supported from Webdriver release 2.20.0 onwards.

Refer API Reference for new Timeout API's

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top