I'm looking for a little bit of help in understanding NUnit when used with C# and Selenium in visual studio.
I've built a suite of tests where a lot of it has been cobbled together via self-learning and youtube videos.
The project used to just need to be a series of regression tests that run against a single site in multiple browsers.
I've achieved this and am quite happy with the results.
What I want to do now is expand this a little further
The product I have been testing against is a website that is reskinned for different clients where 99% of the content is the same.
Instead of just creating multiple projects/solutions in visual studio, I'd like to do something a bit more dynamic to cover regression against the different skins.
What i would like to do, is parametrize the testcase/browser/url combinations e.g.
- TestCase1/Chrome/Site1
- TestCase1/Chrome/Site2
- TestCase1/Edge/Site1
- TestCase1/Edge/Site2 etc.
I've been able to get the Visual Studio Test Explorer to recognize the parameter, but for some reason, it seems to produce un unexpected result e.g.
- TestCase1/Site1
- testcase1/Chrome
- TestCase1/Site2
- TestCase1/Edge/etc.
I've seen forums where they discuss doing something similar to what I'm talking about here by using NUnit parameters but have not been able to produce the desired result.
I thought it would have simply been a case of just adding another NUnit pram and passing it as I did before. Here is a slimmed down version of the code I'm currently using:
namespace AutomationStuffs.SmokeTests
{
[TestFixture]
public class LoginTests : TestBase
{
[Test]
[TestCaseSource(typeof(TestBase), "BrowserToRunWith")]
public void FirstTimeLogin(String BrowserName, String Url)
{
//Browser Driver Setup For test
Setup(BrowserName);
//...DO SOME TESTING THINGS
}
}
}
namespace AutomationStuffs.Utilities
{
public class TestBase
{
public static IWebDriver driver;
public void Setup(String BrowserName)
{
Driver.Intialize(BrowserName);
//... DO SOME SETUP STUFF
LoginPage.GoTo();
//..I DO SOME LOGIN SETUP HERE
}
public static IEnumerable<String> BrowserToRunWith()
{
String[] browsers = BrowsersList.theBrowserList.Split(',');
foreach (String b in browsers)
{
yield return b;
}
}
}
}
namespace AutomationStuffs.Pages
{
public class LoginPage
{
public static void GoTo()
{
Driver.Instance.Navigate().GoToUrl(Driver.baseURL);
}
}
}
namespace AutomationStuffs.Selenium
{
public class Driver
{
public static IWebDriver Instance { get; set; }
public static string baseURL
{
get
{
string url = System.Configuration.ConfigurationManager.AppSettings["BaseUrl"];
return url;
}
}
public static string chromeDriver
{
get
{
string driver = System.Configuration.ConfigurationManager.AppSettings["ChromeDriver"];
driver = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, driver);
return driver;
}
}
public static string ieDriver
{
get
{
string driver = System.Configuration.ConfigurationManager.AppSettings["IEDriver"];
driver = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, driver);
return driver;
}
}
public static string edgeDriver
{
get
{
string driver = System.Configuration.ConfigurationManager.AppSettings["EdgeDriver"];
driver = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, driver);
return driver;
}
}
public static void Intialize(String BrowserName)
{
String DRIVER_PATH = chromeDriver;
String DRIVER_PATH_IEFF = ieDriver;
String DRIVER_PATH_EDGE = edgeDriver;
var optionsChrome = new ChromeOptions();
optionsChrome.AddArgument("start-maximized");
optionsChrome.AddArgument("no-sandbox");
var optionsIe = new InternetExplorerOptions();
if (BrowserName.Equals("ie"))
{
Instance = new InternetExplorerDriver(DRIVER_PATH_IEFF);
Instance.Manage().Window.Maximize();
}
else if (BrowserName.Equals("firefox"))
{
Instance = new FirefoxDriver();
Instance.Manage().Window.Maximize();
}
else if (BrowserName.Equals("edge"))
{
Instance = new EdgeDriver(DRIVER_PATH_EDGE);
Instance.Manage().Window.Maximize();
}
else
{
Instance = new ChromeDriver(DRIVER_PATH, optionsChrome);
}
}
}
}
Here is what I thought I would have to do (And obviously just duplicate and adapt the underlying methods where appropriate):
namespace AutomationStuffs.SmokeTests
{
[TestFixture]
//[Parallelizable]
public class LoginTests : TestBase
{
[Test]
[TestCaseSource(typeof(TestBase), "BrowserToRunWith")]
[TestCaseSource(typeof(TestBase), "URLToRunWith")]
public void FirstTimeLogin(String BrowserName, String Url)
{
//Browser Driver Setup For test
Setup(BrowserName);
Assert.IsTrue(FiveComponentsAndDocStorePage.AssertOnThePage());
}
}
}