Monday, October 22, 2018

Selenium Firefox - Test timeout error after waiting for timeout page

In this test, I want to verify the Timeout Error Page displays after a User has logged in successfully, but has not used the Application after 15 minutes.

Remember, my timeout is in units of seconds. So, adjusting my browser timeout to 15 * 60 seconds plus 30 more seconds to ensure my browser doesn't throw a timeout error before my application timeout. In case this calculation moved too fast because you haven't gotten your coffee yet, I need to wait for 15 minutes, these 15 minutes each have 60 seconds (i.e. 1 minute = 60 seconds, and I must test in seconds according to my function of units), and then I need to wait a few more seconds for my test script to capture the timeout text from the page display before my test browser times out (i.e. plus 30 seconds).

Here's my code.

@Test
public void testLoginTimeoutError() {

    WebDriver firefoxDriver = new FirefoxDriver( new FirefoxProfile() );
    firefoxDriver.manage().timeouts().implicitlyWait(60*15+30, TimeUnit.SECONDS);

    Application.login(firefoxDriver, url, username, password);

    WebElement myTimeOutElement = (new WebDriverWait(firefoxDriver, 60*15+5))
        .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("blockquote h2")));

    String timeOutText = myTimeOutElement.getText();

    Assert.assertTrue("Error: The timeout error did not display as expected.",
                                   timeOutText.equalsIgnoreCase("Your session has timed out"));
}

References
https://www.seleniumhq.org/docs/04_webdriver_advanced.jsp

No comments:

Post a Comment