简体   繁体   中英

Reuse browser instance across multiple tests in same class using FluentAutomation with MSTests

I am using FluentAutomation with MSTests. I need to be able to reuse the browser instance across multiple test methods in the same class. For example, the constructor or TestInitialize method will login to a url, then all the subsequent Test methods in the class will need to use the same logged in session and browser instance.

Tried using the FluentSession.EnableStickySession(); but that didn't work, and 2nd method in execution complains that IEDriver is already being used by another process.

Any ideas how to resolve this?

Here's the sample code for the scenario:

[TestClass]
  public class DummyTests : FluentTest
  {
    public DummyTests()
    {
      SeleniumWebDriver.Bootstrap(SeleniumWebDriver.Browser.InternetExplorer);
      I.Open(@"http://google.com");
      FluentSession.EnableStickySession();
    }

    [TestMethod]
    public void First()
    {
      I.Wait(2)
        .Enter("NBA").In("input#lst-ib.gsfi")
        .Click("button[type='submit']");

    }

    [TestMethod]
    public void Second()
    {
      I.Wait(2)
        .Enter("MLB").In("input#lst-ib.gsfi")
        .Click("button[type='submit']");
    }
  }

Call EnableStickySession before any browsers are created. Most users do it in a common init/TestInitialize/ClassInitialize.

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