我正在使用phantomjs2.1.1
,com.github.detro.phantomjsdriver:1.2.0
来运行自动网络测试,
当我正在运行phantomjsdriver
时,有人可以告诉我如何指定正在运行的端口?我想在端口6666上运行phantomjsdriver
下面是输出日志:
INFO: executable: /Users/wtnull/Downloads/phantomjs-2.1.1-macosx/bin/phantomjs
Mar 12, 2016 1:50:16 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: port: 8852
Mar 12, 2016 1:50:16 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: arguments: [--webdriver=8852, --webdriver-logfile=/Users/wtnull/yeepay/ypt/branches/default/ypt-script-sdk/phantomjsdriver.log]
Mar 12, 2016 1:50:16 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: environment: {} [INFO - 2016-03-12T05:50:17.729Z] GhostDriver - Main - running on port 8852
答案 0 :(得分:5)
在我阅读源代码后,我找到了解决方案。
我可以选择使用PhantomJSDriverService.Build()...build()
创建一个phantomJSDriverService,
并通过new PhantomJSDriver(phantomJSDriverService, new DesiredCapabilities())
在Build()
,PhantomJSDriverService
的内部类中,我可以指定运行phantomjsdriver的端口,下面是代码详细信息。
DesiredCapabilities caps = new DesiredCapabilities()
caps.javascriptEnabled = true
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, '/usr/local/bin/phantomjs')
phantomJSDriver = new PhantomJSDriver((new PhantomJSDriverService.Builder())
.usingPhantomJSExecutable(PhantomJSDriverService.findPhantomJS(caps, "https://github.com/ariya/phantomjs/wiki", "http://phantomjs.org/download.html"))
"https://github.com/detro/ghostdriver/downloads"))
.usingPort(6666)
.withProxy(null)
.withLogFile(new File("phantomjsdriver.log"))
.usingCommandLineArguments(PhantomJSDriverService.findCLIArgumentsFromCaps(caps, "phantomjs.cli.args"))
.usingGhostDriverCommandLineArguments(PhantomJSDriverService.findCLIArgumentsFromCaps(caps, "phantomjs.ghostdriver.cli.args") .build(), caps)
oupput日志是:
Mar 13, 2016 3:15:59 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: executable: /usr/local/bin/phantomjs
Mar 13, 2016 3:15:59 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: port: 6666
Mar 13, 2016 3:15:59 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: arguments: [--webdriver=6666, --webdriver-logfile=/Users/wtnull/yeepay/ypt/branches/default/ypt-script-sdk/phantomjsdriver.log]
Mar 13, 2016 3:15:59 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init>
INFO: environment: {}
[INFO - 2016-03-13T07:16:01.085Z] GhostDriver - Main - running on port 6666