Need Help Parrel Cross Browser Testing

71 views
Skip to first unread message

Lokenath Ghosh

unread,
Apr 23, 2015, 9:10:31 AM4/23/15
to seleniu...@googlegroups.com
Hi,

I want to do cross browser(chrome and Firefox) parallel execution in two different machines using Selenium Grid, TestNG,Selenium Webdriver.  As my code is not  supporting multithreading ,One of the excfution is stopped and another execution is successfully completed. Please suggest What I should do for parallel test excution.

My Java  Code:

@Parameters("browser")
       
        @BeforeTest
        public void  SetupBrowser(String browser) throws MalformedURLException
        {
           
            DesiredCapabilities capability=null;
            String baseurl="http://10.195.7.71:8080/application/";
            String    nodeurl="http://10.195.11.167:5566/wd/hub";
              
                if (browser.equalsIgnoreCase("chrome"))
                {
                  
                    System.setProperty("webdriver.chrome.driver", "\\10.195.11.167\\c$\\Program Files (x86)\\Google\\Chrome\\Applicationchromedriver.exe");
                    capability =  DesiredCapabilities.chrome();
                    capability.setBrowserName("chrome");
                    capability.setPlatform(Platform.VISTA);
                    
                }
           
               
                if(browser.equalsIgnoreCase("firefox"))
                {
                
                     capability =  DesiredCapabilities.firefox();
                    capability.setBrowserName("firefox");
                    capability.setPlatform(Platform.VISTA);
                 
                }
                driver=new RemoteWebDriver(new URL(nodeurl),capability);
                driver.get("http://10.195.7.71:8080/application/");


TestNG XML:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="tests"  thread-count="2" >
<test name="Chrome" >
    <parameter name="browser" value="chrome"></parameter>
    <classes>
      <class name="com.lexmark.testclass.TestARR"/>
    </classes>
  </test>

  <test name="FireFox" >
  <parameter name="browser" value="firefox"></parameter>
    <classes>
      <class name="com.lexmark.testclass.TestARR"/>
    </classes>
  </test> <!-- Test -->
 
   
 
</suite> <!-- Suite -->


Krishnan Mahadevan

unread,
Apr 23, 2015, 9:21:30 AM4/23/15
to Selenium Users


It should help you get started .



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/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
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/756d8576-d6a1-44a2-8db0-c015fce6988c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Lokenath Ghosh

unread,
Apr 24, 2015, 12:26:04 AM4/24/15
to seleniu...@googlegroups.com
Hi Krishnan,

Thank you for giving input.I have tried this before, but it is not worked for me. It is for parallel methods executing. But in my case , I want to run my user journey into two different browser in parallel( parallel="tests" ).

Krishnan Mahadevan

unread,
Apr 24, 2015, 1:23:31 AM4/24/15
to Selenium Users
Lokenath,

You should still be able to extend the concept that I talk about in my blog post and get it done.
Parallelism mechanism [ instance/class/methods/tests] has got nothing to do with the approach.
So if you are sure that for a given <test> tag there will be the need to have just 1 browser you just need to make modifications slightly and this would still work for you.



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/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

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

Lokenath Ghosh

unread,
Apr 24, 2015, 6:32:03 AM4/24/15
to seleniu...@googlegroups.com

I am getting null in method.getTestMethod().getXmlTest(). Code is below. Please provide the solution

package com.lexmark.functionlibrary;

import org.openqa.selenium.WebDriver;
import org.testng.IInvokedMethod;
import org.testng.IInvokedMethodListener;
import org.testng.ITestResult;
 
public class WebDriverListener implements IInvokedMethodListener {
 
    @Override
    public void beforeInvocation(IInvokedMethod method , ITestResult testResult)  {
  // System.out.println("kolkat"+!method.isTestMethod());
        if (!method.isTestMethod()) {
       
       
String browserName = method.getTestMethod().getXmlTest().getLocalParameters().get("browserName");
       
        // String browserName = method.
        // System.out.println("kolkat"+browserName);
            WebDriver driver = LocalDriverFactory.createInstance(browserName);
            LocalDriverManager.setWebDriver(driver);
        }
    }
 
    @Override
    public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
        if (!method.isTestMethod()) {
            WebDriver driver = LocalDriverManager.getDriver();
            if (driver != null) {
                driver.quit();
            }
        }
    }
}






<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<!-- <suite name="Suite" parallel="tests" thread-count="2"> -->
<suite name="Suite">
<listeners>
<listener class-name="com.lexmark.functionlibrary.WebDriverListener"></listener>
</listeners>

<test name="Chrome" >
 <parameter name="browserName" value="chrome"></parameter>
 <classes>
   <class name="com.lexmark.testclass.TestARR"/>
 </classes>
</test> 

  <test name="FireFox" >
  <parameter name="browserName" value="firefox"></parameter>
    <classes>
      <class name="com.lexmark.testclass.TestARR"/>
    </classes>
  </test> 
  
    
  
</suite> <!-- Suite -->





@Parameters("browserName")
@BeforeTest
public void  lauchurl(String url) throws InterruptedException
{
//System.out.println("chalche"+LocalDriverManager.getDriver());
LocalDriverManager.getDriver().get("http://10.195.7.71:8080/application/");
//Thread.sleep(10000);
//System.out.println("chalche"+LocalDriverManager.getDriver());
takescreenshot= new TakeScreenshot();
}

--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/rjMEPqhGwHQ/unsubscribe.
To unsubscribe from this group and all its topics, 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/d/optout.



--
Regards,
 Lokenath Ghosh

Krishnan Mahadevan

unread,
Apr 24, 2015, 7:06:24 AM4/24/15
to Selenium Users
What solution are you looking for ?
I shared a blog post of mine which contains working code.
if (!method.isTestMethod()) {  <---- Why is this line checking if the method is NOT a TEST METHOD and then trying to create a webdriver instance ?




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/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

Lokenath Ghosh

unread,
Apr 24, 2015, 7:25:31 AM4/24/15
to seleniu...@googlegroups.com
I want to initiate my webdriver in @BeforeTest tag. Thats why I was using  (!method.isTestMethod()). I f i use in method.isTestMethod() tag it will a new instance every when I call @test classes.

I am looking the scenario which consists look like like this:


TestNG.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="tests" thread-count="2">

<listeners>
<listener class-name="com.lexmark.functionlibrary.WebDriverListener"></listener>
</listeners>

<test name="Chrome" >
 <parameter name="browserName" value="chrome"></parameter>
 <classes>
   <class name="com.lexmark.testclass.TestARR"/>
 </classes>
</test> 

  <test name="FireFox" >
  <parameter name="browserName" value="firefox"></parameter>
    <classes>
      <class name="com.lexmark.testclass.TestARR"/>
    </classes>
  </test> 
</suite> <!-- Suite -->


Code:
@BeforeTest

//call the webdriver


@Test
\\ do something

@Test
\\ do something

@Test
\\ do something


@Test
\\ do something


@Test
\\ do something

@AfterTest

//quit the webdriver



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

Krishnan Mahadevan

unread,
Apr 24, 2015, 7:40:02 AM4/24/15
to Selenium Users
I would suggest that you please spend some time with TestNG before you take this any further.

TestNG provides you a guarantee that only the beforeInvocation() > test/configuration method > afterInvocation() will run in the same thread. 

For all other cases there is NO GUARANTEE whatsoever that they all will run in the same thread.

The solution that I posted in the blog post relies on the guarantee that TestNG provides for beforeInvocation/test (or) config method/after invocation scenario.

So its never going to work for what you are trying to do.

I still DONT understand why do you want to create a webdriver instance in an @BeforeTest ?? Do you realize that what you are essentially instructing TestNG to do is to create only 1 webdriver instance per <test> tag ?
In that case, do you also realize that there can be chances of multiple @Test annotated test methods trying to do different UI scenarios on the same web browser ?

Why would you want to do this ?

My word of advice : Please take some time to get a good feel of TestNG and then give this a shot.


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/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

Reply all
Reply to author
Forward
0 new messages