简体   繁体   中英

ClassInitialize not working Selenium C#

I try to make initial for each class eq
1. open new browser window with link X for first class1 , make all tests then close browser,
2. open new browser window with link X for second class2 , make all tests then close browser,

When use ClassInitialize it is not openning url at the beginning

public static void Initialize(){
_webDriver.Navigate().GoToUrl(url);
}


     [TestClass]
public class TestBase
{
    [ClassInitialize]
    public void Initialize()
    {
        Browser.Initialize();
        Pages.Login.Login();
    }

    [ClassCleanup]
    public void Cleanup()
    {
        Browser.Close();
        Browser.Quit();
    }

I don't know what does really mean 'TestContext context', What should I put in here? Mabye here is a problem

[ClassInitialize()]
        public static void ClassInit(**TestContext context**)
        {
            MessageBox.Show("ClassInit " **+ context.TestName**);
        }

When I make TestInitialize it's working

 public class TestBase
{

    [TestInitialize]
    public void InitializeEach()
    {
        Browser.Initialize();
    }
    [TestCleanup]
    public void CleanupTestEach()
    {
        Browser.Close();
        Browser.Quit();

    }
}

TestClass1

[TestClass]
public class ValidUserCanSuccesfullyLogIn : TestBase 
{

    [TestMethod]
    public void RunTest()
    {

       PagesTest.Login.GoTo();
       PagesTest.Login.Login("login", "pass");
       Assert.IsTrue(PagesTest.MyMembership.IsAt(), " A valid user was not able to successfully login");

    }

}

As said in msdn documentation ClassInitialize method must have this signature

public static void ClassInit(TestContext context)

You don't call this function by yourself, and in your case, you don't have to do anything with context parameter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM