如何使用Ghostdriver分配专用IP地址和端口
我编写了一个GhostdriverMaven Java项目,在该项目中,我使用Ubuntu 14.04 64位中的shell脚本调用了jar文件的许多实例 shell脚本中的每一行都调用jar文件的一个新实例 每行的格式:如何使用Ghostdriver分配专用IP地址和端口,ip,ubuntu-14.04,ghostdriver,Ip,Ubuntu 14.04,Ghostdriver,我编写了一个GhostdriverMaven Java项目,在该项目中,我使用Ubuntu 14.04 64位中的shell脚本调用了jar文件的许多实例 shell脚本中的每一行都调用jar文件的一个新实例 每行的格式: public class className { PhantomJSDriver driver; public static final File PHANTOMJS_EXE = new File("//home/username/phantomjs
public class className {
PhantomJSDriver driver;
public static final File PHANTOMJS_EXE = new File("//home/username/phantomjs/bin/phantomjs");
public className() {
callGhostdriver();
driver.quit();
}
private void callGhostdriver() {
{
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability("phantomjs.binary.path",
PHANTOMJS_EXE.getAbsolutePath());
driver = new PhantomJSDriver(caps);
driver.manage().window().maximize();
actions = new Actions(driver);
}
}
}
screen-dmS name java-jar/path/name.jar arg1 arg2 arg3
目前,我有一个网络接口(eth0)被分成多个网络别名(eth0:1、eth0:2等),每个别名指向一个私有IP,而私有IP又指向一个公共IP
我正试图找到最好的方法,为java程序的每个实例分配一个私有IP和可能的端口号。目前我在程序中调用Ghostdriver
我在程序中调用ghost驱动程序的方式:
public class className {
PhantomJSDriver driver;
public static final File PHANTOMJS_EXE = new File("//home/username/phantomjs/bin/phantomjs");
public className() {
callGhostdriver();
driver.quit();
}
private void callGhostdriver() {
{
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability("phantomjs.binary.path",
PHANTOMJS_EXE.getAbsolutePath());
driver = new PhantomJSDriver(caps);
driver.manage().window().maximize();
actions = new Actions(driver);
}
}
}
任何帮助都将不胜感激
***更新****
我尝试更改callGhostdriver方法,但没有成功
private void callGhostdriver() {
DesiredCapabilities dcaps = new DesiredCapabilities();
dcaps.setCapability(
PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
PHANTOMJS_EXE.getAbsolutePath());
String[] phantomJsArgs = {"--webdriver=172.16.190.131:6781"};
dcaps.setCapability(
PhantomJSDriverService.PHANTOMJS_CLI_ARGS,
phantomJsArgs);
driver = new PhantomJSDriver(dcaps);
driver.manage().window().maximize();
actions = new Actions(driver);
}
参数--webdriver=IP:端口似乎被默认值覆盖
--网络驱动程序呼叫
运行jar的输出:
*2015年4月12日下午5:26:25 org.openqa.selenium.phantomjs.PhantomJSDriverService信息:端口:8651
2015年4月12日下午5:26:25
org.openqa.selenium.phantomjs.PhantomJSDriverService信息:参数:
[--webdriver=172.16.190.131:6781,--webdriver=8651,
--webdriver日志文件=/home/RemovedPath/phantomjsdriver.log]2015年4月12日下午5:26:25 org.openqa.selenium.phantomjs.PhantomJSDriverService
信息:环境:{}[INFO-2015-04-12T21:26:26.584Z]幽灵驱动程序-
主-在端口8651上运行
具有不同专用IP的端口6781应该是它正在使用的,但它使用的是8651。试试这个-->
List cliArgsCap=Arrays.asList(
“--webdriver=172.16.190.131:6781”);
dcaps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS,cliArgsCap)代码>我找到了一种黑客方法来设置端口,但仍然没有弄清楚如何设置私有ip,我可能不得不使用iptables来路由流量
private void loadLightWeightDriverCustom() {
ArrayList<String> cliArgsCap = new ArrayList();
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, PHANTOMJS_EXE.getAbsolutePath());
cliArgsCap.add("--web-security=false");
cliArgsCap.add("--ssl-protocol=any");
cliArgsCap.add("--ignore-ssl-errors=true");
capabilities.setCapability(
PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);
driver = new PhantomJSDriver(Configure(cliArgsCap), capabilities);
}
private PhantomJSDriverService Configure(ArrayList<String> cap) {
return new PhantomJSDriverService.Builder().usingPhantomJSExecutable(PHANTOMJS_EXE)
.usingPort(5555)
.usingCommandLineArguments(
(cap.toArray(new String[cap.size()])))
.build();
}
private void loadLightweightDriverCastom(){
ArrayList cliArgsCap=新的ArrayList();
DesiredCapabilities=新的DesiredCapabilities();
setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_属性,PHANTOMJS_EXE.getAbsolutePath());
cliArgsCap.add(“--websecurity=false”);
cliArgsCap.add(“--ssl协议=any”);
cliArgsCap.add(“--ignoressl errors=true”);
能力。设置能力(
PhantomJSDriverService.PHANTOMJS_CLI_ARGS,cliArgsCap);
驱动程序=新的PhantomJSDriver(配置(cliArgsCap),功能);
}
专用PhantomJSDriverService配置(ArrayList cap){
使用PhantomJSExecutable(PHANTOMJS_EXE)返回新的PhantomJSDriverService.Builder()
.使用端口(5555)
.使用CommandLineArguments(
(cap.toArray(新字符串[cap.size()]))
.build();
}
我找到了--webdriver命令的修复程序,我编译了这个jar并将其加载。现在我越来越紧张了
Apr 24, 2015 10:35:04 AM org.openqa.selenium.phantomjs.PhantomJSDriverService
INFO: executable: C:*Removed Path\phantomjs-2.0.0-windows\bin\phantomjs.exe
Apr 24, 2015 10:35:04 AM org.openqa.selenium.phantomjs.PhantomJSDriverService
INFO: port: 41533
Apr 24, 2015 10:35:04 AM org.openqa.selenium.phantomjs.PhantomJSDriverService
INFO: arguments: [--webdriver=127.0.0.1:6666, --webdriver-logfile=C:\Removed Path*\phantomjsdriver.log]
Apr 24, 2015 10:35:04 AM org.openqa.selenium.phantomjs.PhantomJSDriverService
INFO: environment: {}
[INFO - 2015-04-24T14:35:06.222Z] GhostDriver - Main - running on port 6666
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.45.0', revision: '5017cb8e7ca8e37638dc3091b2440b90a1d8686f', time: '2015-02-27 09:10:26'
System info: host: 'MBC5708', ip: '167.74.185.13', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_45'
Driver info: driver.version: PhantomJSDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:593)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:126)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:139)
我调用phantomjs的方法是:
ArrayList<String> cliArgsCap = new ArrayList<String>();
DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
cliArgsCap.add("--webdriver=6666");
capabilities.setCapability(
PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,PHANTOMJS_EXE.getAbsolutePath());
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);
driver = new PhantomJSDriver(capabilities);
ArrayList cliArgsCap=new ArrayList();
DesiredCapabilities=DesiredCapabilities.phantomjs();
cliArgsCap.add(“--webdriver=6666”);
能力。设置能力(
PhantomJSDriverService.PHANTOMJS_可执行文件_路径_属性,PHANTOMJS_EXE.getAbsolutePath();
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS,cliArgsCap);
驱动程序=新的PhantomJSDriver(功能);
不幸的是,这不起作用,它给我的输出与我之前发布的“信息:参数:[--webdriver=172.16.190.131:6781,--webdriver=3205,--webdriver logfile=/home/RemovedPath/phantomjsdriver.log]2015年4月12日下午5:26:25”[INFO-2015-04-13T22:05:13.944Z]GhostDriver-Main-在端口3205上运行,因此它似乎覆盖了我为webdriver输入的另一个webdriver参数。我可以设置所有功能,但是--webdriver=port,似乎您无法更改它,或者它是一个bug?我至少可以更改它使用的端口吗?这样我就可以使用iptables来管理流量。目前它只是随机选择一个端口。哈,一定有更好的方法来实现这一点。