Parallel execution across VMs using selenium webdriver and junits

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Parallel execution across VMs using selenium webdriver and junits

Payal
Hi Tarun,

Can you here help me with this issue .

I need to distribute my test suite(100TCs) to multiple machine for the execution on IE browser.I am looking for parallel/simultaneous execution.

I am using selenium webdriver and selenium 2.19 standalone jar and m trying to achieve this distribution on junit framework.

I have started listeners on each machines and they are properly connected to hub..

But I am not sure what piece of code would do the distribution on VMs(i am looking for distrbution at run time)

Please help if you have any idea on the same.I m kinda stuck on this for long.

Thanks in anticipation !!
Reply | Threaded
Open this post in threaded view
|

Re: Parallel execution across VMs using selenium webdriver and junits

softwaretestingforum
Administrator
Hi Payal,

Welcome to group

I assume you are using Webdriver.
Have you seen code snippet -


WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);


in page - http://code.google.com/p/selenium/wiki/Grid2
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: Parallel execution across VMs using selenium webdriver and junits

Payal
Hi Tarun,

Thank you for welcoming.

Yes I am using selenium webdrivers.This is how I defined capabilities :
public class Browser {
       
    private WebDriver driver;

    private DesiredCapabilities capability;

    private String strBrowser = "";
    private String strServerUrl = "";
    private String strVersion = "";
    private String strPlatform = "";

        public Browser(String browser,String version,String platform){

                try {
                        this.strBrowser = browser;
                        this.strVersion = version;
                        this.strPlatform = platform;
                       
                        this.setCapability();
                } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
        }
        public String getVersion() {
                return strVersion;
        }
       
        public void setVersion(String strVersion) {
                this.strVersion = strVersion;
        }

        public void setServerUrl(String s){
                strServerUrl = s;
        }
        private void setCapability() throws Exception {

            if (strBrowser.contains(Global.FIREFOX)){
                  capability = DesiredCapabilities.firefox();    

              FirefoxProfile profile = new FirefoxProfile();      
                  profile.setAssumeUntrustedCertificateIssuer(false);
                  profile.setPreference(CapabilityType.PROXY, "NONE");
                  //sets ff proxy to use no proxy
                  Proxy localhostProxy = new Proxy();
                  localhostProxy.setProxyType(Proxy.ProxyType.DIRECT);
                  profile.setProxyPreferences(localhostProxy);    
                  capability.setCapability(FirefoxDriver.PROFILE, profile);
            }
            if (strBrowser.contains(Global.INTERNET_EXPLORER)){
                    capability = DesiredCapabilities.internetExplorer();    
            capability.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
            }
        }
       
        public String getPlatform() {
                return strPlatform;
        }

        public void setPlatform(String strPlatform) {

                this.strPlatform = strPlatform;
           
                if (this.strPlatform.compareToIgnoreCase("WINDOWS") == 0){
                        capability.setCapability(CapabilityType.PLATFORM, Platform.WINDOWS);
            }
            if (this.strPlatform.compareToIgnoreCase("XP") == 0){
                        capability.setCapability(CapabilityType.PLATFORM, Platform.XP);
            }
            if (this.strPlatform.compareToIgnoreCase("VISTA") == 0){
                        capability.setCapability(CapabilityType.PLATFORM, Platform.VISTA);
            }
            if (this.strPlatform.compareToIgnoreCase("MAC") == 0){
                        capability.setCapability(CapabilityType.PLATFORM, Platform.MAC);
            }
        }

        public void setDriver() throws Exception {
    driver = new RemoteWebDriver(new URL(strServerUrl), capability);
        }

       
        public WebDriver getDriver(){
                return driver;
        }
        }

I have Junit framework to execute the test suite. I am stuck on how can I distribute this suite across VMs for IE browser.
Reply | Threaded
Open this post in threaded view
|

Re: Parallel execution across VMs using selenium webdriver and junits

softwaretestingforum
Administrator
With Junit you must be using @Before etc annotation to create driver.
I notice in your code -

public void setDriver() throws Exception {
    driver = new RemoteWebDriver(new URL(strServerUrl), capability);
}


But when is it invoked?
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: Parallel execution across VMs using selenium webdriver and junits

Payal
Yes there is another class invoking this which goes as follows :
public class RemoteController extends TestCase {

        public static String BASE_URL = "";
        public static String environment = "";
        public static String testPhase = "";
        public WebDriver driver;
        public Selenium selenium;
        public String strUsername = "";
        public static String strPassword = "";
        public String strFile = "";
        public static String delimiter = "";
        public static String strServerUrl = "";
        public static String scope = "";
        public String strBrowser = "";
        public static String strQuery = "";
        public String strVersion = "";
        public String strPlatform = "";
        public static String strBuildNo = "";

        @BeforeClass
        public void setUp() throws Exception {

                // init global element locator
                GlobalElementLocator.init();
                // boolean createdBrowser = false;
                // int timeout = 3000;
                FileInputStream fstream = new FileInputStream("Resource/system.properties");
                Properties props = new Properties();
                props.load(fstream);
                testPhase = props.getProperty("test_run_phase");
                if (strUsername == null || strUsername.isEmpty()) {
                        strUsername = props.getProperty("username");
                }
                strPassword = props.getProperty("password");
                strServerUrl = props.getProperty("serverUrl");

                // get browser
                if (strBrowser.isEmpty()) {
                        strBrowser = props.getProperty("browser");
                }

        //get browser version    
        if (strVersion.isEmpty()){
        strVersion = props.getProperty("version");
        }

        //get platform
        if (strPlatform.isEmpty()){
        strPlatform = props.getProperty("platform");
        }

                // get lastBuild
                strBuildNo = GlobalElementLocator.getValue("global:buildNo");

                // get environment & base url accordingly
                if (environment == null || environment.isEmpty()) {
                        environment = props.getProperty("environment");
                        System.out.println("environment: " + environment);
                }
               
                BASE_URL = props.getProperty(environment.toUpperCase() + "_url");

                // get scope.

        if (scope == null){
        scope = props.getProperty("scope");
        }
        if (scope.equalsIgnoreCase("full")){
        strQuery = Global.RALLY_QUERY_GET_ALL_WEB_CLIENT;
        }else if (scope.equalsIgnoreCase("smoke")){
        strQuery = Global.RALLY_QUERY_SMOKE_TEST;
        }else if (!scope.isEmpty()){
        //this query is for testing one test case in Jenkins
        strQuery = "(FormattedID%20=%20" + scope +")";
        }

                // end get scope

                Browser browser = new Browser(strBrowser, strVersion, strPlatform);
                browser.setServerUrl(strServerUrl);
                browser.setDriver();
                driver = browser.getDriver();
                System.out.println("base URL: " + BASE_URL);
                driver.get(BASE_URL);
                driver.manage().deleteAllCookies();
                selenium = new WebDriverBackedSelenium(driver, BASE_URL);
                selenium.useXpathLibrary("javascript-xpath");
                // browser behavior
                selenium.windowMaximize();
                selenium.windowFocus();
                // maximizeWindow();
                // Increase the wait time
                selenium.setTimeout("180000");

        try {
            boolean errorServer = selenium.isTextPresent("HTTP Status");
            if (errorServer == true) {
                System.out.println("this DriverUrl " + BASE_URL +" is not available");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

        public void setPlatform(String platform) {
                if (strPlatform.compareToIgnoreCase("WINDOWS") == 0) {
                        strPlatform = "WINDOWS_7";
                }

                if (strPlatform.isEmpty()) {
                        strPlatform = selenium.getEval("navigator.platform");
                }
        }

        @AfterClass
        public void tearDown() throws Exception {
                if (null != selenium) {
                        selenium.stop();
                        // currentBrowserCount --;
                }
        }


My test class somewhat looks like this :

import org.testng.annotations.Test;
public class TestInternetExplorer {
       
        RunTestScenario scenario = new RunTestScenario();
       
        @Test
        public void version7() {
                System.out.println("## running Internet Explorer 7 automation");
                scenario.runScenario(Global.INTERNET_EXPLORER,"7","XP","username");
        }
        @Test
        public void version8() {
                System.out.println("## running Internet Explorer 8 automation");
                scenario.runScenario(Global.INTERNET_EXPLORER,"8","VISTA","username");
        }
        @Test
        public void version9() {
                System.out.println("## running Internet Explorer 9 automation");
                scenario.runScenario(Global.INTERNET_EXPLORER, "9","WINDOWS","username");
        }

}

Using this test class I am trying to achieve distribution across 3 virtual machines.

RunTestScenario class here mentioned is as follows :

public class RunTestScenario {
        public void runScenario(String browser, String version, String platform, String username) {
               
                String scope = "";
                String  env = "";
               
                try {
                        DSAARun run = new DSAARun();
                        run.strBrowser = browser;
                        run.strVersion  = version;
                        run.strPlatform  = platform;
                        run.strUsername  = username;
                       
                        env = System.getProperty("environment");
                        scope = System.getProperty("scope");
                       
                        System.out.println("-Denvironment -->" + env);
                        System.out.println("-Dscope -->" + scope);
                        System.out.println("Username -->" + username);
                        DSAARun.environment = env;
                        DSAARun.scope = scope;
                       
                        run.setUp();
                        run.processTestCases();
                        run.tearDown();
                } catch (Exception e) {
                        e.printStackTrace();
                }
        }
}

Please let me know if any more input is required from my end.
Thank you !!
Reply | Threaded
Open this post in threaded view
|

Re: Parallel execution across VMs using selenium webdriver and junits

softwaretestingforum
Administrator
This was pretty big.
Since you are not able to run test in VM on IE at all, my suggestion to you is to use simple main method, instantiate RemoteWebDriver in it to run test on a VM. This would help in narrowing down the problem.
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: Parallel execution across VMs using selenium webdriver and junits

Payal
Pardon me if I've overdone.
it is not that I am not able to run tests on IE at all.It is just that I am not able run in multiple VMs parallely.

the test class which I have shared before has 3 methods and hence I expect that class to launch one thread in 3 VMs and start the parallel execution.

I am really stuck on this part, so your help is much appreciated.
Reply | Threaded
Open this post in threaded view
|

Re: Parallel execution across VMs using selenium webdriver and junits

softwaretestingforum
Administrator
I am no JUnit master but I would try.
I suppose by Three methods you are referring to -

       @Test
        public void version7() {
                System.out.println("## running Internet Explorer 7 automation");
                scenario.runScenario(Global.INTERNET_EXPLORER,"7","XP","username");
        }
        @Test
        public void version8() {
                System.out.println("## running Internet Explorer 8 automation");
                scenario.runScenario(Global.INTERNET_EXPLORER,"8","VISTA","username");
        }
        @Test
        public void version9() {
                System.out.println("## running Internet Explorer 9 automation");
                scenario.runScenario(Global.INTERNET_EXPLORER, "9","WINDOWS","username");
        }


If you use just one method, do your tests work? Can you try?
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: Parallel execution across VMs using selenium webdriver and junits

Payal
Thank you for your help !!

Yes I have tried with one method also..In this case, it starts the execution on only one machine.
Reply | Threaded
Open this post in threaded view
|

Re: Parallel execution across VMs using selenium webdriver and junits

softwaretestingforum
Administrator
Now try with two methods. Do you encounter any exception?
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: Parallel execution across VMs using selenium webdriver and junits

Payal
Hi Tarun
When I execute 2 methods , I get following exception :

Running Test Cases Count: 0
        at org.testng.TestRunner.run(TestRunner.java:600)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:317)
        at org.testng.SuiteRunner.access$000(SuiteRunner.java:34)
        at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:351)
        at org.testng.internal.thread.ThreadUtil$CountDownLatchedRunnable.run(ThreadUtil.java:147)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
Running Failed: 0
Running Passed: 0
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:662)
org.openqa.selenium.WebDriverException: Session [1335980027566] not available - [c04a5f08-3f29-40c1-9ba2-3a22a2984a98 (i
nt. key, remote not contacted yet.), ext. key 1335979806778, ext. key 1335980027567]
Command duration or timeout: 564 milliseconds
Build info: version: '2.19.0', revision: '15848', time: '2012-02-08 16:25:03'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_31'
Driver info: driver.version: RemoteWebDriver
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:170)
        at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:123)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:439)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:443)
        at org.openqa.selenium.remote.RemoteWebDriver.quit(RemoteWebDriver.java:318)
        at org.openqa.selenium.WebDriverCommandProcessor.stop(WebDriverCommandProcessor.java:110)
        at com.thoughtworks.selenium.DefaultSelenium.stop(DefaultSelenium.java:139)
        at com.########.studios.dsaa.qa.RemoteController.tearDown(RemoteController.java:162)
        at com.########.studios.dsaa.qa.scenarios.RunTestScenario.runScenario(RunTestScenario.java:35)
        at com.########.studios.dsaa.qa.scenarios.TestInternetExplorer.version7(TestInternetExplorer.java:41)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:74)
        at org.testng.internal.Invoker.invokeMethod(Invoker.java:673)
        at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:846)
        at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1170)
        at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
        at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
        at org.testng.TestRunner.runWorkers(TestRunner.java:1147)
        at org.testng.TestRunner.privateRun(TestRunner.java:749)
        at org.testng.TestRunner.run(TestRunner.java:600)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:317)
        at org.testng.SuiteRunner.access$000(SuiteRunner.java:34)
        at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:351)
        at org.testng.internal.thread.ThreadUtil$CountDownLatchedRunnable.run(ThreadUtil.java:147)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:662)
Caused by: org.openqa.grid.common.exception.GridException: Session [1335980027566] not available - [c04a5f08-3f29-40c1-9
ba2-3a22a2984a98 (int. key, remote not contacted yet.), ext. key 1335979806778, ext. key 1335980027567]
        at org.openqa.grid.web.servlet.handler.RequestHandler.process(RequestHandler.java:163)
        at org.openqa.grid.web.servlet.DriverServlet.process(DriverServlet.java:81)
        at org.openqa.grid.web.servlet.DriverServlet.doDelete(DriverServlet.java:73)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
        at org.openqa.jetty.jetty.servlet.ServletHolder.handle(ServletHolder.java:428)
        at org.openqa.jetty.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:473)
        at org.openqa.jetty.jetty.servlet.ServletHandler.handle(ServletHandler.java:568)
        at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1530)
        at org.openqa.jetty.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:633)
## running Internet Explorer 8 automation
-Denvironment -->QA
-Dscope -->FULL
Username -->rallyAutomation@dsaa.com
Root element :dsaa
global element locator: buildNo --> 18.42
        at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1482)
        at org.openqa.jetty.http.HttpServer.service(HttpServer.java:909)
        at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:820)
        at org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:986)
        at org.openqa.jetty.http.HttpConnection.handle(HttpConnection.java:837)
        at org.openqa.jetty.http.SocketListener.handleConnection(SocketListener.java:243)
        at org.openqa.jetty.util.ThreadedServer.handle(ThreadedServer.java:357)
        at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
May 15, 2012 10:46:48 AM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: I/O exception (java.net.SocketException) caught when processing request: Software caused connection abort: recv fa
iled
May 15, 2012 10:46:48 AM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: Retrying request
base URL: <a href="http://qa.dsaa.########.go.com/">http://qa.dsaa.########.go.com/
test123>>>>>>>>>>
strQuery: https://rally1.rallydev.com/slm/webservice/1.29/testcase?query=((Project.Name%20=%20"Web%20Client")%20and%20(A
utomationIsAutomated%20=%20true))
query already already started...
directory exists
output filename: 1336022220554_iexplore__WINDOWS_7_PASS.html
directory exists
output filename: 1336022220554_iexplore__WINDOWS_7_FAIL.html
global element locator: username --> id=username
global element locator: password --> id=password
global element locator: loginButton --> id=loginSubmitButton
Logging in
username: rallyAutomation@dsaa.com
password: test123
com.thoughtworks.selenium.SeleniumException: Element id=username not found
        at org.openqa.selenium.internal.seleniumemulation.ElementFinder.findElement(ElementFinder.java:103)
        at org.openqa.selenium.internal.seleniumemulation.Type.handleSeleneseCommand(Type.java:56)
        at org.openqa.selenium.internal.seleniumemulation.Type.handleSeleneseCommand(Type.java:28)
        at org.openqa.selenium.internal.seleniumemulation.SeleneseCommand.apply(SeleneseCommand.java:36)
        at org.openqa.selenium.internal.seleniumemulation.Timer.run(Timer.java:39)
        at org.openqa.selenium.WebDriverCommandProcessor.execute(WebDriverCommandProcessor.java:145)
        at org.openqa.selenium.WebDriverCommandProcessor.doCommand(WebDriverCommandProcessor.java:75)
        at com.thoughtworks.selenium.DefaultSelenium.type(DefaultSelenium.java:317)
        at com.########.studios.dsaa.qa.util.Login.logIn(Login.java:69)
        at com.########.studios.dsaa.qa.scenarios.DSAARun.processTestCases(DSAARun.java:139)
        at com.########.studios.dsaa.qa.scenarios.RunTestScenario.runScenario(RunTestScenario.java:34)
        at com.########.studios.dsaa.qa.scenarios.TestInternetExplorer.version8(TestInternetExplorer.java:16)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:74)
        at org.testng.internal.Invoker.invokeMethod(Invoker.java:673)
        at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:846)
        at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1170)
        at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
        at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
        at org.testng.TestRunner.runWorkers(TestRunner.java:1147)
        at org.testng.TestRunner.privateRun(TestRunner.java:749)
        at org.testng.TestRunner.run(TestRunner.java:600)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:317)
        at org.testng.SuiteRunner.access$000(SuiteRunner.java:34)
        at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:351)
        at org.testng.internal.thread.ThreadUtil$CountDownLatchedRunnable.run(ThreadUtil.java:147)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:662)
Caused by: org.openqa.selenium.WebDriverException: JavaScript error (WARNING: The server did not provide any stacktrace
information)
Command duration or timeout: 63 milliseconds
Build info: version: '2.15.0', revision: '15105', time: '2011-12-08 09:56:25'
System info: os.name: 'Windows XP', os.arch: 'amd64', os.version: '5.2', java.version: '1.6.0_25'
Driver info: driver.version: EventFiringWebDriver
Command duration or timeout: 3.08 seconds
Build info: version: '2.19.0', revision: '15848', time: '2012-02-08 16:25:03'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_31'
Driver info: driver.version: RemoteWebDriver
Reply | Threaded
Open this post in threaded view
|

Re: Parallel execution across VMs using selenium webdriver and junits

softwaretestingforum
Administrator
A little confused with it. You mentioned earlier that you were using Junit but exception looks like that of TestNG -

 at org.testng.TestRunner.run(TestRunner.java:600)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:317)
        at org.testng.SuiteRunner.access$000(SuiteRunner.java:34)
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: Parallel execution across VMs using selenium webdriver and junits

GulshanSaini
In reply to this post by Payal
As you are saying, it looks like you are using Junit but, imported wrong libraries into project.

Thanks
Gulshan