I need the help with combining multiple browser test fixtures into my framework. My goal is to run test on multiple browsers one after another by defining type of testFixture: ChromeDriver, InternetExplorerDriver etc.
I have followed one of tutorials on Pluralsight to build my framework. Now this look like this:
TestClass: LoginTest
[TestFixture]
public class LoginTest : PortalTest
{
[Test]
public void LoginUser()
{
Assert.IsTrue(HomePage.IsAt, "Failed to login. ");
}
}
Next, PortalTest base class:
public class PortalTest
{
[SetUp]
public void Init()
{
Driver.Initialize();
LoginPage.Goto();
LoginPage.LoginAs("user").WithPassword("pass").Login();
}
[TearDown]
public void CleanUp()
{
Driver.Close();
}
}
LoginPage with GoTo():
public class LoginPage
{
public static void Goto()
{
//var wait = new WebDriverWait(Driver.Instance, TimeSpan.FromSeconds(10));
//wait.Until(d => d.SwitchTo().ActiveElement().GetAttribute("id") == "UserName");
Driver.Instance.Navigate().GoToUrl(Driver.BaseAddress + "Account/LogOn?ReturnUrl=%2FHome");
if (Driver.Instance.Title != "Login")
{
throw new Exception("Not on Login page");
}
}
And my Driver class which initializes FirefoxDriver:
public class Driver : TestBase
{
public static IWebDriver Instance { get; set; }
public static void Initialize()
{
Instance = new FirefoxDriver();
// wait 5 sec
Instance.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
}
As you can see Driver class extends TestBase. This one defined multiple browser cases and returns the appropriate driver.
I had few attempts but with no luck. Related posts I'm basing on: https://stackoverflow.com/a/7854838/2920121
http://makit.net/testing-aspdotnet-mvc-application-with-selenium-and-nunit