If we want to run our tests in parallel on different browser or same browser, we can make use of NUnit's Parallelizable attribute.
Below is the complete code, In the below example, There are 2 tests configured to run on IE and Chrome Browser, but if we need some more browser we can add that too, as per the requirements or even stick to just one browser and still do parallel execution.
1. Login to Redifmail
2. Open Google
So when we execute the below tests, we can see that 2 chrome browser window will open and execute the above 2 tests simultaneously, and once that is done it will open 2 IE Window and execute the tests again.
NOTE: To make this run on Parallel, in Test Explorer Window, make sure to select " Run Tests in Parallel" button ( Button with 3 arrows) and click on Run All button.
Below is the complete code, In the below example, There are 2 tests configured to run on IE and Chrome Browser, but if we need some more browser we can add that too, as per the requirements or even stick to just one browser and still do parallel execution.
1. Login to Redifmail
2. Open Google
So when we execute the below tests, we can see that 2 chrome browser window will open and execute the above 2 tests simultaneously, and once that is done it will open 2 IE Window and execute the tests again.
NOTE: To make this run on Parallel, in Test Explorer Window, make sure to select " Run Tests in Parallel" button ( Button with 3 arrows) and click on Run All button.
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Chrome;
using System.Diagnostics;
namespace Purush_Selenium
{
[TestFixture(typeof(ChromeDriver))]
[TestFixture(typeof(InternetExplorerDriver))]
public class Purush_ParallelExecution<TWebDriver> where TWebDriver : IWebDriver, new()
{
private IWebDriver driver;
[Test, Parallelizable]
public void
Purush_RediffMailLogin()
{
driver = new TWebDriver();
// Navigate
driver.Navigate().GoToUrl("https://mail.rediff.com/cgi-bin/login.cgi");
driver.SwitchTo().DefaultContent();
driver.FindElement(By.Name("login")).SendKeys("Purush");
driver.FindElement(By.Name("passwd")).SendKeys("Purush@Password");
driver.FindElement(By.Name("proceed")).Click();
}
[Test, Parallelizable]
public void
Purush_OpenGoogle()
{
driver = new TWebDriver();
driver.Navigate().GoToUrl("https://www.google.com");
}
}
}
0 comments: