In this part we will use NUnit framework with Selenium C# in Visual Studio to execute multiple test methods along with many other features like
Initializing the Test method – Before execution
Cleaning up the Test method — After execution
NUnit will also give us many other assertion features which will be helpful while trying to assert two objects types, some of the methods are shown below
Splitting our code
In this post, we are going to split the code discussed in our last post to three different methods like
Initialize() — Setup
ExecuteTest() – Test
CleanUp – Teardown
Here is the complete explanation of the above discussion in the video
Here is the complete code of the above video
class Program
{
//Create Global reference for our browser via WebDriver
IWebDriver driver = new ChromeDriver();
[SetUp]
public void Initialize()
{
//Navigate to Execute automation demo page
driver.Navigate().GoToUrl("http://executeautomation.com/demosite/index.html?UserName=&Password=&Login=Login");
Console.WriteLine("Opened URL");
}
[Test]
public void ExecuteTest()
{
//Find the Element
IWebElement element = driver.FindElement(By.Id("q"));
//Perform Ops
element.SendKeys("executeautomation");
Console.WriteLine("Executed Test");
}
[Test]
public void NextTest()
{
Console.WriteLine("Next method");
}
[TearDown]
public void CleanUp()
{
driver.Close();
Console.WriteLine("Closed the browser");
}
}
Thanks for watching the video and reading the post!!
Please leave your comments and let me know if there is anything need to be improved in the post!!!
Thanks,
Karthik KK