請先自行安裝 Phantom JS
pom.xml 加入
<dependency>
<groupId>com.github.detro.ghostdriver</groupId>
<artifactId>phantomjsdriver</artifactId>
<version>1.0.4</version>
</dependency>
上一篇那種寫法,雖然很方便,但是有點小複雜,我改的簡略一點,大家比較好參考。
先提一下可額外設定的變數有兩類
* phantomjs command line
* capabilitie
那要怎麼設呢?看下面這兩個範例
phantomjs {
Capabilities caps = DesiredCapabilities.phantomjs()
PhantomJSDriverService.createDefaultService(caps)
driver = {new PhantomJSDriver(caps)}
}
phantomjs {
DesiredCapabilities caps = new DesiredCapabilities(
'phantomjs.cli.args': [
'--ignore-ssl-errors=true',
'--ssl-protocol=any',
] as String[],
)
caps.setCapability("takesScreenshot", true);
driver = {new PhantomJSDriver(caps)}
}