I'm learning Selenium/Webdriver
NUnit
testing and run into a problem when executing a test:
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using NUnit.Framework;
class NUnitTest
{
IWebDriver driver;
FirefoxOptions options;
[SetUp]
public void Initialize()
{
driver = new FirefoxDriver();
}
[Test]
public void OpenAppTest()
{
driver.Navigate().GoToUrl("http:/www.demoqa.com");
}
[TearDown]
public void EndTEst()
{
driver.Quit();
}
}
When running test, I'm getting an exception:
OpenQA.Selenium.WebDriverException: Cannot start the driver service on localhost TearDown: System.NUllReferenceException: Object reference not set to an instance of an object
I have no clue how to fix it.
However, the following approach works:
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using Microsoft.VisualStudio.TestTools.UnitTesting;
public class UnitTest1
{
IWebDriver driver;
[TestMethod]
public void VerifyTitle()
{
//Write Actual Test
string title = driver.Title;
Assert.AreEqual(title, "Demoqa | Just another WordPress site");
}
[TestInitialize]
public void Setup()
{
//start browser and open url
driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http:/www.demoqa.com");
}
[TestCleanup]
public void CleanupTest()
{
//close browser
driver.Quit();
}
}
Here, I'm using the same approach to start the webdriver
as in the failing example.
The only difference is that the failing example is using NUnit.Framework
and the correct one is using Microsoft.VisualStudio.TestTools.UnitTesting
I'm not sure what is wrong with the second approach?