Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to run Selenium tests in multiple browsers one after another from C# NUnit?
We can run Selenium tests in multiple browsers one after another from C# NUnit. This is done with the help of the Test Fixture concept. This is an attribute that identifies a class, step up and tear down methods.
There are some rules to be followed for a class to have a fixture −
It should not be of type abstract.
There should be a default constructor for a non−parameterized fixture.
The parameterized fixture should have a constructor.
It can be publicly exported.
Example
using NUnit.Framework;
using OpenQA.Selenium
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using System;
namespace NUnitTestProject1{
//Test Fixture declaration
[TestFixture(typeof(FirefoxDriver))]
[TestFixture(typeof(ChromeDriver))]
public class MultipleBrowser<TWebDriver> where
TWebDriver : IWebDriver, new(){
private IWebDriver driver;
[SetUp]
public void CreateDriver(){
this.driver = new TWebDriver();
}
[Test]
public void Test1(){
//launching URL.
driver.Navigate()
.GoToUrl("https://www.tutorialspoint.com/index.htm");
}
[TearDown]
public void close_Browser(){
driver.Quit();
}
}
}Advertisements