Tuesday, 8 November 2011

Groovy Geb tests: enabling Javascript for HTMLUnit driver

Ran into a problem where my HTMLUnit driver wouldn't execute Javascript on my pages. Found a simple fix:

import org.openqa.selenium.htmlunit.HtmlUnitDriver
import geb.spock.GebSpec

class TestSomething extends GebSpec {

def setup() {
if (driver instanceof HtmlUnitDriver) {
driver.javascriptEnabled = true

I'm going to stick this in a base class that extends GebSpec that all my test classes can then inherit from.


Ricardo said...

Nice! Thank you.

MichaƂ said...

Use configuration in GebConfig.groovy

driver = {
def driver = new HtmlUnitDriver()
driver.javascriptEnabled = true