4

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

asked Sep 5, 2017 at 13:22
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?

answered Sep 6, 2017 at 14:28
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");
 }
 }
}
answered Nov 4, 2018 at 13:52
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. Commented Nov 5, 2018 at 12:42

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.