6

Suppose a webpage has a functionality, it refreshes the whole webpage after a fixed time interval and nothing changes on the webpage.

How we can test this with automation?

4

One possible way is to force a change in a parallel session or in the database with a script. Then you can keep polling for some seconds until the new data becomes visible.

I would expect the feature is not to refresh the page, but to refresh to show new data. Test the feature, not only the known behavior, thus test why the page refreshes instead. Ask yourself how you would test it manually, I guess automated would be the same.

Also in a single page web-application the page does not refresh, only the content is partly updated, making it even harder to check if the page is really updated.

Another way is to ask the development-team to add an invisible counter to the page which you can read out to check the page has finished refreshing. In short ask them to make the application testable for you.

2

Ask development to place a HTML comment that has the timestamp, e.g.

<!-- 06-jan-2016 08:09-->

or add it to the actual page so that tools that have access to the full dom can easily access it, but make it not display on the browser

<div display:none">06-jan-2016 08:09</div>

If it has to be present but not visible then

<div visibility:hidden">06-jan-2016 08:09</div>

Another option is to look into http timestamps as mentioned in
http://code.tutsplus.com/tutorials/http-the-protocol-every-web-developer-must-know-part-1--net-31177
Specifically "The Date header field is used to timestamp the request/response message"

0

You can make use of window.sessionStorage.

  1. You can ask development to define an pre-defined object, for example reloadflag="true".

    • You will check the value for true with window.sessionStorage.getItem("reloadflag")
    • After each check you have to set the value to false with window.sessionStorage.setItem("reloadflag", "false")
  2. If you do not have possibility to make change in development, you can try to hack it, dig in session storage for element, which is always present and "not absolutely necessary" and after reload check you will simply remove that item by window.sessionStorage.removeItem("itemname"). Beware, do not remove cornerstones of the page. By removing or changing an element you can change behaviour of the application. If there is nothing in session storage, you cannot do it.

0

I hope this might help

public void waitForPageLoad(WebDriver driver){
ExpectedCondition<Boolean> expectation = new ExpectedCondition<Boolean>() 
{
    public Boolean apply(WebDriver driver)
    {
        return ((JavascriptExecutor)driver).executeScript("return document.readyState").equals("complete");          }
};
Wait<WebDriver> wait = new WebDriverWait(driver,30);
try
{
    wait.until(expectation);
}
catch(Throwable error)
{
    assertFalse("Timeout waiting for Page Load",true);
}}

In addition to that you can also check whether js actions are performed.

return ((JavascriptExecutor)driver).executeScript("return jQuery.active == 0");
0

An element you interacting become stale when it is destroyed and recreated. Hence when page refreshes, every element in that page become stale. So we can check if the page is refreshed by waiting for an element in that page to become stale. The following Java code illustrate how it is achieved using Selenium webdriver. If the page is not refreshed in 30 seconds, then TimeoutException will be thrown

WebDriverWait wait=new WebDriverWait(driver,30);
try{
       wait.until(ExpectedConditions.stalenessOfElement(element));
}catch(TimeoutException e){
       System.out.println("Page is not refreshed in 30 seconds");
}
  • I'm not sure this would give the OP the desired result. You might want to add more information to describe how checking for a specific element having been refreshed is going to correctly determine whether the entire page has been refreshed. – Kate Paulk Jun 13 '16 at 13:39
  • @KatePaulk Answer updated – stackoverflow Jun 14 '16 at 3:58
0

So the problem with refreshes, and this goes into wait logic as well, is that if nothing is different on the web page, there's really nothing to wait for. So the solution we came up with is to inject something unique on the page, trigger the refresh, wait for that thing that we injected to disappear, and then perform whatever wait logic you usually use for that page to load.

JavascriptExecutor js = (JavascriptExecutor) Browser.driver;
        js.executeScript("arguments[0].appendChild(document.createTextNode('" 
+ textToInject + "'))",
                elementToInjectTextInto, textToInject);

This injects a text node into the specified element. Then you would wait for this element to no longer have the text node.

try {
            WebDriverWait wait = (WebDriverWait) new WebDriverWait(driver, secondsToWait);
        wait.ignoring(NullPointerException.class).until(new Function<WebDriver, Boolean>() {
            public Boolean apply(WebDriver driver) {
                return !driver.findElement(By.xpath("elementXPathGoesHere"))
                        .getAttribute("innerText").contains(textWeInjected);
            }
        });
    } catch (Exception e) {

    }

Then we wait for that element to no longer contain that text.

0

Use a network traffic tool such as Fiddler to capture the traffic; see the Web Debugging page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.