Question

I'm struggling to add a node with many concurrent PhantomJS instances. On GhostDriver github page you can find instructions which will register one node with only one instance of PhantomJS:

phantomjs --webdriver=8080 --webdriver-selenium-grid-hub=http://127.0.0.1:4444

I'm not allowed to post images so here is the grid view after adding a node with following method: enter image description here

Here's configuration tab content:

port:6666
servlets:[]
host:null
cleanUpCycle:5000
browserTimeout:0
hubHost:127.0.0.1
registerCycle:5000
hub:http://127.0.0.1:4444/grid/register/
capabilityMatcher:org.openqa.grid.internal.utils.DefaultCapabilityMatcher
newSessionWaitTimeout:-1
url:http://127.0.0.1:6666
remoteHost:http://127.0.0.1:6666
prioritizer:null
register:true
throwOnCapabilityNotPresent:true
nodePolling:5000
proxy:org.openqa.grid.selenium.proxy.DefaultRemoteProxy
maxSession:1
role:wd
jettyMaxThreads:-1
hubPort:4444
timeout:300000

Since selenium grid allows to define node browsers from command line I tried to do so with phantomjs, but as you can see here it's not supported.

Parameters allowed for -browser: browserName={android, chrome, firefox, htmlunit, internet explorer, iphone, opera} version={browser version} firefox_binary={path to executable binary} chrome_binary={path to executable binary} maxInstances={maximum number of browsers of this type} platform={WINDOWS, LINUX, MAC}

Was it helpful?

Solution

struggling agaist the same issue: I'm expected to implement the following architecture (the screen below): archtecture

But I'm facing the following issue: 1) in case we configure selenium-server- with the following params ( configured on UI way of execution, i.e over either ffox,chrome or IE) like

java -jar  selenium-server-standalone-2.41.0.jar -role node -hub htt
p://localhost:4444/grid/register -port 7575 -browser  browserName=firefox,maxIns
tances=5,platform=WINDOWS

then we obtain result needed : http://gyazo.com/6cd19155c78a59b22a09f4a3da3439b5 I would like to pay your attention that main parameter that makes it possible is: -browser browserName=firefox,maxInstances=5,platform=WINDOWS

But in case of e.g GhostDriver over phantomJs we are expected to launch not selenium-server-.jar but phantomjs.exe app, which does not support -browser parameter: unknown parameter unknown parameter 2

In accordance to the list of allowed phantomjs parameters I've managed to launch only 1 phantom jsInstance in comparison to 5 concurrent instances of firefox.

Probably that may help you - now I'm reorgainizing my test architecture and will try to adjust to the following: 1 NODE = 1 PhantomJs instance. reorganized test architecture

On localhost it is possible to run many nodes (IE, Ffox, Chrome) with different ports: http://gyazo.com/302fab9b6722251aa2cc6d98e2522931


This solution worked for me:

  • some words about project structure : I've got linux machine (192.34.61.205, selenium hub is runnin here) and ~20 phantomJs nodes related to it: http://gyazo.com/0a3a50f2ee1638d10b1766e300438891 On all nodes phantomJs is running as service ( in order to restart phantomJs on node just enter command sudo service phantomjs restart )

some of nodes have the following IPs: 162.243.175.134 162.243.175.97 162.243.175.252 ....

public class BrowserOneInstance extends BaseMethodsForMultipleBrowsers {

    private WebDriver driver;

    private final static Logger log = LoggerFactory.getLogger(BrowserOneInstance.class);
    public static LoginPage loginPage;
    public static FacebookUserPage homePage;

    FileOperations fileManipulator = new FileOperations();


//staring   hub - nodes model (on local WIN machine) over GhostDriver- pHantomJS

    @BeforeClass
    public void seleniumGrridUponGhostDriver() throws MalformedURLException {


//        File phantomjs = Phanbedder.unpack(); //Phanbedder to the rescue!

        File phantomjs = new File(System.getProperty("java.io.tmpdir")+File.separator+"phantomjs-1.9.7");


        DesiredCapabilities dcaps = new DesiredCapabilities();
        dcaps.setCapability("takesScreenshot", true);


        dcaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantomjs.getAbsolutePath());

// !!!!! hardCoded initizliations of GhostDriver node
//        driver = new RemoteWebDriver(new URL("http://localhost:8080"), dcaps);

//    driver initialization   using  method  providing IP of running Ghost node connected to running hub
//        this.driver= new RemoteWebDriver(new URL("http://"+getGhostNodesIp()+":8080"),dcaps);

//        node  connected to linux hub:
        this.driver = new RemoteWebDriver(new URL("http://162.243.175.134:8080"), dcaps);


        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);

        //page instances init()
        loginPage = PageFactory.initElements(driver, LoginPage.class);
        homePage = PageFactory.initElements(driver, FacebookUserPage.class);
    }

      @Test
 public void abracadabraTestMethod(){

  ....
 }


        @AfterTest
    public void driverTearDown() {
//        close any of the instances: either Firefox or GhostDriver
        driver.quit();
    }

}

NOTE:

if you like to make phantomJs work in a crossplatform way eliminating manual substitution you can use Phanbedder - PhantomJS Windows/Mac OS X/Linux native binary embedder:

import net.anthavio.phanbedder.Phanbedder;

......

 @BeforeClass
    public void seleniumGrridUponGhostDriver() throws MalformedURLException {

        File phantomjs = Phanbedder.unpack(); //Phanbedder to the rescue!


        DesiredCapabilities dcaps = new DesiredCapabilities();
        dcaps.setCapability("takesScreenshot", true);


        dcaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantomjs.getAbsolutePath());


        this.driver = new RemoteWebDriver(new URL("http://162.243.175.134:8080"), dcaps);

......

Hope this works for you.

OTHER TIPS

I got this working with my own Docker container: https://github.com/madhavajay/selenium-node-phantomjs

It uses PhantomJS 2.1.1 Custom Build and then my own modifications to Ghostdriver to allow --remoteHost so that the Grid can connect back to the Docker container no matter which host it is on.

I hope this helps someone else. :)

Docker Hub: madhavajay/selenium-node-phantomjs

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top