gpt4 book ai didi

selenium - 运行 PhantomJSDriver 时如何指定端口

转载 作者:行者123 更新时间:2023-12-01 11:27:48 26 4
gpt4 key购买 nike

我正在使用 phantomjs2.1.1com.github.detro.phantomjsdriver:1.2.0 运行自动 webui 测试,

当我运行 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

最佳答案

看完源码后,我找到了解决办法。

我可以选择使用 PhantomJSDriverService.Build()...build() 来创建一个 phantomJSDriverService,并通过 new PhantomJSDriver(phantomJSDriverService, new DesiredCapabilities())

获取 phantomjsDriver 实例

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)

输出日志是:

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

关于selenium - 运行 PhantomJSDriver 时如何指定端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35954485/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com