Running Selenium tests in parallel

8,017 views
Skip to first unread message

Bhoomika Annaiah

unread,
Mar 14, 2012, 4:33:50 AM3/14/12
to webdriver
Hi,

I am very new to Selenium and am trying to use it for cross browser
testing. I am facing issues when I try to run same test in parallel on
multiple browsers.
I am using testng with webdriver(2.20 version).

FF 4.0 IE9

I have an xml file like this :

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Same TestCases on Different Browsers and ports"
verbose="3" parallel="tests" thread-count="2">
<test name="Run on Firefox">
<parameter name="browser" value="firefox"/>
<parameter name="username" value="xxxx"/>
<parameter name="password" value="xxxx"/>
<parameter name="port" value="5555"/>
<parameter name="path" value="path to ff profile"/>
<classes>
<class name="com.WebUploadsFFIE"/>
</classes>
</test>
<test name="Run on Internet Explore port 5556">
<parameter name="browser" value="iexplore"/>
<parameter name="username" value="xxx"/>
<parameter name="password" value="xxx"/>
<parameter name="port" value="5556"/>
<parameter name="path" value=""/>
<classes>
<class name="com.WebUploadsFFIE"/>
</classes>
</test>
</suite>

I have a baseclass whihc starts the selenium server.

I have a before test annotation where i am setting capabilities for FF/
IE.

If i run a single test either on IE or FF it passes. But when I am
trying to run them parallely i am facing issues.


Base class for starting Selenium Server :

package com;

import org.openqa.selenium.server.RemoteControlConfiguration;
import org.openqa.selenium.server.SeleniumServer;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
//import org.testng.annotations.Parameters;

import java.net.BindException;
import java.net.ServerSocket;

public class StartSeleniumServer {

public static SeleniumServer server;

//@Parameters({"server_port"})
@BeforeSuite(alwaysRun = true)
public static void startSeleniumServer() throws Exception {

try {
ServerSocket serverSocket = new
ServerSocket(RemoteControlConfiguration.DEFAULT_PORT);
serverSocket.close();
//Server not up, start it
try {
RemoteControlConfiguration rcc = new
RemoteControlConfiguration();
rcc.setPort(RemoteControlConfiguration.DEFAULT_PORT);
server = new SeleniumServer(false, rcc);

} catch (Exception e) {
System.err.println("Could not create Selenium
Server because of: "
+ e.getMessage());
e.printStackTrace();
}
try {
server.start();
System.out.println("Server started");
} catch (Exception e) {
System.err.println("Could not start Selenium
Server because of: "
+ e.getMessage());
e.printStackTrace();
}
} catch (BindException e) {
System.out.println("Selenium server already up, will
reuse...");
}


}

@AfterSuite(alwaysRun = true)
public static void stopSeleniumServer(){
if (server != null)
{
try
{
server.stop();
server = null;
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
}


My Actual test class:

package com;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import java.net.URL;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
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.annotations.*;
import static org.junit.Assert.*;

public class WebUploadsFFIE extends StartSeleniumServer {

public String username;
public String password;
public static WebDriver driver;
private static Properties properties;

@Parameters({"browser","username","password","port","path"})
@BeforeTest
public void setup(String browser, String username, String password,
String port, String path) throws IOException {


properties = new Properties();
properties.load(new FileInputStream("verizon_test.properties"));
assertNotNull("Invalid Portal URL",
properties.getProperty("Portal.url"));

String PROXY = "cache2.lexmark.com:8080";

org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setHttpProxy(PROXY)
.setFtpProxy(PROXY)
.setSslProxy(PROXY);

DesiredCapabilities capability=null;

this.username = username;
this.password = password;

if(browser.equalsIgnoreCase("iexplore")){
System.out.println("iexplore");
capability=DesiredCapabilities.internetExplorer();
capability.setBrowserName("iexplore");
capability.setPlatform(org.openqa.selenium.Platform.WINDOWS);

capability.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
true);
capability.setCapability(CapabilityType.PROXY, proxy);
capability.setCapability("port", port);
}

if(browser.equalsIgnoreCase("firefox")){


FirefoxProfile profile = new FirefoxProfile(new File(path));
profile.setEnableNativeEvents(false);

System.out.println("firefox");
capability= DesiredCapabilities.firefox();
capability.setBrowserName("firefox");
capability.setPlatform(org.openqa.selenium.Platform.ANY);
capability.setCapability(CapabilityType.PROXY, proxy);
capability.setCapability(FirefoxDriver.PROFILE, profile);
capability.setCapability("port", port);

}

driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/
hub"), capability);
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

driver.navigate().to(properties.getProperty("Portal.url"));
}

@Test
public void test_txt_file() throws Exception {
driver.findElement(By.id("IDToken1")).sendKeys(username);
driver.findElement(By.id("IDToken2")).sendKeys(password);

driver.findElement(By.name("signin")).click();

try {
assertTrue(Wait_For_String("My Print Queue"));
Thread.sleep(200);
}catch (Throwable t) {
System.out.println("Error in file uplaod");
}

WebElement inputElement = driver.findElement(By.className("x-btn-
inner"));
((JavascriptExecutor)driver).executeScript("arguments[0].checked =
true;", inputElement);
inputElement.click();

try {
assertTrue(Wait_For_String("Done"));
Thread.sleep(200);
}catch (Throwable t) {
System.out.println("Error in file uplaod");
}

inputElement = driver.findElement(By.name("file"));
((JavascriptExecutor)driver).executeScript("arguments[0].checked =
true;", inputElement);

driver.findElement(By.name("file")).sendKeys("C:\\Testing_Originals\
\ODS-testfile1.ods");
driver.findElement(By.name("file")).sendKeys("C:\\Testing_Originals\
\html-file1.html");
driver.findElement(By.name("file")).sendKeys("C:\\Testing_Originals\
\ODP-test_file1.odp");
driver.findElement(By.name("file")).sendKeys("C:\\Testing_Originals\
\print-stream-pg-count-test-1.JPG");



assertTrue(Wait_For_String("Done"));
driver.findElement(By.xpath("//span[.='Done']")).click();
//driver.switchTo().defaultContent();
assertTrue(Wait_For_String("My Print Queue"));
Thread.sleep(200);

inputElement = driver.findElement(By.className("sign-in-text-
name"));
((JavascriptExecutor)driver).executeScript("arguments[0].checked =
true;", inputElement);
inputElement.click();


inputElement = driver.findElement(By.xpath("//span[.='Sign Out']"));
((JavascriptExecutor)driver).executeScript("arguments[0].checked =
true;", inputElement);
inputElement.click();

}

private static boolean Wait_For_String(String Message) {

int timeout = 0;
do{
boolean result = driver.getPageSource().contains(Message);
if((result == false) && (timeout > 300)) { return result; }
timeout++;
} while(timeout <= 300 );
return true;

}

@AfterTest
public void tearDown(){
System.out.println("Closing the driver==========\n===============
\n==========\n================\n==============");
try {
driver.quit();
}catch(Exception e) {
System.out.println("Driver quit failed with error" + e);
}
}
}



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

On execution the test starts on IE & ff but fails either with
"Unreachable browser" exception or
"Error 500 java.util.concurrent.RejectedExecution" etc.

I am not sure where I am going wrong. Any help would be apprciated.

Thanks
Bhoomika

Krishnan Mahadevan

unread,
Mar 14, 2012, 8:06:14 AM3/14/12
to webd...@googlegroups.com
Bhoomika,

Curious. Does this work when you just execute one of the tests ? (against IE or firefox) ?

To be honest, first time am seeing this approach for starting up a local Grid, so just wanted to rule out of starting the local hub is NOT being the root cause of the problem.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"



Bhoomika

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.


Bhoomika Annaiah

unread,
Mar 14, 2012, 10:16:06 AM3/14/12
to webdriver
HI Krishnan,

If i execute on just one browser either IE or FF by modifying the xml,
the test passes.
Would appreciate if you could tell me how to proceed on this.

Thanks
Bhoomika

On Mar 14, 8:06 am, Krishnan Mahadevan
> ...
>
> read more »

Mike Riley

unread,
Mar 14, 2012, 1:43:35 PM3/14/12
to webdriver
Bhoomika,

I have not done parallel tests via the TestNG XML file like this, but
one thing struck my in your code to start up the server. You have
commented out the line that would have passed the server port in as a
parameter and are instead using the default port.

If I understand how this will end up working you are going to end up
starting two servers on the same port, so whichever server starts last
will lose.

I see no advantage to even starting a server the way you are doing it
here. This implies that you are starting a server on the same system
where your code is running. Frankly, that is just adding a layer of
abstraction between you and the browser that you won't need. The only
reason to use a server (IMHO) is when you are running tests on another
system or systems. In that case it is almost always better to have a
grid hub that you use as a traffic cop for the jobs to direct them to
the first available server that can meet your job requirements.

If you were to simply run this locally, as it seems you are doing,
then I would just run it as a new WebDriver instead of RemoteWebDriver
instance. That would totally eliminate the need to start any server
and worry about ports (which using a Hub server would have done, BTW).

Mike

On Mar 14, 7:16 am, Bhoomika Annaiah <sbhoomika.anna...@gmail.com>
wrote:
> > >                WebElement inputElement =...
>
> read more »

Bhoomika Annaiah

unread,
Mar 14, 2012, 2:16:17 PM3/14/12
to webdriver
Hi Mike,

Thanks for your response.

A couple of questions so that I can understand this better:
1) If I am starting the server at default port why would it happen
twice. Since this server is started before running the suite, I am not
clear why will it be invoked twice.
2) I am eventually going to use this in a VM environment to have
multiple instances of IE which is not possible on a single node, but
since I am new to selenium I wanted to get things right before i
expand it to multiple VM's etc.
3) I have not explored much on the invoking server remotely. I would
appreciate if you could help me with that.

Thanks
Bhoomika
> ...
>
> read more »

Bhoomika Annaiah

unread,
Mar 14, 2012, 3:10:39 PM3/14/12
to webd...@googlegroups.com
HI,

I also tried running two instances of FF using WebDriver where the FF starts on two different ports using two different profiles in which case one test is consistently failing withe error: "Error communicating with the remote browser. It may have died."

Any suggestions on this would be appreciated.

Thanks
BHoomika

Mike Riley

unread,
Mar 15, 2012, 12:39:49 PM3/15/12
to webdriver
You should look at using a Grid 2 server if you are using multiple
servers. The servers will register with the Grid 2 server and your
test only needs to initiate a session with the Grid server. It will
then send it to the next available server and suspend you until one is
available. You can have multiple servers running on a single system,
if you wish, with each one registered with the Grid 2 server. Each
node server (when on the same system) would need to use a different
port, but the Grid 2 hub will know which port each is using and handle
switching to the appropriate one when it assigns a session to that
server.

In my code I display what the parameters are that I am using to open
the session with. I think if you put some diagnostic info like that
in your task output you will see better what is going on.

Mike

On Mar 14, 12:10 pm, Bhoomika Annaiah <sbhoomika.anna...@gmail.com>
wrote:

Bhoomika Annaiah

unread,
Mar 15, 2012, 12:54:48 PM3/15/12
to webd...@googlegroups.com
Appreciate your response Mike.

Could you please point me some reference for setting up multiple grid servers and using it, the way u r describing...

Thanks
Bhoomika

Robert

unread,
Mar 15, 2012, 1:52:30 PM3/15/12
to webd...@googlegroups.com

Bhoomika Annaiah

unread,
Mar 15, 2012, 10:35:43 PM3/15/12
to webd...@googlegroups.com
Hey Mike,

Would appreciate if u could give some steps to go about doing the setup.


Thanks
Bhoomika


On Thursday, March 15, 2012 12:39:49 PM UTC-4, Mike Riley wrote:

Krishnan Mahadevan

unread,
Mar 15, 2012, 10:41:37 PM3/15/12
to webd...@googlegroups.com
Refer my post for understanding how to setup the Grid.

http://rationaleemotions.wordpress.com/2012/01/23/setting-up-grid2-and-working-with-it/

Twiki page for Grid :
http://code.google.com/p/selenium/wiki/Grid2
> --
> You received this message because you are subscribed to the Google Groups "webdriver" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/lOMU03Z-gt4J.

> To post to this group, send email to webd...@googlegroups.com.
> To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.
>

--
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/

Bhoomika Annaiah

unread,
Mar 16, 2012, 12:34:59 PM3/16/12
to webd...@googlegroups.com
Hi Krishnan,

Thanks for your message.
I have tried setting up the grid the way you have explain in the post, but while running the tests, my nodes are getting killed in the middle. I get a erro message : FAILED CONFIGURATION: @AfterClass tearDown
org.openqa.selenium.WebDriverException: Session [1331914063622] not available - []
Command duration or timeout: 20 milliseconds.

Any pointers on this?

thanks
Bhoomika
Message has been deleted

Bhoomika Annaiah

unread,
Mar 19, 2012, 3:59:55 AM3/19/12
to webd...@googlegroups.com
Hi Krishnan,

So i have na xml file and I am running tests on remote m/s as given in ur blog.
So now when i say try to run two threads , the parameters whihc I am sending for two tests are gettign passed into one test causing failures

my xml file


<?xml version="1.0" encoding="UTF-8"?>
<suite name="Same TestCases on Different Browser" verbose="3"  parallel="tests" thread-count="2"> 
    <test name="test3">
    <parameter name="IP"  value="xxx"/>
    <parameter name="username"  value="xx...@gmail.com"/>

    <parameter name="password"  value="xxx"/>
        <classes>
            <class name="cptests.Gmail"/>
        </classes>
    </test>
    <test name="Test4: " preserve-order="true">
    <parameter name="IP"  value=1xxx"/>

    <parameter name="username"  value="xxx"/>
    <parameter name="password"  value="xxx"/>
        <classes>
            <class name="cptests.Gmail"/>
        </classes>
    </test>
</suite>

Now I call this from my script whihc is given below:

package cptests;


import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import java.net.URL;
import org.openqa.selenium.*;
import org.openqa.selenium.remote.
DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Assert;

import org.testng.annotations.*;

import static org.junit.Assert.*;

public class Gmail{


    public String username;
    public String password;
    public static WebDriver driver;   
    private static Properties properties;
     
    @Parameters({"IP","username","password"})
    @BeforeClass
    public void setup(String ip, String username, String password) throws IOException {
       
        properties = new Properties();
        properties.load(new FileInputStream("email_test.properties"));
        assertNotNull("Invalid Portal URL", properties.getProperty("Gmail.url"));

               
        DesiredCapabilities capability=null;
       
        this.username = username;
        this.password = password;

        System.out.println("firefox");
        capability= DesiredCapabilities.firefox();
        capability.setBrowserName("firefox");
        capability.setPlatform(org.openqa.selenium.Platform.ANY);   

          //driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
        driver = new RemoteWebDriver(new URL("http://"+ ip +":4444/wd/hub"), capability);
        driver.manage().timeouts().implicitlyWait(300, TimeUnit.SECONDS);
        driver.manage().deleteAllCookies();
        driver.navigate().to(properties.getProperty("Gmail.url"));
    }
   
    @Test   
    public void test_file_upload_gmail() throws Exception {
   
        //starting the autoit script for file uplaod from email
           
        try {
            String[] commands = new String[]{};
            commands = new String[]{"C:\\Automation\\file_upload.exe"}; //location of the autoit executable
            Runtime.getRuntime().exec(commands);
        } catch (IOException e) {
            e.printStackTrace();
        }
       
    //    try {
            WebElement element;
            //Enter email id
            driver.findElement(By.name("Email")).sendKeys(username);
            // Enter password
            driver.findElement(By.name("Passwd")).sendKeys(password);
            // Click on sign in button
            driver.findElement(By.name("signIn")).click();
            driver.switchTo().frame("canvas_frame");
                                
            Assert.assertTrue(Wait_For_String("COMPOSE"));
           
            driver.get("https://mail.google.com/mail/#compose");    
           
            driver.switchTo().defaultContent();            
            driver.switchTo().frame("canvas_frame");

            System.out.println("\n==========\nVerifying the compose page load \n==========");
            Assert.assertTrue(Wait_For_String("To"));
   
            //Enter the destination email address
            System.out.println("\n==========\nEnetrign the receiver's email address \n==========");
            element = driver.findElement(By.name("to"));
            element.sendKeys(properties.getProperty("GmailTests.destination.email"));            
   
            System.out.println("\n==========\nEntering email Subject \n==========");
            //Entering the subject in "Subject" field
            element = driver.findElement(By.name("subject"));
            element.sendKeys(properties.getProperty("GmailTests.subject"));
           
            System.out.println("\n==========\nEntering email body \n==========");
            element = driver.findElement(By.name("body"));
            element.sendKeys(properties.getProperty("GmailTests.body"));
     
            System.out.println("\n==========\nAdding Attachments \n==========");
            driver.findElement(By.name("FLASH_UPLOADER_1")).click();
                 
           
            driver.switchTo().defaultContent();
            driver.switchTo().frame("canvas_frame");
           
            System.out.println("\n==========\nChecking for cancel string \n==========");
            long end = System.currentTimeMillis() + 60000;
            while (System.currentTimeMillis() < end) {
                boolean resultsDiv = driver.getPageSource().contains("Cancel");
                // If results have been returned, the results are displayed in a drop down.
                if (resultsDiv) {
                  break;
                }
            }   
           
            System.out.println("\n==========\nVerifying that File attaching is complete\n==========");
            end = System.currentTimeMillis() + 60000;
            while (System.currentTimeMillis() < end) {
                boolean resultsDiv = driver.getPageSource().contains("Cancel");
                // If results have been returned, the results are displayed in a drop down.
                if (!(resultsDiv)) {
                  break;
                }
            }   
           
               
               System.out.println("\n==========\nSending the Email\n==========");
            //Sending the email by clicking on Send button
               element = driver.findElement(By.xpath("//div[@class][.='Send']/b"));
            ((JavascriptExecutor)driver).executeScript("arguments[0].checked = true;", element);
            element.click();
       
            driver.switchTo().defaultContent();
            driver.switchTo().frame("canvas_frame");
           
              System.out.println("\n==========\nVerifying if the email has been sent\n==========");
            Assert.assertTrue(Wait_For_String("Your message has been sent"));
           
            driver.findElement(By.id("gbgs4dn")).click();
            driver.findElement(By.id("gb_71")).click();
           

            driver.navigate().to(properties.getProperty("Gmail.logout.url"));
           
    /*    } catch(Exception e){
            System.out.println("\n==========\n Error found" + e);
        }*/

       
    }
   
    private static boolean Wait_For_String(String Message) {
       
        long end = System.currentTimeMillis() + 60000;
        while (System.currentTimeMillis() < end) {
            boolean resultsDiv = driver.getPageSource().contains(Message);
            // If results have been returned, the results are displayed in a drop down.
            if (resultsDiv) {
              return true;
            }
        }
        return false;   
    }
   
    @AfterClass
    public void tearDown(){
        System.out.println("\n==========\n==========\nClosing the driver\n==========\n==========");
            driver.quit();
    }
}

Both the data is gettign populated in one login username box ....

Where am I goign wrong?

Thanks
bhoomika


On Friday, March 16, 2012 12:34:59 PM UTC-4, Bhoomika Annaiah wrote:
Hi Krishnan,

Thanks for your message.
I have tried setting up the grid the way you have explain in the post, but while running the tests, my nodes are getting killed in the middle. I get a erro message : FAILED CONFIGURATION: @AfterClass tearDown
org.openqa.selenium.WebDriverException: Session [1331914063622] not available - []
Command duration or timeout: 20 milliseconds.

Any pointers on this?

thanks
Bhoomika


> To unsubscribe from this group, send email to webdriver+unsubscribe@googlegroups.com.

> For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.
>

--
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/

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+unsubscribe@googlegroups.com.

Bhoomika

unread,
Mar 19, 2012, 6:07:34 AM3/19/12
to webd...@googlegroups.com
Hi,

My requirement is to run the same test on multiple vm's but with different input data.. Any help will be appreciated..

Regards
Bhoomika
Sent from my iPhone
To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/7cQXqvhz16oJ.

To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.

Karthik

unread,
Mar 19, 2012, 7:38:07 AM3/19/12
to webd...@googlegroups.com
Hi, 

Have you tried using Jenkins / Hudson - Master slave setup to get your tests running in different machines? Using this would help save lots of precious time in trying to manage the grid. You could immediately start concentrating on your tests rather on managing the test infrastructure. 


Regards, Karthik
--------

Andy

unread,
Mar 19, 2012, 1:40:41 PM3/19/12
to webdriver
Bhoomika,

You are running your "tests" in parrallel.
<suite name="Same TestCases on Different Browser" verbose="3"
parallel="tests" thread-count="2">

This tells testng each @Test or in your case each parameterized test
is to be run as a seperate thread. In Java static variables are shared
by all threads running under the same process.

So you have WebDriver declared at the top as static.

> public static WebDriver driver;

This means that all of your test will share the same WebDriver. That
is why all the commands are being sent to one browser.

You have two options to fix this.

1. Run your suite as parallel="classes", this means that each .java
file will run in parrallel. So it will run like this

Class1.java
BeforeClass1
Test1
AfterClass1

Class2.java
BeforeClass2 (in parrallel w/class1)
Test2
AfterClass2

2. Leave it as parallel="tests", remove all statics that are not ment
to be shared by threads, move everthing inside the @Test, that means
every class level variable, everything inside the beforeclass, and
afterclass. Becuase the execution order will be like this

Beforeclass
Test1 (in parrallel)
Test2 (in parrallel)
Test3 (in parrallel)
Test4 (in parrallel)
Afterclass

On Mar 19, 12:59 am, Bhoomika Annaiah <sbhoomika.anna...@gmail.com>
wrote:
> Hi Krishnan,
>
> So i have na xml file and I am running tests on remote m/s as given in ur
> blog.
> So now when i say try to run two threads , the parameters whihc I am
> sending for two tests are gettign passed into one test causing failures
>
> my xml file
>
> <?xml version="1.0" encoding="UTF-8"?>
> <suite name="Same TestCases on Different Browser" verbose="3"
> parallel="tests" thread-count="2">
>     <test name="test3">
>     <parameter name="IP"  value="xxx"/>
>     <parameter name="username"  value="x...@gmail.com"/>

Bhoomika Annaiah

unread,
Mar 19, 2012, 2:02:33 PM3/19/12
to webd...@googlegroups.com
Hi Andy,

Thanks for explaining me where I was going wrong. You saved my day :).
Appreciate your help.

Regards
Bhoomika


--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.

Bhoomika Annaiah

unread,
Mar 19, 2012, 2:47:46 PM3/19/12
to webd...@googlegroups.com
Hey Andy,

I am hoping you can help me out with one more thing.

Suppose I want to run the same test on multiple browsers with different data what should I do.

When I try to do this with say one FF & one IE browser, My IE browser always hangs. I assume this might be because they r competing for resources.

Basically I want to modify the same test as given in the code above but also run it in parallel on each VM with different data set  and on different browsers.

Would really appreciate if you could help me with this :).

Thanks
Bhoomika

SANTHOSH BABY

unread,
Mar 19, 2012, 11:11:39 PM3/19/12
to webd...@googlegroups.com
yup this is how one should run ,  Driver instance(threads) should be created always separate 



Santhosh Software Automation  Engineer
 



Think GREEN. Please consider the environment before printing this email

"When The Winds of Change Blow..... Some people Build Walls & Others Windmills.... Attitude Matters...."



--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
image001.gif

Bhoomika Annaiah

unread,
Mar 20, 2012, 12:10:26 PM3/20/12
to webd...@googlegroups.com
Hi All,

So I have my code working where I can access multiple browser on a single system and have test's runnign in parallel. Webdriver does not seem to be thread safe if i have understood it correctly, so we have to ensure that a thread is created for each browser instance we are trying to launch. I hope this helps people who are trying to figure out a way to do this without using ant or other build tools. I also have an testng.xml file to run this test in parallel on multiple VM's

==============================================================================
package cptests;


import java.util.Properties;
import java.util.concurrent.TimeUnit;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.*;
import org.testng.Assert;
import org.testng.annotations.*;


public class TestFileUpload {

    private static Properties properties;

    private final ThreadLocal<RemoteWebDriver> driver = new
            ThreadLocal<RemoteWebDriver>();
   
    @DataProvider(name = "dp", parallel = true)
    public Object[][] getdata() {
    return new Object[][] { { "xxxx", "xxx" }, { "x...@gmail.com", "xxx" }};

    }

    @BeforeMethod(alwaysRun = true)
    @Parameters({"IP"})
    public void doSetup(String ip) throws MalformedURLException {
       
            DesiredCapabilities dc = new DesiredCapabilities();
            dc.setBrowserName(DesiredCapabilities.firefox().getBrowserName());
            driver.set(new RemoteWebDriver(new URL("http://" + ip + ":4444/wd/hub"),dc));
            driver.get().manage().deleteAllCookies();
            driver.get().manage().timeouts().implicitlyWait(300, TimeUnit.SECONDS);
            driver.get().get("xxxxxx");
    }
   
    @Test(dataProvider = "dp")
    public void test_file_upload(String username, String password) throws Exception {
       
       
        Thread.sleep(300);
        System.out.println("\n==========\nLogging in to the web portal with usersname :" + username + " & password :" + password + "\n==========\n");
       
        driver.get().findElementById("IDToken1").sendKeys(username);
        driver.get().findElementById("IDToken2").sendKeys(password);
       
            //driver.findElement(By.name("Login.Submit")).click();
        driver.get().findElementByName("signin").click();
        driver.get().switchTo().defaultContent();
       
        System.out.println("\n==========\nVerify if portal page has loaded \n==========\n");
        Assert.assertTrue(Wait_For_String("My Print Queue", driver));
       
        System.out.println("\n==========\nUplaoding files to the Web Portal of the user \n==========\n");
        driver.get().findElementByXPath("//button[starts-with(@id, 'ext-gen')]").click();
               
        Assert.assertTrue(Wait_For_String("Done", driver));
       
        driver.get().findElementByName("file").sendKeys("C:\\Testing_Originals\\ODS-testfile1.ods");
        driver.get().findElementByName("file").sendKeys("C:\\Testing_Originals\\test1.odt");
        driver.get().findElementByName("file").sendKeys("C:\\Testing_Originals\\test2.ppt");
        driver.get().findElementByName("file").sendKeys("C:\\Testing_Originals\\html-file1.html");
   
   
        System.out.println("\n==========\nVerify if file uplaod has completed \n==========\n");
        Assert.assertTrue(Wait_For_String("Done", driver));
        driver.get().findElementByXPath("//span[.='Done']").click();
       
        System.out.println("\n==========\nVerify that user is back to his home page having his pritn queue \n==========\n");
        driver.get().switchTo().defaultContent();
        Assert.assertTrue(Wait_For_String("My Print Queue", driver));   
   
        System.out.println("\n==========\nSigning out of the web Portal \n==========\n");
        driver.get().findElementByClassName("sign-in-text-name").click();
        driver.get().findElementByXPath("//span[.='Sign Out']").click();
   
        driver.get().navigate().to(properties.getProperty("Portal.url"));
   
    }

    private boolean Wait_For_String(String Message, ThreadLocal<RemoteWebDriver> driver) {

       
        long end = System.currentTimeMillis() + 60000;
        while (System.currentTimeMillis() < end) {
            boolean resultsDiv = driver.get().getPageSource().contains(Message);

            // If results have been returned, the results are displayed in a drop down.
            if (resultsDiv) {
              return true;
            }
        }
        return false;   
    }
   
    @AfterMethod(alwaysRun = true)
    public void cleanUp() {
    driver.get().quit();
    }
   
}
   
  ================================================================================================================================= 
   
<?xml version="1.0" encoding="UTF-8"?>
<suite name="Same TestCases on multiple VM's" parallel="tests" thread-count="2"> 
    <test name="Run on leocp" >
    <parameter name="IP"  value="xxxxx"/>
        <classes>
            <class name="cptests.TestFileUpload"/>
        </classes>
    </test>    
    <test name="Test4: Run on hornback" >
    <parameter name="IP"  value="xxxxx"/>
        <classes>
            <class name="cptests.TestFileUpload"/>
        </classes>
    </test>
</suite>

==========================================================================================

Thanks
 Bhoomika
image001.gif

Mike Riley

unread,
Mar 20, 2012, 2:30:43 PM3/20/12
to webdriver
This has been a useful discussion.

Can you also have it do something like parallel="suite"?

I have some suites that are so large I implemented them as multiple
classes which extended the base class (where I put common variables
and objects, as well as methods they would all need).

Right now I am running serially, but later I will be running most of
these in parallel.

Mike

Bhoomika Annaiah

unread,
Mar 20, 2012, 2:33:27 PM3/20/12
to webd...@googlegroups.com
Hi Mike,

I will update you if i do anything on that.

Thanks
Bhoomika


--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.

SANTHOSH BABY

unread,
Mar 20, 2012, 3:52:14 PM3/20/12
to webd...@googlegroups.com
with selenium rc grid  there was no problem of this selenium hub used handle this  issue

But in Selenium 2 grid  it  is explicitly mentioned  threads has to be handle separately . that means users code has to take care of thread safety . Selenium2 hub just runs the incoming instances ,
image001.gif

payal

unread,
May 4, 2012, 8:12:42 AM5/4/12
to webdriver
Hi Bhoomika,

I am also trying to achieve parallel distribution of test suite across
VMs. Here you have mentioned that you are trying to execute same test
cases on different virtual machine.

My requirement is to distribute test cases of a test suite across VMs.

I am not sure on how can we update testng file to make this work.
Because you have already achieved execution on VMs simultaneously,
Your help is much appreciated on this.

You can refer to this link for all the discussion I had so far
https://groups.google.com/forum/#!msg/webdriver/VmqDFnsKgWE/S3fNAd75UacJ

On Mar 21, 12:52 am, SANTHOSH BABY <santosh.b...@gmail.com> wrote:
> with selenium rc grid  there was no problem of this selenium hub used
> handle this  issue
>
> But in *Selenium 2 grid  it  is explicitly mentioned  threads has to be
> handle separately . that means users code has to take care of thread safety
> . Selenium2 hub just runs the incoming instances ,*
> *
> *
> > driver.get().findElementByName("file").sendKeys("C:\\Testing_Originals\\ODS -testfile1.ods");
>
> > driver.get().findElementByName("file").sendKeys("C:\\Testing_Originals\\tes t1.odt");
>
> > driver.get().findElementByName("file").sendKeys("C:\\Testing_Originals\\tes t2.ppt");
>
> > driver.get().findElementByName("file").sendKeys("C:\\Testing_Originals\\htm l-file1.html");
> > On Mon, Mar 19, 2012 at 11:11 PM, SANTHOSH BABY <santosh.b...@gmail.com>wrote:
>
> >> yup this is how one should run ,  Driver instance(threads) should be
> >> created always separate
>
> >> **
>
> >> *
>
> >> *
> >> *
> >> Santhosh|  Software Automation  Engineer
> >> *
> >> <https://webmail.symphonysv.com/owa/redir.aspx?C=c6625cdd4dae48d58b5ce...>
> >> *
>
> >> <http://in.linkedin.com/in/santhoshbaby>
>
> >> Think GREEN. Please consider the environment before printing this email
> >> *
> >> *
>
> >> "When The Winds of Change Blow..... Some people Build Walls & Others
> >> Windmills.... Attitude Matters...."
> >> *
> ...
>
> read more »
>
>  image001.gif
> 4KViewDownload

Krishnan Mahadevan

unread,
Jul 16, 2012, 5:38:21 AM7/16/12
to webd...@googlegroups.com
Harini,
Instead of that, why not try instantiating the ThreadLocal<WebDriver> within a beforeInvocation() {TestNG Listeners} and then use it.
This is how we created our internal framework and its worked fine till now.

In a nutshell, this is what I am talking about :



Browse through this project : https://github.com/freynaud/testng-support


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"



On Sat, Jul 14, 2012 at 4:11 AM, seluser <techie...@gmail.com> wrote:
Hello Bhoomika,

I am trying to do the same thing. But I notice that my @BeforeMethod and @AfterMethod run on the same thread ID but my @Test runs on a different one. So my ThreadLocal<WebDriver> is not valied in my @Test Scope. Did you face something similar too?

My base class has all the @before and @after methods for driver setup. The TestNG class extends this base class.

Thanks for any help!
Harini
To unsubscribe from this group, send email to webdriver+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/xNJLuk9AUmcJ.

tech hari

unread,
Jul 16, 2012, 1:42:35 PM7/16/12
to webd...@googlegroups.com

Hello Krishnan,

Thanks much for you help. I did some analysis on this thread issue: I found that the tests and configuration methods(@before and @aftermethods) run in separate threads only if I specify a timeout. Does this method work for tests having a timeout param in @test annotation?

Thanks!!

Krishnan Mahadevan

unread,
Jul 16, 2012, 1:53:14 PM7/16/12
to webd...@googlegroups.com
Harini,
I dont see any reason it shouldnt. Although I havent played around with setting timeouts to @Test methods my gut feel is it would work in all cases. 


--
Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

Ranjith kumar

unread,
Feb 13, 2013, 12:05:08 PM2/13/13
to webd...@googlegroups.com, sbhoomik...@gmail.com
Hi Andy and Bhoomika.. Thanks for clarification.

Is this is the only way to run the same test in multiple machines.
if there is any other way to do. please give me ur suggestion on this.


Thanking you.
K.Ranjithkumar

Krishnan Mahadevan

unread,
Feb 14, 2013, 1:33:41 AM2/14/13
to webd...@googlegroups.com
Ranjith,

How is it going to impact you if the test run on the same machine or different machine ?
If the test is running on different environments, then it makes sense, and in that case, the test differs in every iteration w.r.t values it gets.
So no there are no other alternatives here.

Either create multiple <test> in your suite file and pass different parameters or work with Factory powered by a Data Provider to have it cook up unique test class instances which get its values from a data source.


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/


To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.

To post to this group, send email to webd...@googlegroups.com.

sagar

unread,
Mar 15, 2013, 5:50:48 AM3/15/13
to webd...@googlegroups.com
Hi Karthik,

Can you elaborate more by providing some help like useful links?
Thank you.

Regards,
Sagari

Regards, Karthik
--------




> To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.
>

--
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/

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/7cQXqvhz16oJ.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.
Reply all
Reply to author
Forward
0 new messages