Quantcast

URL not getting passed on parallel execution of methods

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

URL not getting passed on parallel execution of methods

Aswathy Nair
Hi ,
I am facing weird issue of URL not getting passed to browser. My test class has multiple @Test 's. Though multiple browser instances and threads are getting created, only one browser instance has URL. In case of chrome , its showing "data:,"
and in firefox empty url.

Kindly find below configuration

public class BaseTest {

protected WebDriver driver ;
protected DesiredCapabilities desiredCapabilities;

HomePage pg;

@BeforeMethod
@Parameters("browser")
public void setUp(String browser) throws MalformedURLException {

System.out.println("in the setup method "+Thread.currentThread().getId());

if (browser.equalsIgnoreCase("firefox")) {
System.setProperty("webdriver.gecko.driver", "src/test/resources/geckodriver");
driver = new FirefoxDriver();
driver.manage().window().maximize();

} else if (browser.equalsIgnoreCase("chrome")) {
System.setProperty("webdriver.chrome.driver", "src/test/resources/chromedriver");

driver = new ChromeDriver();
Toolkit toolkit = Toolkit.getDefaultToolkit();
int Width = (int) toolkit.getScreenSize().getWidth();
int Height = (int) toolkit.getScreenSize().getHeight();
driver.manage().window().setSize(new org.openqa.selenium.Dimension(Width, Height));


} else {
throw new IllegalArgumentException("Invalid browser value!!");
}
driver.get("http://automationpractice.com/index.php");

}

@AfterMethod
public void teardown() throws Exception {
driver.quit();
}

TESTNG.XML

<suite name="TestNG Test" parallel="methods" thread-count="4">
<test name="Chrome Tests">

<classes>
<parameter name="browser" value="chrome" />
<class name="com.abn.testNGTest.FirstTest"/>
</classes>
</test>

</suite>


public class FirstTest extends BaseTest {

@Test()
public void aTest() throws IOException {

System.out.println("aTest in " + getClass().getSimpleName()
+ " with Thread Id: " + Thread.currentThread().getId());
pg = new HomePage(driver);
}


@Test()
public void bTest() throws Exception {
System.out.println("contactUsTest in " + getClass().getSimpleName()
+ " with Thread Id: " + Thread.currentThread().getId());
pg = new HomePage(driver);

}



Here only one of the test method gets URL though multiple threads and browser instance gets created.

Kindly let me know if am doing something wrong in configuration.

Regards,

Aswathy

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: URL not getting passed on parallel execution of methods

⇜Krishnan Mahadevan⇝
Aswathy,

Your code seems to be suffering from concurrency issues.
Here's a threadsafe version of what you are trying to do.


public class GetParamsFromSuite {
    private static ThreadLocal<String> names = new ThreadLocal<>();

    @BeforeMethod
    @Parameters ("name")
    public void setup(String name) {
        names.set(name);
    }

    @Test
    public void testMethod() {
        System.err.println("Obtained : " + names.get());
        Assert.assertNotNull(names.get(), "Ensuring name is never null.");
        Assert.assertTrue(names.get().contains("tiger"));
    }

    @Test
    public void anotherTestMethod() {
        System.err.println("Obtained : " + names.get());
        Assert.assertNotNull(names.get(), "Ensuring name is never null.");
        Assert.assertTrue(names.get().contains("lion"));
    }

    @AfterMethod
    public void cleanup() {
        names.set(null);
    }
}

Here's a suite xml file


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="1265_Suite" parallel="methods" verbose="2">
    <test name="92">
        <classes>
            <class name="org.rationale.emotions.GetParamsFromSuite">
                <methods>
                    <include name="testMethod">
                        <parameter name="name" value="tiger clan"/>
                    </include>
                    <include name="anotherTestMethod">
                        <parameter name="name" value="lion clan"/>
                    </include>
                </methods>
            </class>
        </classes>
    </test>
</suite>
Here's the output

...
... TestNG 6.9.10 by Cédric Beust ([hidden email])
...

[TestNG] Running:
  /Users/krmahadevan/playground/scrappable-project/src/test/resources/get_params_from_suite.xml
[TestRunner] Starting executor for test 92 with time out:2147483647 milliseconds.
Obtained : tiger clan
Obtained : lion clan
PASSED: testMethod
PASSED: anotherTestMethod

===============================================
    92
    Tests run: 2, Failures: 0, Skips: 0
===============================================

===============================================
1265_Suite
Total tests run: 2, Failures: 0, Skips: 0
===============================================
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/

On Saturday, January 14, 2017 at 9:52:44 PM UTC+5:30, Aswathy wrote:
Hi ,
I am facing weird issue of URL not getting passed to browser. My test class has multiple @Test 's. Though multiple browser instances and threads are getting created, only one browser instance has URL. In case of chrome , its showing "data:,"
and in firefox empty url.

Kindly find below configuration

public class BaseTest {

protected WebDriver driver ;
protected DesiredCapabilities desiredCapabilities;

HomePage pg;

@BeforeMethod
@Parameters("browser")
public void setUp(String browser) throws MalformedURLException {

System.out.println("in the setup method "+Thread.currentThread().getId());

if (browser.equalsIgnoreCase("firefox")) {
System.setProperty("webdriver.gecko.driver", "src/test/resources/geckodriver");
driver = new FirefoxDriver();
driver.manage().window().maximize();

} else if (browser.equalsIgnoreCase("chrome")) {
System.setProperty("webdriver.chrome.driver", "src/test/resources/chromedriver");

driver = new ChromeDriver();
Toolkit toolkit = Toolkit.getDefaultToolkit();
int Width = (int) toolkit.getScreenSize().getWidth();
int Height = (int) toolkit.getScreenSize().getHeight();
driver.manage().window().setSize(new org.openqa.selenium.Dimension(Width, Height));


} else {
throw new IllegalArgumentException("Invalid browser value!!");
}
driver.get("<a href="http://automationpractice.com/index.php" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fautomationpractice.com%2Findex.php\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF_PkfeEgLRF3xMecOqAyHM99S4iQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fautomationpractice.com%2Findex.php\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF_PkfeEgLRF3xMecOqAyHM99S4iQ&#39;;return true;">http://automationpractice.com/index.php");

}

@AfterMethod
public void teardown() throws Exception {
driver.quit();
}

TESTNG.XML

<suite name="TestNG Test" parallel="methods" thread-count="4">
<test name="Chrome Tests">

<classes>
<parameter name="browser" value="chrome" />
<class name="com.abn.testNGTest.FirstTest"/>
</classes>
</test>

</suite>


public class FirstTest extends BaseTest {

@Test()
public void aTest() throws IOException {

System.out.println("aTest in " + getClass().getSimpleName()
+ " with Thread Id: " + Thread.currentThread().getId());
pg = new HomePage(driver);
}


@Test()
public void bTest() throws Exception {
System.out.println("contactUsTest in " + getClass().getSimpleName()
+ " with Thread Id: " + Thread.currentThread().getId());
pg = new HomePage(driver);

}



Here only one of the test method gets URL though multiple threads and browser instance gets created.

Kindly let me know if am doing something wrong in configuration.

Regards,

Aswathy

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: URL not getting passed on parallel execution of methods

Aswathy Nair
In reply to this post by Aswathy Nair
Hi Krishnan,

Thanks a lot. Meanwhile i have gone through one of your blog on the same : https://rationaleemotions.wordpress.com/2013/07/31/parallel-webdriver-executions-using-testng/

This helped in solving the issue.

Thank you.

Regards,

Aswathy

On Saturday, 14 January 2017 21:52:44 UTC+5:30, Aswathy wrote:
Hi ,
I am facing weird issue of URL not getting passed to browser. My test class has multiple @Test 's. Though multiple browser instances and threads are getting created, only one browser instance has URL. In case of chrome , its showing "data:,"
and in firefox empty url.

Kindly find below configuration

public class BaseTest {

protected WebDriver driver ;
protected DesiredCapabilities desiredCapabilities;

HomePage pg;

@BeforeMethod
@Parameters("browser")
public void setUp(String browser) throws MalformedURLException {

System.out.println("in the setup method "+Thread.currentThread().getId());

if (browser.equalsIgnoreCase("firefox")) {
System.setProperty("webdriver.gecko.driver", "src/test/resources/geckodriver");
driver = new FirefoxDriver();
driver.manage().window().maximize();

} else if (browser.equalsIgnoreCase("chrome")) {
System.setProperty("webdriver.chrome.driver", "src/test/resources/chromedriver");

driver = new ChromeDriver();
Toolkit toolkit = Toolkit.getDefaultToolkit();
int Width = (int) toolkit.getScreenSize().getWidth();
int Height = (int) toolkit.getScreenSize().getHeight();
driver.manage().window().setSize(new org.openqa.selenium.Dimension(Width, Height));


} else {
throw new IllegalArgumentException("Invalid browser value!!");
}
driver.get("<a href="http://automationpractice.com/index.php" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fautomationpractice.com%2Findex.php\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF_PkfeEgLRF3xMecOqAyHM99S4iQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fautomationpractice.com%2Findex.php\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF_PkfeEgLRF3xMecOqAyHM99S4iQ&#39;;return true;">http://automationpractice.com/index.php");

}

@AfterMethod
public void teardown() throws Exception {
driver.quit();
}

TESTNG.XML

<suite name="TestNG Test" parallel="methods" thread-count="4">
<test name="Chrome Tests">

<classes>
<parameter name="browser" value="chrome" />
<class name="com.abn.testNGTest.FirstTest"/>
</classes>
</test>

</suite>


public class FirstTest extends BaseTest {

@Test()
public void aTest() throws IOException {

System.out.println("aTest in " + getClass().getSimpleName()
+ " with Thread Id: " + Thread.currentThread().getId());
pg = new HomePage(driver);
}


@Test()
public void bTest() throws Exception {
System.out.println("contactUsTest in " + getClass().getSimpleName()
+ " with Thread Id: " + Thread.currentThread().getId());
pg = new HomePage(driver);

}



Here only one of the test method gets URL though multiple threads and browser instance gets created.

Kindly let me know if am doing something wrong in configuration.

Regards,

Aswathy

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Loading...