0

I want to run same script on three browser IE, Chrome and Firefox at a time (i.e., parallel). I am using the following code in Testng.xml file

 <test name="RunTests-1">
    <parameter name="browser" value="firefox" />     
    <parameter name="port" value="http://localhost:4444/wd/hub" />
    <classes>
        <class name="Com.TestSuite.class1"/>
    </classes>
</test>  
<test name="RunTests-2">
    <parameter name="browser" value="chrome" />     
    <parameter name="port" value="http://localhost:4444/wd/hub" />
    <classes>
        <class name="Com.TestSuite.class1"/>
    </classes>
</test>
<test name="RunTests-3">
    <parameter name="browser" value="internet explorer" />     
    <parameter name="port" value="http://localhost:4444/wd/hub" />
    <classes>
        <class name="Com.TestSuite.class1"/>
    </classes>
</test> 

while running it using TestNG, it is opening 3 browsers and executing the script. But the problem is while executing the script, it is performing some operations in the script(like entering a text in text field, clicking on a button etc) twice in one browser and not at all performing in other browsers. Please let me know what may be the reason for that.

4
  • Post the code which you used to invoke the browser. Commented Feb 12, 2013 at 8:33
  • Please refer to following google docs link for my code: docs.google.com/document/d/… Commented Feb 12, 2013 at 8:54
  • In the code where is driver instance declaration part and check weather you declared as a Static or not. Commented Feb 12, 2013 at 10:17
  • ya i have given as private static WebDriver driver; .... i have updated in above google docs link Commented Feb 12, 2013 at 12:18

1 Answer 1

3

When you declare the variable as a Static. It will consider as a server side variable. In your case when you launch three browsers. It will use single driver instance for all the three browser sessions. For that reason alone the action is performing repeatedly in a same browser. To resolve the issue remove the Static keyword from the web driver definition.

Eg:

private WebDriver driver = null;

Sign up to request clarification or add additional context in comments.

2 Comments

If my solution helps you then make it as a answer.
@Manigandan thanks a lot.Wish I could've seen it 5 hours earlier.:)Wish could give you 100 upvotes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.