4

How to run test scripts in parallel for Selenium WebDriver with Visual Studio and C# ?

0

2 Answers 2

4

Disclaimer: the answer is assuming you're using the MsTest unit test framework.

Solution 1

The easiest way to run parallel tests is simply to activate this flag here:

enter image description here

An important note here: this only works for tests in different assemblies (projects). So tests in the same test project will still run sequentially. Of course, with large test suites for several modules, proper structuring of code should almost automatically result in several projects.

Solution 2

Another way to run in parallel is described here, in short: add the <parallelTestCount> node to the <Execution> node in your TestSettings.xml. This allows parallelism within an assembly. However, I have noticed that you'll probably need to deploy resource files using the DeploymentItem attribute.

Solution 3

Using SeleniumGrid as described here. I imagine this option is beyond the intent of your question?

0

Add attribute [Parallelizable] to your classes or methods which you wanna to execute parallel and try to tun. Be careful because if you add [Parallelizable] attribute to all test methods in the class with the attribute [TestFixture] - will use only 1 copy of driver in all tests. The sample below works for me fine.

[TestFixture]
public class AllTestByID
{
    IWebDriver _currentBrowser = new ChromeDriver(@"C:\Docs\QA\TestFrame\TestFrame\bin\Debug");

    [TestFixture]
    [Parallelizable]
    public class CheckSearch
    {
        AllTestByID newCopy = new AllTestByID();

        [Test]
        public void DownloadReport()
        {
            newCopy._currentBrowser.Navigate().GoToUrl("https://www.google.com/");
            newCopy._currentBrowser.FindElement(By.XPath("//input[@id='lst-ib']")).SendKeys("Find something");
        }
    }

    [TestFixture]
    [Parallelizable]
    public class CheckSearch2
    {
        AllTestByID newCopy = new AllTestByID();

        [Test]
        public void DownloadReport()
        {
            newCopy._currentBrowser.Navigate().GoToUrl("https://www.google.com/");
            newCopy._currentBrowser.FindElement(By.XPath("//input[@id='lst-ib']")).SendKeys("Find something");
        }
    }
}
1
  • For a late answer like this, you really need to explain how the [Parallelizable] attribute on classes or methods will impact the OP. Are there limits to parallelization? Methods/classes that can't be run in parallel? As it stands your answer might be correct, but it needs much more information to be a good answer. The Help Center (sqa.stackexchange.com/help/how-to-answer) has advice on what makes a good answer.
    – Kate Paulk
    Commented Nov 5, 2018 at 12:42

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.