Search code examples
firefoxseleniumgeb

Turn off FireFox driver refresh POST warning


I have inherited some GEB tests that are testing logging into a site (and various error cases/validation warnings).

The test runs through some validation failures and then it attempts to re-navigate to the same page (just to refresh the page/dom) and attempts a valid login. Using GEB's to() method, it detects that you are attempting to navigate to the page you are on, it just calls refresh - the problem here is that attempts to refresh the last POST request, and the driver displays the

"To display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier"

message - as the test is not expecting this popup, it hangs and the tests timeout.

Is there a way to turn off these warnings in Firefox webdriver? or to auto-ignore/accept them via Selenium or GEB?

GEB Version: 0.9.2, Selenium Version: 2.39.0

(Also tried with minor version above: 0.9.3 & 2.40.0)

Caveats:

  • I know about the POST/Re-direct/GET pattern - but am not at liberty to change the application code in this case
  • The warning message only causes an issue intermittently (maybe 1 in 5 times) - I have put this down to speed/race conditions whereby the test completes the next actions before the message appears - I know a possible solution is to update tests to wait for message to appear and then accept, but my question is, is there a global setting that can just avoid these being triggered/displayed?

Solution

  • If I understand you issue properly this might help. In Groovy you can modify a class on the fly.

    We use Spock with Geb and I placed this in a Super class which all Spock Spec inherit from. Eg: QSpec extends GebSpec.

    It is the original method slightly modified with the original code commented out so you know what has been changed. I use this technique in several required places to alter Geb behaviour.

    static {
    
        Browser.metaClass.go = { Map params, String url ->
            def newUrl = calculateUri(url, params)
            //          if (driver.currentUrl == newUrl) {
            //              driver.navigate().refresh()
            //          } else {
            //              driver.get(newUrl)
            //          }
            driver.get(newUrl)
            if (!page) {
                page(Page)
            }
        }
    }