4

I wrote a Ghostdriver Maven Java project where I call many instances of the jar file using a shell script in Ubuntu 14.04 64bit.

Each line in my shell script calls a new instance of my jar file.

The format of each line:

screen -dmS name java -jar /path/name.jar arg1 arg2 arg3

Currently I have 1 network interface (eth0) split up into multiple network aliases (eth0:1, eth0:2, etc), each alias points to a private IP which in turns points to a public IP.

I am trying to find the best way to allocate a private IP and possibly port number to each instance of my java program. Currently I call Ghostdriver inside my program.

The way I call ghost driver within my program:

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);
        }
    }
}

Any help would be greatly appreciated.

***Update****

I tried changing the callGhostdriver method but had no success.

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);
}

Argument --webdriver=IP:PORT seems to be overridden by a default --webdriver call.

Output from running jar:

*Apr 12, 2015 5:26:25 PM org.openqa.selenium.phantomjs.PhantomJSDriverService INFO: port: 8651 Apr 12, 2015 5:26:25 PM org.openqa.selenium.phantomjs.PhantomJSDriverService INFO: arguments: [--webdriver=172.16.190.131:6781, --webdriver=8651, --webdriver-logfile=/home/RemovedPath/phantomjsdriver.log] Apr 12, 2015 5:26:25 PM org.openqa.selenium.phantomjs.PhantomJSDriverService INFO: environment: {} [INFO - 2015-04-12T21:26:26.584Z] GhostDriver - Main - running on port 8651

Port 6781 with the different private IP should be what it is using but it uses 8651 instead.

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
Hydtek
  • 161
  • 1
  • 12
  • I can set every capability but --webdriver=port, seems like you cannot change it, or it's a bug? – Hydtek Apr 15 '15 at 00:50
  • Can I at least change the port that it uses? This way I can use iptables to manage traffic. Currently it just picks a port at random. – Hydtek Apr 15 '15 at 22:51

3 Answers3

2

I was able to find a hackish way to set the port but still haven't figured out how to set the private ip, I may have to use iptables to route the traffic.

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();
}
Hydtek
  • 161
  • 1
  • 12
1

Try this --> List<String> cliArgsCap = Arrays.asList( "--webdriver=172.16.190.131:6781"); dcaps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);

  • Unfortunately this did not work, it gave me the same output that I previously posted "INFO: arguments: [--webdriver=172.16.190.131:6781, --webdriver=3205, --webdriver-logfile=/home/RemovedPath/phantomjsdriver.log] Apr 12, 2015 5:26:25 PM " [INFO - 2015-04-13T22:05:13.944Z] GhostDriver - Main - running on port 3205 so it seems like its overriding what I put in for webdriver with another webdriver argument. – Hydtek Apr 13 '15 at 22:37
0

I was able to find a fix to the --webdriver command, https://github.com/detro/ghostdriver/pull/438, I compiled that jar and loaded it in. Now I am getting

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)

My method invoking phantomjs is:

  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);
Hydtek
  • 161
  • 1
  • 12