LoginSignup
2
2

More than 5 years have passed since last update.

Groovyのちょっとしたこと「gebでhtmlUnitのオプションを設定する方法」

Last updated at Posted at 2015-06-03

driverにクロージャを設定する。
そうすると、GebはBrowser.drive(closure)の際にこのクロージャによって初期化されたDriverを使用する。

以下の設定では、htmlUnitはJavaScriptを実行し、ScriptErrorの際にExceptionを投げない、セキュアでないSSL通信を許可する。
設定可能な項目は、WebClientOptionsを参照してね。

GebConfig.groovy
import geb.driver.DriverRegistry
import geb.driver.NameBasedDriverFactory

driver = (Settings.gebDriver)?Settings.gebDriver:'firefox'

if(driver=='htmlunit'){
  driver = {
    def htmlunitDriver = new NameBasedDriverFactory(classLoader,'htmlunit').getDriver()
    htmlunitDriver.webClient.options.setJavaScriptEnabled(true)
    htmlunitDriver.webClient.options.setThrowExceptionOnScriptError(false)
    htmlunitDriver.webClient.options.setUseInsecureSSL(true)
    htmlunitDriver
  }
}
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2