0

Is there any solutions for executing multiple selenium webdriver java test-scripts having different parameters at one time and get results.

If parameter is URLs, then we can test multiple Urls on one browserNames i.e Chrome, Firefox, Microsoft Edge, etc. as both sequential & parallel test execution.

But If parameter is browserNames, then we can achieve only sequential test execution.

Now, clear objective is to achieve parallel test execution of common test-script(selenium webdriver) to run on multi web browsers (chrome, firefox , edge, etc.) at sametime to get Test Pass/Fail.

So, Is it possible to achieve parallel test execution ?

I have code example, which leads this desiring idea :-

package InternetTestWebsite;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class TestData1 {
    public static void main(String[] args) {
        String baseUrl = "https://www.saucedemo.com";
        String browserName = "chrome";
        LoginThePage(browserName, baseUrl);
    }

    public static void LoginThePage(String browserNameforTestExecution, String baseUrl) {
        try {
            WebDriver driver;
            if (browserNameforTestExecution.equalsIgnoreCase("firefox")) {
                System.setProperty("webdriver.gecko.driver", ".\\geckodriver.exe");
                driver = new FirefoxDriver();
            } else if (browserNameforTestExecution.equalsIgnoreCase("chrome")) {
                System.setProperty("webdriver.chrome.driver", ".\\chromedriver.exe");
                driver = new ChromeDriver();
            } else if (browserNameforTestExecution.equalsIgnoreCase("Edge")) {
                System.setProperty("webdriver.edge.driver", ".\\MicrosoftWebDriver.exe");
                driver = new EdgeDriver();
            } else {
                throw new Exception("Browser is not correct");
            }

            driver.get(baseUrl);
            driver.manage().window().maximize();

            WebElement username = driver.findElement(By.xpath("//input[@type='text']"));
            username.clear();
            username.sendKeys("standard_user");

            WebElement password = driver.findElement(By.xpath("//input[@type='password']"));
            password.clear();
            password.sendKeys("secret_sauce");

            WebElement loginbtn = driver.findElement(By.xpath("//input[@type='submit']"));
            loginbtn.click();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
2
  • 2
    Can you add some code? You question is not clear.
    – Alexey R.
    Feb 1 at 7:44
  • Hello Alexey R. , i have added sample code and enhanced description above.
    – user51288
    Feb 2 at 6:41

2 Answers 2

0

The parameters of execution depends on the setup you do to the WebDriver objects. Meaning you can control how the execution will happen when creating the driver objects.

Example (pseudo-code):

class LoginSuite:
   constructor:
      driver = WebDriver(Firefox)


class LogoutSuite:
   constructor:
      driver = WebDriver(Chrome)

And, of course, the parameters don't need to be hardcoded - they can come from a configuration file, an execution argument, or some remote configuration server.

Note: If you run these suites in parallel, you may have concurrency issues with the selenium server - it will depend on your application and how it deals with the browser. In the case of sequential execution, you probably won't have issues.

1
  • So João ,this means that sequential test execution is only possible way and best final solution.
    – user51288
    Feb 2 at 6:15
0

Parallel execution is possible but unless you have a requirement to do this, I wouldn't recommend it. For example, I had a project where the requirement was to make sure that there was no data bleed between multiple browsers running on the same machine. I was able to run 4 or 5 browsers on the same machine at once, but this was pushing the memory limit. I would recommend running tests on multiple machines or running them sequentially, as João stated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy