0

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']");
    }
  }
Vin
  • 6,115
  • 4
  • 41
  • 55
  • This is pretty dangarous as MsTest doesn't guarantee execution order, nor does it preclude parallel test execution. – jessehouwing Apr 01 '15 at 20:12
  • Not really, using test settings we can limit execution to 1 at a time. The order also would not matter as long as the test cases are independent of one another and have no dependency on another one being run first – Vin Apr 01 '15 at 23:26

1 Answers1

1

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

stirno
  • 598
  • 4
  • 10
  • That's it. I called it after the bootstrap, which I think was the problem. Thanks for pointing out. – Vin Apr 02 '15 at 16:04