samedi 30 mai 2015

Call Method through two classes in Selenium C#

This is probably a stupid question but I haven't found an answer that leads me to a solution yet

Say I have a testmethod to verify the functionality of a login portal. It's in TestClassA. I want to run that method in TestClassB's TestInitialize method so I can reliably have selenium start on a blank slate for testing features past that login portal.

Here's the test code in question

using Test_Login_Elements;
using Dashboard;

namespace Test_Dashboard_Elements
{
[TestClass]
public class DashboardTests
{
    IWebDriver _driver;
    DashboardElements dash;

    [TestInitialize]
    public void Test_Setup()
    {
        dash = new DashboardElements(_driver);
        _driver = new FirefoxDriver();
        _driver.Navigate().GoToUrl("exampleurl.com/login");
        dash.Login();
    }
}

Which calls an instance of DashboardElements and passes the selenium webdriver, then calls the login method from DashboardElements (DashboardElements has LoginPage as a reference, by the way)

    public void Login()
    {
        LoginPage login = new LoginPage(_driver);
        login.sendUserName("example_user");
        login.sendPassword("example_password");
        login.submit();
    }

This returns Message: Initialization method Test_Dashboard_Elements.DashboardTests.Test_Setup threw exception. System.ArgumentNullException: System.ArgumentNullException: searchContext may not be null Parameter name: searchContext

I feel like this has to do with passing _driver twice, once through the instance inside the TestInitialize and again in the DashboardElements login method, but I have no idea how else to do this.

Aucun commentaire:

Enregistrer un commentaire