Run few test in parallel - all test in particular group that depends on other group- Testng + Webdriver

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

Run few test in parallel - all test in particular group that depends on other group- Testng + Webdriver

garvitagirotraev
Hi,

Here is my present testng.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test name="Dashborad">
 <groups>
<dependencies>
<group name="RunSecond" depends-on="RunFirst" />
                              <group name="RunThird" depends-on="RunSecond" />
</dependencies>
</groups> 
<classes>
<class name="ipd.xxxxxx.CreateClient" />
<class name="ipd.xxxxxx.CreateProject" />
<class name="ipd.xxxxxx.CreateUser" />
<class name="ipd.xxxxxx.uploadData" />
                        <class name="ipd.xxxxxx.Chart1" />
                        <class name="ipd.xxxxxx.Chart2" />
                        <class name="ipd.xxxxxx.Chart3" />
        </test>
</suite> 

Where, CreateClient, CreateProject, CreateUser belong to group {RunFirst}, UploadData class belongs to group {RunSecond} and 3 chart classes belong to group {RunThird}.

I want only chart classes to run in parallel. I tried implementing it by making 2 tests : 1 sequential and other parallel, where parallel="classes". But it did not give desired output.If test are running in parallel, each test should open in new driver instance that will require logging in to portal and going to required page. Each class extends base class and driver is instantiated in constructor of base class, so each class can run independently.

Logic for logging in is written in @BeforeSuite method :

@Parameters({ "url", "username", "password" })
    @BeforeSuite
    public void init(String url, String Username, String Password)
            throws IOException {
        try {
           
            driver.navigate().to(url);
            input("UserID", Username);
            input("PassBox", Password);
            click("Login_Button");
          }
       }


Driver is initiated in constructor of base class and each class extends base class:

public Base() throws IllegalArgumentException, IOException {
        try {
            prop = new Properties();
            loadPropertyFile(path);
            final String browser = prop.getProperty("ipd.browser", "firefox");

            switch (browser) {
            case "firefox": {
                setupFirefoxDriver();
                break;
            }
            case "chrome": {
                setupChromeDriver();
                break;
            }
            default:
                throw new IllegalArgumentException("Unknown ipd.test.browser");
            }
}

Thanks !!

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

Re: Run few test in parallel - all test in particular group that depends on other group- Testng + Webdriver

Krishnan Mahadevan

Am not sure I completely understand your problem.

You have a @BeforeSuite annotated method which seems to be loading the URL etc., That is going to be executed only once per suite.

 

Can you please create a simple standalone project, upload it to github and share the link ? That way its easy for anyone who wants to debug your issue to just look at the code directly.

 

Also please get rid of all Selenium code etc., so that we eliminate any failures due to selenium and share what is the expected output when one runs your code.

 

For your problem statement wherein you want to run only the chart related code in parallel, adding a parallel=”methods” at the <test> level should suffice. But that is going to cause the other methods to run in parallel as well.

 

You also cannot establish dependencies across <test> tags.

 

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-To: <[hidden email]>
Date: Monday, March 26, 2018 at 3:18 PM
To: testng-users <[hidden email]>
Subject: [testng-users] Run few test in parallel - all test in particular group that depends on other group- Testng + Webdriver

 

Hi,

 

Here is my present testng.xml:

 

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="Suite">

                <test name="Dashborad">

                                 <groups>

                                                <dependencies>

                                                                <group name="RunSecond" depends-on="RunFirst" />

                              <group name="RunThird" depends-on="RunSecond" />

                                                </dependencies>

                                </groups> 

                                <classes>

                                                <class name="ipd.xxxxxx.CreateClient" />

                                                <class name="ipd.xxxxxx.CreateProject" />

                                                <class name="ipd.xxxxxx.CreateUser" />

                                                <class name="ipd.xxxxxx.uploadData" />

                        <class name="ipd.xxxxxx.Chart1" />

                        <class name="ipd.xxxxxx.Chart2" />

                        <class name="ipd.xxxxxx.Chart3" />

        </test>

</suite> 

 

Where, CreateClient, CreateProject, CreateUser belong to group {RunFirst}, UploadData class belongs to group {RunSecond} and 3 chart classes belong to group {RunThird}.

 

I want only chart classes to run in parallel. I tried implementing it by making 2 tests : 1 sequential and other parallel, where parallel="classes". But it did not give desired output.If test are running in parallel, each test should open in new driver instance that will require logging in to portal and going to required page. Each class extends base class and driver is instantiated in constructor of base class, so each class can run independently.

 

Logic for logging in is written in @BeforeSuite method :

 

@Parameters({ "url", "username", "password" })

    @BeforeSuite

    public void init(String url, String Username, String Password)

            throws IOException {

        try {

           

            driver.navigate().to(url);

            input("UserID", Username);

            input("PassBox", Password);

            click("Login_Button");

          }

       }

 

 

Driver is initiated in constructor of base class and each class extends base class:

 

public Base() throws IllegalArgumentException, IOException {

        try {

            prop = new Properties();

            loadPropertyFile(path);

            final String browser = prop.getProperty("ipd.browser", "firefox");

 

            switch (browser) {

            case "firefox": {

                setupFirefoxDriver();

                break;

            }

            case "chrome": {

                setupChromeDriver();

                break;

            }

            default:

                throw new IllegalArgumentException("Unknown ipd.test.browser");

            }

}

 

Thanks !!

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

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