Help Needed to run parallel in Selenium Grid!

1,570 views
Skip to first unread message

sirus tula

unread,
Aug 28, 2013, 3:42:57 PM8/28/13
to seleniu...@googlegroups.com, selenium...@gmail.com
Hello Selenium Experts,

After getting two VM's after long request, I tried to ran my regression script parallell in two VM's which is node 1 and node 2 from hub but got into lot of errors.

My regression scripts works just fine if i run in one VM or my local host machine but if i distribute my script into multiple VM's, my scripts
keep on failing all the time.

Is there any reason why it's failing if i try to run in more than one machine? 

Can it be a thread issue or do i need to set up something in order to make it run smoothly?

Any help would be appreciated.


Below are my whole regression selenium grid configuration files.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------

//hub json file
{
  "host": 10.###.###.43, // hub IP
  "port": 4444,
  "newSessionWaitTimeout": -1,
  "servlets" : [],
  "prioritizer": null,
  "capabilityMatcher": "org.openqa.grid.internal.utils.DefaultCapabilityMatcher",
  "throwOnCapabilityNotPresent": true,
  "nodePolling": 5000,

  "cleanUpCycle": 5000,
  "timeout": 300000,
  "browserTimeout": 0,
  "maxSession": 5
}

//node1 json file
{
  "capabilities":
      [
        {
          "browserName": "firefox",
          "maxInstances": 5,
          "seleniumProtocol": "WebDriver"
        },
        {
          "browserName": "chrome",
          "maxInstances": 5,
          "seleniumProtocol": "WebDriver"
        },
        {
          "platform": "WINDOWS",
          "browserName": "internet explorer",
          "maxInstances": 1,
          "seleniumProtocol": "WebDriver"
        }
      ],
  "configuration":
  {
    "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
    "maxSession": 5,
    "port": "6666",
    "host": "10.###.###.53",    //VM IP
    "register": true,
    "registerCycle": 5000,
    "hubHost": "10.##.##",     //
    "hubPort": 4444
  }
}


//node2 json file
{
  "capabilities":
      [
        {
          "browserName": "firefox",
          "maxInstances": 5,
          "seleniumProtocol": "WebDriver"
        },
        {
          "browserName": "chrome",
          "maxInstances": 5,
          "seleniumProtocol": "WebDriver"
        },
        {
          "platform": "WINDOWS",
          "browserName": "internet explorer",
          "maxInstances": 1,
          "seleniumProtocol": "WebDriver"
        }
      ],
  "configuration":
  {
    "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
    "maxSession": 5,
    "port": "6666",
    "host": "10.###.###.53",    //VM IP
    "register": true,
    "registerCycle": 5000,
    "hubHost": "10.##.##",     //Hub IP
    "hubPort": 4444
  }
}

//Driver script that runs firefox

public static String hubURL = "http://localhost:4444/wd/hub";

DesiredCapabilities capabilities= DesiredCapabilities.firefox();
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setCapability("platform", Platform.WINDOWS);
try {
    // add url to environment variables to avoid releasing with source
    driver = new RemoteWebDriver(new URL(hubURL), capabilities);
    driver.manage().window().maximize();
    System.out.println("Starting firefox version 10.0 in grid VM");

} catch (MalformedURLException e) {
    e.printStackTrace();
}

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Suite XML File  ( Works fine if i run one by one but when i run parallel in two VM's it keeps failing).

<suite name="RegressionSuite" parallel="classes" thread-count="2" >
    <!--
    <listeners>
        <listener class-name="library.PriorityInterceptor" />
    </listeners> -->
    <test name="RegressionSuite" preserve-order="false">
    <classes>

        <class name="TestScripts.Test1" />    
        <class name="TestScripts.Test2" />
        <class name="TestScripts.Test3" />
        <class name="TestScripts.Test4" />
        <class name="TestScripts.Test5" />
        <class name="TestScripts.Test6" />
</classes>
   </test>
 </suite>

---------------------------------------------------------------------------------------------------------

//startmyhub batch file
cd C:\selenium\tools\selenium-grid
java -jar selenium-server-standalone-2.30.0.jar -role hub -hubConfig hub.json


//startnode1 batch file
cd C:\selenium\tools\selenium-grid
java -jar selenium-server-standalone-2.30.0.jar -role node -nodeConfig node1.json

//startnode2 batch file
cd C:\selenium\tools\selenium-grid
java -jar selenium-server-standalone-2.30.0.jar -role node -nodeConfig node2.json


--
 
- "If you haven't suffered, you haven't lived your life."
 
Thanks,
 
Sirus

David Lai

unread,
Aug 28, 2013, 6:40:58 PM8/28/13
to seleniu...@googlegroups.com, selenium...@gmail.com
If the nodes are running on the same physical IP address, it's good to have the nodes are different ports.  But I'm thinking that would normally cause problems with the nodes joining themselves, and you'd pick up the issue before the first heartbeat.

can you post your stack trace?

sirus tula

unread,
Aug 29, 2013, 10:01:56 AM8/29/13
to seleniu...@googlegroups.com
Thank you David for your reply.

If I understood your question, I am registering node 1 and node 2 (which are two VM's that has different IP address) to one hub(one VM) and I am able to register them succesfully.

When i run my regression scripts in one VM or my local machine with only one thread, it runs succesfully but when i run it parallel in two or more threads in one local machine or two VM's, it's failing with intermittent errors saying connection refused 

Below is the stack error.

Exception in thread "pool-2-thread-2" org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: '2.32.0', revision: '6c40c187d01409a5dc3b7f8251859150c8af0bcb', time: '2013-04-09 10:39:28'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_17'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:569)
at org.openqa.selenium.firefox.FirefoxDriver.getScreenshotAs(FirefoxDriver.java:316)
at Util.ScreenshotListener.onTestFailure(ScreenshotListener.java:27)
at org.testng.internal.Invoker.runTestListeners(Invoker.java:1796)
at org.testng.internal.Invoker.runTestListeners(Invoker.java:1780)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1230)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Caused by: org.apache.http.conn.HttpHostConnectException: Connection to http://###.##.0.1:#### refused
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:190)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:151)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:125)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:640)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:479)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
at org.openqa.selenium.remote.HttpCommandExecutor.fallBackExecute(HttpCommandExecutor.java:316)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:295)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.execute(NewProfileExtensionConnection.java:133)
at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.execute(FirefoxDriver.java:355)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527)
... 11 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:75)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
at java.net.Socket.connect(Socket.java:579)
at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:127)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180)
... 21 more


Any advice/suggestions would be helpful.


On Thu, Aug 29, 2013 at 9:01 AM, sirus tula <selenium...@gmail.com> wrote:
Thank you David for your reply.

If I understood your question, I am registering node 1 and node 2 (which are two VM's that has different IP address) to one hub(one VM) and I am able to register them succesfully.

When i run my regression scripts in one VM or my local machine with only one thread, it runs succesfully but when i run it parallel in two or more threads in one local machine or two VM's, it's failing with intermittent errors saying connection refused 

Below is the stack error.

Exception in thread "pool-2-thread-2" org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: '2.32.0', revision: '6c40c187d01409a5dc3b7f8251859150c8af0bcb', time: '2013-04-09 10:39:28'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_17'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:569)
at org.openqa.selenium.firefox.FirefoxDriver.getScreenshotAs(FirefoxDriver.java:316)
at Util.ScreenshotListener.onTestFailure(ScreenshotListener.java:27)
at org.testng.internal.Invoker.runTestListeners(Invoker.java:1796)
at org.testng.internal.Invoker.runTestListeners(Invoker.java:1780)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1230)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Caused by: org.apache.http.conn.HttpHostConnectException: Connection to http://###.##.0.1:#### refused
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:190)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:151)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:125)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:640)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:479)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
at org.openqa.selenium.remote.HttpCommandExecutor.fallBackExecute(HttpCommandExecutor.java:316)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:295)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.execute(NewProfileExtensionConnection.java:133)
at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.execute(FirefoxDriver.java:355)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527)
... 11 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:75)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
at java.net.Socket.connect(Socket.java:579)
at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:127)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180)
... 21 more


Any advice/suggestions would be helpful.

sirus tula

unread,
Aug 29, 2013, 10:03:13 AM8/29/13
to seleniu...@googlegroups.com
Thank you David for your reply.

If I understood your question, I am registering node 1 and node 2 (which are two VM's that has different IP address) to one hub(one VM) and I am able to register them successfully.

sirus tula

unread,
Aug 29, 2013, 5:13:32 PM8/29/13
to seleniu...@googlegroups.com
Any help would be highly appreciated

Nick Oppersdorff

unread,
Aug 29, 2013, 6:38:51 PM8/29/13
to seleniu...@googlegroups.com

Try running each node individually and see if the test will run successfully against each of the nodesindependently.
Have you double checked firewall settings?
Are all machines in the grid running the same version of Selenium and Java?

sirus tula

unread,
Aug 30, 2013, 9:58:23 AM8/30/13
to seleniu...@googlegroups.com
Thank you for your reply, Nick.

I am able to run my test successfully against each nodes independently. However when I tried to run my script against two or three nodes parallel from TestNG from my hub, then i get all sorts of errors.  One of them is shown below.

I am pretty sure everyone is running their script against multiple VM's. I hope if anyone can help me debug this problem.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/eb8589e5-075f-4295-98af-6e88eb9d7023%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

David Lai

unread,
Aug 30, 2013, 12:16:00 PM8/30/13
to seleniu...@googlegroups.com
can't really say what's wrong.  You might want to pop open a browser window and check the status of selenium grid before and after running your tests.  If if the browsers and machiens are joining correctly and you're getting the expected browser instances.  After that, I'd look at the capabilities settings.  Make sure the capabilities settings match an expected browser you have available.  


sirus tula

unread,
Aug 30, 2013, 12:29:50 PM8/30/13
to seleniu...@googlegroups.com
Thank you David for your reply again.  Yes, I am not sure what's wrong either. I might think it might be thread issue or JVM crashes for some reason.

When I look at the status of my grid, after starting my grid running in three VM's, I see all of them are used as it first starts in all three VM's. 

However, After the script fails in one VM or completes the script in one VM, it takes atleast 5 or 10 mins to start on that VM again. So overall, it's not using all three VM's at the same time although they are registered to the main hub.

I am frustrated trying to run my scripts in all three VM's at the same time. While it works perfect running in one local host or VM node, it's failing with intermittent errors running via grid in three VMs.

Have you had success running your script in different VM's succesfully without any errors?

If yes, if you could share your driver script that runs the selenium grid, that would be great.

Below is my driver manager file that runs my script in grid.

Thank you again for  your help.
--------------------------------------------------------------------------------------------------------------------------------------------
import Data.Browser;
import com.opera.core.systems.OperaDriver;
import org.omg.PortableInterceptor.TRANSPORT_RETRY;
import org.openqa.selenium.Platform;
import org.openqa.selenium.UnsupportedCommandException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.log4testng.Logger;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * A singleton style manager to maintain Drivers to prevent
 * test slowdown for creating a browser for each class with tests.
 *
 * Also counts time to start a browser and extrapolates from that how much
 * time you have saved using such hacky code.
 */
public class SeleniumGridManager extends Thread{



    private static WebDriver aDriver=null;
    private static long browserStartTime = 0L;
    private static long savedTimecount = 0L;
    public static final long DEFAULT_TIMEOUT_SECONDS = 10;
    private static boolean avoidRecursiveCall=false;
    public static final String BROWSER_PROPERTY_NAME = "selenium2Basics.webdriver";

    public enum BrowserName{FIREFOX, GOOGLECHROME, SAUCELABS, OPERA, IE, HTMLUNIT}

    public static BrowserName currentDriver;
    public static DesiredCapabilities capabilities;

    private static BrowserName useThisDriver = null;


    public static String hubURL = "http://localhost:4444/wd/hub";

    public static void set(BrowserName aBrowser){
        useThisDriver = aBrowser;

        // close any existing driver
        if(aDriver != null){
            aDriver.quit();
            aDriver = null;
        }
    }

    public static WebDriver get() {

        if(useThisDriver == null){


            String defaultBrowser = System.getProperty(BROWSER_PROPERTY_NAME, "FIREFOX");

            BrowserName b= BrowserName.valueOf(defaultBrowser);

            switch (b){
                case FIREFOX:
                    useThisDriver = BrowserName.FIREFOX;
                    break;
                case GOOGLECHROME:
                    useThisDriver = BrowserName.GOOGLECHROME;
                    break;
                case IE:
                    useThisDriver = BrowserName.IE;
                    break;
                case OPERA:
                    useThisDriver = BrowserName.OPERA;
                    break;
                case SAUCELABS:
                    useThisDriver = BrowserName.SAUCELABS;
                    break;
                case HTMLUNIT:
                    useThisDriver = BrowserName.HTMLUNIT;
                    break;
                default:
                    throw new RuntimeException("Unknown Browser in " + BROWSER_PROPERTY_NAME + ": " + defaultBrowser);
            }

        }


        if(aDriver==null){


            long startBrowserTime = System.currentTimeMillis();

            switch (useThisDriver) {
                case FIREFOX:
                        DesiredCapabilities capabilities= DesiredCapabilities.firefox();
                        capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
                        //capabilities.setCapability(CapabilityType.SUPPORTS_APPLICATION_CACHE, true);
                        //capabilities = DesiredCapabilities.firefox();
                        //capabilities.setCapability("version", "10.0");
                        capabilities.setCapability("platform", Platform.WINDOWS);
                     try {
                            // add url to environment variables to avoid releasing with source
                            aDriver = new RemoteWebDriver(new URL(hubURL), capabilities);
                            aDriver.manage().window().maximize();
                            System.out.println("Starting firefox version 10.0 in grid VM");

                        } catch (MalformedURLException e) {
                            e.printStackTrace();
                        }


                        currentDriver = BrowserName.FIREFOX;
                        System.out.println("Starting Browser: " +useThisDriver);
                        break;



                case OPERA:

                    aDriver = new OperaDriver();
                    currentDriver = BrowserName.OPERA;
                    System.out.println("Starting Browser: " +useThisDriver);
                    break;

                case HTMLUNIT:

                    aDriver = new HtmlUnitDriver();
                    currentDriver = BrowserName.HTMLUNIT;
                    System.out.println("Starting Browser: " +useThisDriver);
                    break;

                case IE:

                    setDriverPropertyIfNecessary("webdriver.ie.driver", "/tools/iedriver_64/IEDriverServer.exe", "C:/ahj/HC/tools/webdrivers/iedriver_64/IEDriverServer.exe");

                    //aDriver = new InternetExplorerDriver();
                    //currentDriver = BrowserName.IE;
                    try {
                    DesiredCapabilities capabilities2 = DesiredCapabilities.internetExplorer();
                    capabilities2.setCapability("enableNativeEvents", true);
                    capabilities2.setCapability("requireWindowFocus", true);
                    capabilities2.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
                    //capabilities2 = DesiredCapabilities.internetExplorer();


                    //capabilities.setCapability("version", "8");
                    //capabilities.setCapability("platform", Platform.ANY);
                        try {
                            // add url to environment variables to avoid releasing with source
                            //String sauceURL = System.getenv("SAUCELABS_URL");
                            aDriver = new RemoteWebDriver(new URL(hubURL),capabilities2);
                            aDriver.manage().window().maximize();
                            System.out.println("Starting IE version 8 in grid VM");
                        } catch (MalformedURLException e) {
                            e.printStackTrace();
                        }

                    }

                    catch(Exception e) {
                        aDriver = new InternetExplorerDriver();
                        aDriver.manage().window().maximize();
                        System.out.println("Starting IE version 9 in windows local host computer");
                    }

                    currentDriver = BrowserName.IE;
                    System.out.println("Starting Browser: " +useThisDriver);
                    break;
                case GOOGLECHROME:

                    setDriverPropertyIfNecessary("webdriver.chrome.driver",".../chromedriver.exe","C:/ahj/HC/tools/chromedriver/chromedriver.exe");
                    //String chromeDriverLocation = currentDir + "/tools/chromedriver/chromedriver.exe";
                    ChromeOptions options = new ChromeOptions();
                    options.addArguments("--ignore-certificate-errors");
                    options.addArguments("disable-plugins");
                    options.addArguments("disable-extensions");

                    aDriver = new ChromeDriver(options);
                    aDriver.manage().window().maximize();

                    capabilities = DesiredCapabilities.chrome();
                    //capabilities.setCapability("version", "9");
                    //capabilities.setCapability("platform", Platform.ANY);
                    try {
                        // add url to environment variables to avoid releasing with source
                        //String sauceURL = System.getenv("SAUCELABS_URL");
                        aDriver = new RemoteWebDriver(
                                new URL(hubURL),
                                capabilities);
                    } catch (MalformedURLException e) {
                        e.printStackTrace();
                    }

                    currentDriver = BrowserName.GOOGLECHROME;
                    System.out.println("Starting Browser: " +useThisDriver);
                    break;

                case SAUCELABS:

                    capabilities = DesiredCapabilities.firefox();
                    capabilities.setCapability("version", "5");
                    capabilities.setCapability("platform", Platform.XP);
                    try {
                        // add url to environment variables to avoid releasing with source
                        String sauceURL = System.getenv("SAUCELABS_URL");
                        aDriver = new RemoteWebDriver(
                                new URL(sauceURL),
                                capabilities);
                    } catch (MalformedURLException e) {
                        e.printStackTrace();
                    }
                    currentDriver = BrowserName.SAUCELABS;
                    System.out.println("Starting Browser: " +useThisDriver);
                    break;
            }


            long browserStartedTime = System.currentTimeMillis();
            browserStartTime = browserStartedTime - startBrowserTime;

            // we want to shutdown the shared brower when the tests finish
            Runtime.getRuntime().addShutdownHook(
                    new Thread(){
                        public void run(){
                            DriverManager.quit();
                        }
                    }
            );

        }else{

            try{
                // is browser still alive
                if(aDriver.getWindowHandle()!=null){
                    // assume it is still alive
                }
            }catch(Exception e){
                if(avoidRecursiveCall){
                    // something has gone wrong as we have been here already
                    throw new RuntimeException();
                }

                quit();
                aDriver=null;
                avoidRecursiveCall = true;
                return get();
            }

            savedTimecount += browserStartTime;
            System.out.println("Saved another " + browserStartTime + "ms : total saved " + savedTimecount + "ms");
        }

        avoidRecursiveCall = false;
        return aDriver;
    }

    protected static void setDriverPropertyIfNecessary(String propertyKey, String relativeToUserPath, String absolutePath) {

        if(!System.getProperties().containsKey(propertyKey)){

            String currentDir = System.getProperty("user.dir");
            String chromeDriverLocation = currentDir + relativeToUserPath;
            File driverExe = new File(chromeDriverLocation);
            if(driverExe.exists()){
                System.setProperty(propertyKey, chromeDriverLocation);
            }else{
                driverExe = new File(absolutePath);
                if(driverExe.exists()){
                    System.setProperty(propertyKey, absolutePath);
                }else{
                    // expect an error on the follow through when we try to use the driver
                }
            }
        }
    }

    public static WebDriver get(String aURL, boolean maximize){
        get();
        aDriver.get(aURL);
        if(maximize){
            try{
                aDriver.manage().window().maximize();
            }catch(UnsupportedCommandException e){
                System.out.println("Remote Driver does not support maximise");
            }catch(UnsupportedOperationException e){
                System.out.println("Opera driver does not support maximize yet");
            }
        }
        return aDriver;
    }

    public static WebDriver get(String aURL){
        return get(aURL,true);
    }


    public static void quit(){
        if(aDriver!=null){
            System.out.println("total time saved by reusing browsers " + savedTimecount + "ms");
            try{
                aDriver.quit();
                aDriver=null;
            }catch(Exception e){
                // I don't care about errors at this point
            }

        }
    }
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------


On Fri, Aug 30, 2013 at 11:16 AM, David Lai <sbs...@gmail.com> wrote:
can't really say what's wrong.  You might want to pop open a browser window and check the status of selenium grid before and after running your tests.  If if the browsers and machiens are joining correctly and you're getting the expected browser instances.  After that, I'd look at the capabilities settings.  Make sure the capabilities settings match an expected browser you have available.  


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

Nick Oppersdorff

unread,
Aug 30, 2013, 1:08:06 PM8/30/13
to seleniu...@googlegroups.com
Is each node connecting to the hub via a different port?

How are you calling your get() methods?  From within the @Test method? or the @Before method?  If from one particular way then try the other.

sirus tula

unread,
Aug 30, 2013, 1:50:15 PM8/30/13
to seleniu...@googlegroups.com
Hi Nick, 

That's correct. 

The port are different for every node as mentioned in the json file in the original post and I see all three nodes running first time when I start my selenium scripts. 

After the tests completes in VM, I see only one running and other two unused in localhost:444/grid/console.  It takes more than 5 mins then it starts on two VM's or three VM's. I think once it gets error, it takes enormous amount of time to kill the JVM machine and start new test.

----------------------------------------------------------------------------------------------
Here's the basic script which is NOT the one i'm running but it replicates my test case as it uses the "Drivermanager" class that instantiates the browser.

public class GoogleTest  {
    private WebDriver driver;
    private String baseUrl;
    private StringBuffer verificationErrors = new StringBuffer();
    DataSet Properties = new DataSet();

    @BeforeMethod
    public void setUp() throws Exception {
        driver= DriverManager.get();
        baseUrl= "http://www.gmail.com";
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }

    @Test
    public void Create_New_Account() throws Exception {

        driver.navigate().to(baseUrl);
        if (isElementPresent(By.cssSelector("div[class='T-I J-J5-Ji T-I-KE L3']")))             //checking for Compose button
        {
            System.out.println("Already logged in");
        }

        else
        {
            System.out.println("Loggin in");
            driver.findElement(By.id("Email")).isDisplayed();
            driver.findElement(By.id("Email")).sendKeys("<username>");
            driver.findElement(By.id("Passwd")).sendKeys("<password>");
            driver.findElement(By.id("signIn")).click();
            if (!isElementPresent(By.cssSelector("div[class='T-I J-J5-Ji T-I-KE L3']")))         //checking for Compose button
            {
                System.err.println("Failed to login");
                //fail("Unable to login");
            }
        }
    }
}


On Fri, Aug 30, 2013 at 12:08 PM, Nick Oppersdorff <nvo...@gmail.com> wrote:
Is each node connecting to the hub via a different port?

How are you calling your get() methods?  From within the @Test method? or the @Before method?  If from one particular way then try the other.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

sirus tula

unread,
Sep 9, 2013, 10:18:53 AM9/9/13
to seleniu...@googlegroups.com
Can anyone help me on this issue?

I think I'm having concurrency problem while running selenium grid through VM's although I am running the tests via TestNG framework.

I think the solution that I can think is to try first have the factory method on driver manager attached below synchronised then return a new Remote Webdriver Instance from each call, rather than maintaining a set of thread associated instances. And at the end of each test. quit the driver to free it up for other tests. 

However, since I have basic to intermediate knowledge of Java, I am having trouble to do the above solution.

If anyone could give a kickstart or some hints, that would be great.

Below is my driver file

Ken Pace

unread,
Sep 9, 2013, 5:09:38 PM9/9/13
to seleniu...@googlegroups.com
I think you're going to want to store the threads into a ThreadLocal instance.  TestNG will kick off as many threads as you want, but you'll need to store them somehow so you're not getting cross-thread pollution from a WebDriver instance...

Krishnan Mahadevan

unread,
Sep 9, 2013, 8:16:04 PM9/9/13
to seleniu...@googlegroups.com
I second what Ken stated. I didnt get to see the complete code [ Maybe you can put it in gist.github.com and share a link ]

When it comes to parallelism ThreadLocal is a reliable way to ensure that there are no mixups. 


For more options, visit https://groups.google.com/groups/opt_out.


--
Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

sirus tula

unread,
Sep 10, 2013, 9:26:47 AM9/10/13
to seleniu...@googlegroups.com
Thank you Ken and Krishnan for your answer.

I tried to play around with ThreadLocal instance but didn't know how to use it in my  existing driver script.

Krishnan, I looked at your blog and gave me nice idea about ThreadLocal but to do that, I need to change the whole configurations as my driver script is lot different than yours as posted above. 

However, I found the work-around solution although it's not perfect.  What I did to solve this issue, was to remove the static property on webdriver variable and instantiate the driver class on every test which would create new webdriver instance for every test and close it as the test is completed. 

Also on top of that, TestNG has a nice annotation called 'singleThreaded' which  needs to be implemented in the class as true which will run the test on separate threads as mentioned here http://beust.com/weblog2/archives/000407.html

Anyway, Thank you guys for your help.









For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages