I built a simple NUnit Framework to run a Selenium WebDriver C# Test in Visual Studio 2015.
I've installed the NUnit v3.12, Selenium WebDriver v3.141, NUnit3TestAdapter v3.17 extensions.
If I'm unable to download the Browser Driver why am I'm getting this Error:
******------ Discover test started ------
An exception occurred while test discoverer 'NUnit3TestDiscoverer' was loading tests. Exception: Object reference not set to an instance of an object.
========== Discover test finished: 0 found (0:00:03.1151069) ==========******
Below code trying to navigate to web page and login to application:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Edge;
using OpenQA.Selenium.Firefox;
namespace eMPWR_TEST_AUTOMATION
{
[TestFixture] // This is your Test Suite containing all you below TESTS ([Test])
public class eMPWR_SmokeTests
{
private IWebDriver driver;
private StringBuilder verificationErrors;
private String baseURL;
private bool acceptNextAlert = true;
[SetUp]
public void SetUpTests()
{
driver = new FirefoxDriver();
baseURL = "https://va--fasaoadev.my.salesforce.com";
verificationErrors = new StringBuilder();
}
[TearDown]
public void TearDownTests()
{
try
{
driver.Quit();
}
catch (Exception)
{
//ignore errors if unable to close the browser
}
Assert.AreEqual("", verificationErrors.ToString());
}
[TestCase("UserName1", "Password1")] // Using 3 scenarios instead of below variables
[TestCase("UserName2", "Password2")]
[TestCase("UserName3", "Password3")]
public void eMPWR_Login(string UserName, string Password)
{
//String UserName = "UserName1";
//String Password = "Password1";
String Url = "www.login.Salesforce.com";
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl(Url);
driver.FindElement(By.Id("UserName")).SendKeys(UserName);
driver.FindElement(By.Id("Password")).SendKeys(Password);
driver.FindElement(By.Id("Login")).Click();
String ExpectedData = "Salesforce";
String ActualData = "Sales Force";
Assert.That(ExpectedData, Is.EqualTo(ActualData)); // from NUnit Framework
driver.Close();
}
[Test]
public void eMPWR_SearchSSN()
{
string URL = "https://va--fasaoadev.my.salesforce.com";
string FN = "John";
string LN = "Doe";
string Email = "[email protected]";
string PWD = "F00tB@11";
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl(URL);
driver.FindElement(By.CssSelector("input.submitbutn")).Click();
driver.FindElement(By.Id("ctl00_MainContent.txtFirstName")).Clear();
driver.FindElement(By.Id("ctl00_MainContent.txtFirstName")).SendKeys(FN);
driver.FindElement(By.Id("ctl00_MainContent.txtLastName")).Clear();
driver.FindElement(By.Id("ctl00_MainContent.txtLastName")).SendKeys(LN);
driver.FindElement(By.Id("ctl00_MainContent.txtEmail")).Clear();
driver.FindElement(By.Id("ctl00_MainContent.txtEmail")).SendKeys(Email);
driver.FindElement(By.Id("ctl00_MainContent.txtVerifyPassword")).Clear();
driver.FindElement(By.Id("ctl00_MainContent.txtVerifyPassword")).SendKeys(PWD);
driver.FindElement(By.CssSelector("input.submitbutn")).Click();
Assert.AreEqual("Login Successful",
driver.FindElement(By.Id("ctl00_MainContentlblTransactionResult")).Text);
}
}
}
Taken from https://www.stevefenton.co.uk/2018/02/nunit-exception-occurred-test-discoverer-loading-tests/:
It worked for me!