I'm running my tests using gradle which is specifying JVM properties in the following manner:
-Dgeb.env=dev -Dgeb.driver=org.openqa.selenium.htmlunit.HtmlUnitDriver
This sets driver and configures environment in Geb config script.
I want to enable JavaScript for HtmlUnit after specifying it in environment property. To be more general, I want to overwrite driver in the config script (I'm not interested in setting driver in every test's setup()
block)
I tried putting the following code snippet in Geb config script:
if (System.getProperty("geb.driver")=="org.openqa.selenium.htmlunit.HtmlUnitDriver") {
driver = {
println "Setting JavaScript"
def driver = new HtmlUnitDriver()
driver.setJavascriptEnabled(true)
driver
}
}
This prints out the message but the tests fail due to
java.lang.UnsupportedOperationException: Javascript is not enabled for this HtmlUnitDriver instance
I'm a bit surprised that you're seeing
Setting JavaScript
printed out but what happens is that your driver closure doesn't get called because if you usegeb.driver
system property then Geb creates the driver for you internally based on that. I suggest you either use the env to create the driver in yourGebConfig.groovy
or use a different system property thangeb.driver
to ask for a given driver impl to be used and manage driver creation yourself.