Silent alert accept issue when calling module method

49 views
Skip to first unread message

Adam Bęben

unread,
Oct 27, 2016, 8:36:55 AM10/27/16
to Geb User Mailing List
Meta:
OS: Windows 7
Selenium version: 2.52.0
Browser: Firefox v.45.4.0
Geb version: 1.0
Groovy version: 2.4.6

Expected Behavior:
Test should throw UnhandledAlertException

Actual Behavior:
Creating module without Navigator context is silently accepting alert

Steps to reproduce:
import geb.Browser

Browser.drive {

    js.exec('alert("ups!")')
    module(SomeSimpleModule)

    assert title == "Geb - Very Groovy Browser Automation"
}

I think the above script should not pass and should throw the UnhandledAlertException. But creating module this way:
module(SomeSimpleModule)
is silently accepting alert instead of throwing UnhandledAlertException.

So the question is: bug or not?

Marcin Erdmann

unread,
Nov 1, 2016, 5:25:50 PM11/1/16
to Geb User Mailing List
Hi Adam,

I've just executed the following script on my machine:

-------------

@Grab("org.gebish:geb-core:1.0")
@Grab("org.seleniumhq.selenium:selenium-firefox-driver:2.53.1")
@GrabExclude("org.codehaus.groovy:groovy-all")
import geb.Browser
import geb.Module

Browser.drive {

    js.exec('alert("ups!")')
    module(SomeSimpleModule)

    assert title == "Geb - Very Groovy Browser Automation"
}

class SomeSimpleModule extends Module {}

---------------

With FF 44.0 installed, using groovy 2.4.5 and got the following exception:

org.openqa.selenium.UnhandledAlertException: Unexpected modal dialog (text: ups!): ups!
Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09'
System info: host: 'Erdis-MacBook-Pro.local', ip: '192.168.1.72', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.6', java.version: '1.8.0_102'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=44.0, platform=MAC, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 8039421b-b0ac-744d-86f3-0779d6c5de99
*** Element info: {Using=xpath, value=/*}
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.createUnhandledAlertException(ErrorHandler.java:187)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:154)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:363)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:500)
at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:355)
at org.openqa.selenium.WebDriver$findElement$0.call(Unknown Source)
at geb.navigator.factory.BrowserBackedNavigatorFactory.createBase(BrowserBackedNavigatorFactory.groovy:39)
at geb.navigator.factory.BrowserBackedNavigatorFactory.getBase(BrowserBackedNavigatorFactory.groovy:45)
at geb.navigator.factory.AbstractNavigatorFactory.getProperty(AbstractNavigatorFactory.groovy)
at geb.content.NavigableSupport.getBase(NavigableSupport.groovy:34)
at geb.content.NavigableSupport.module(NavigableSupport.groovy:207)
at geb.content.Navigable$module.call(Unknown Source)
at geb.Page.module(Page.groovy:491)
at geb.Browser.methodMissing(Browser.groovy:206)
at geb.Browser.invokeMethod(Browser.groovy)
at geb$_run_closure1.doCall(geb.groovy:11)
at geb$_run_closure1.doCall(geb.groovy)
at geb.Browser.drive(Browser.groovy:1061)
at geb.Browser$drive$0.callStatic(Unknown Source)
at geb.Browser.drive(Browser.groovy:1031)
at geb.Browser$drive.call(Unknown Source)
at geb.run(geb.groovy:7)

Are you sure that you're not seeing the exception being thrown? My versions are slightly different than yours but I don't see how that could cause different behaviour for me and for you.

Marcin

--
You received this message because you are subscribed to the Google Groups "Geb User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geb-user+unsubscribe@googlegroups.com.
To post to this group, send email to geb-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/geb-user/dd5245ab-a587-4d43-b92e-9033bcf970ac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Adam Bęben

unread,
Nov 2, 2016, 7:12:49 AM11/2/16
to Geb User Mailing List
Hi Marcin,

Your script is running with exception as well on my machine. It turns out that I had to add baseNavigatorWaiting property in Browser config to reproduce issue with your script:
@Grab("org.gebish:geb-core:1.0")
@Grab("org.seleniumhq.selenium:selenium-firefox-driver:2.53.1")
@GrabExclude("org.codehaus.groovy:groovy-all")
import geb.Browser
import geb.Module

Browser.drive {
    browser.config.baseNavigatorWaiting = true

    js.exec('alert("ups!")')
    module(SomeSimpleModule)

    assert title == "Geb - Very Groovy Browser Automation"
}

class SomeSimpleModule extends Module {}
To unsubscribe from this group and stop receiving emails from it, send an email to geb-user+u...@googlegroups.com.

Marcin Erdmann

unread,
Nov 2, 2016, 3:12:50 PM11/2/16
to Geb User Mailing List
On Wed, Nov 2, 2016 at 11:12 AM, Adam Bęben <abebe...@gmail.com> wrote:

Your script is running with exception as well on my machine. It turns out that I had to add baseNavigatorWaiting property in Browser config to reproduce issue with your script

That explains a lot. 

When using Firefox driver UnhandledAlertException is thrown when executing any Webdriver command that does not target the alert while an alert is displayed. At the point of throwing that exception the alert is also automatically dismissed by the driver. Calling the module(Class) method on a page object (which you are in essence doing in your script down to method delegation on Browser instances) and not on a Navigator requires Geb to obtain a base navigator which is the root element of your document to then use it as the module base (http://www.gebish.org/manual/current/#base-and-context). If you set the baseNavigatorWaiting property then obtaining the base navigator is wrapped in a waitFor statement which swallows any exceptions (as explained in http://www.gebish.org/manual/current/api/geb/waiting/Wait.html#waitFor(Closure%3CT%3E)).

The above is causing the behaviour you're seeing.

Reply all
Reply to author
Forward
0 new messages