FluentAutomation icon indicating copy to clipboard operation
FluentAutomation copied to clipboard

Support providing your own webdriver instance, parallell instances break

Open andrejohansson opened this issue 9 years ago • 1 comments

It's unclear today how the bootstrap method sets up webdrivers, it would be good to be able to provide your own webdriver instance in many cases (newer drivers, custom drivers, parallelll tests).

We have the following setup:

  1. We have some tests
  2. We run nunit 3 because it supports parallell execution
  3. We use browserstack so all our tests are running towards clean instances

We have a base fixture like this:

    [TestFixture("Edge", "12.0", "Windows", "10", "TestData.json")]
    [TestFixture("IE", "11.0", "Windows", "8.1", "TestData.json")]
    [TestFixture("Chrome", "47.0", "Windows", "8.1", "TestData.json")]
    [TestFixture("Firefox", "43.0", "Windows", "8.1", "TestData.json")]
    [Parallelizable(ParallelScope.Fixtures)]
    public class BaseTestFixture : FluentTest
    {
        public string Browser { get; set; }
        public string BrowserVersion { get; set; }
        public string Os { get; set; }
        public string OsVersion { get; set; }
        public string TestDataPath { get; set; }

        public Dictionary<string, object> Capabilities { get; set; }

        public BaseTestFixture(string browser, string browserVersion, string os, string osVersion, string testDataPath)
        {
            Browser = browser;
            BrowserVersion = browserVersion;
            Os = os;
            OsVersion = osVersion;
            TestDataPath = Path.Combine(@".\Data", testDataPath);
        }

        [SetUp]
        public void Init()
        {
            ReadTestData();
            Capabilities = GetCapabilitites();

            SeleniumWebDriver.Bootstrap(
                BrowserStack.Uri,
                Capabilities);
            LogCapabilities();

            // Setup settings
            FluentSettings.Current.ExpectIsAssert = true;

            // Navigate to root page to initialize the provider
            I.Open(new Uri(string.Format(TestHelper.BaseUrl, TestData.customer.domain.Value)));

            // Show session state
            LogCookies();
        }

...

I expected each test having it's own driver using this, but it doesn't seem like it since fluentautomaiton is using the TinyIoCContainer.

Would it be possible to have some initialization like this and for fluentautomation to not use any static state sharing between instances?

SeleniumWebDriver.Bootstrap(new MyDriver(Capabilities));

andrejohansson avatar Jan 18 '16 12:01 andrejohansson

Researching a bit further I checked the bootstrap code and there you seems to be generating new driver instances per browser name (depending on which of the bootstap overloads you use).

It would be good to be able to specify your own identifier to support parallell runs. For example: myContextBasedOnParallellRun could be created from a combination of browser, versions, and os to enable parallell remote runs using nunit.

myContextBasedOnParallellRun = "FF-43-WIN-8"; // build this from the nunit attributes or some other parallell metadata instead of just browser name
container.Register<IWebDriver>((c, f) => new EnhancedRemoteWebDriver(BrowserStack.Uri, desiredCapabilities, defaultCommandTimeout), myContextBasedOnParallellRun);

andrejohansson avatar Jan 18 '16 15:01 andrejohansson