Beispiel #1
0
        public static IServiceProvider GetServiceProvider(bool headless)
        {
            // Force local Browser running for local file
            IWebDriverConfiguration driverConfig =
                WebDriverConfigurationBuilder.Start()
                .WithHeadless(headless)
                .WithBrowser(Browser.Firefox)
                .WithWindowSize(WindowSize.Hd)
                .Build();

            IWebDriverManager driverManager = ServiceCollectionFactory.GetDefaultServiceCollection(true, driverConfig)
                                              .BuildServiceProvider()
                                              .GetRequiredService <IWebDriverManager>();

            IServiceCollection serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton <IWebDriverManager>(driverManager);
            serviceCollection.AddSingleton <IWebDriver>(driverManager.Get());

            serviceCollection.Scan(scan => scan
                                   .FromAssemblyOf <PageTests>()
                                   .AddClasses()
                                   .UsingRegistrationStrategy(RegistrationStrategy.Skip)
                                   .AsSelf()
                                   .WithSingletonLifetime());

            return(serviceCollection.BuildServiceProvider());
        }
Beispiel #2
0
        public void BuilderJsonConfigStringProducesCorrectSerialisation(
            Browser browser,
            WindowSize windowSize,
            bool headless,
            bool isLocal,
            string gridUri,
            PlatformType platformType)
        {
            // Arrange
            var webDriverConfigurationBuilder = WebDriverConfigurationBuilder.Start()
                                                .WithBrowser(browser)
                                                .WithHeadless(headless)
                                                .WithWindowSize(windowSize)
                                                .WithIsLocal(isLocal)
                                                .WithGridUri(new Uri(gridUri))
                                                .WithPlatformType(platformType);
            WebDriverConfiguration expectedConfig = webDriverConfigurationBuilder.Build();
            string requestedJson = expectedConfig.SerializeToJson();


            string jsonConfigString = webDriverConfigurationBuilder.GetJsonConfigString();

            // Act
            WebDriverConfiguration returnedConfig             = WebDriverConfiguration.DeserializeFromJson(requestedJson);
            WebDriverConfiguration configFromJsonConfigString = WebDriverConfiguration.DeserializeFromJson(jsonConfigString);

            // Assert
            configFromJsonConfigString.Should().BeEquivalentTo(returnedConfig);
        }
Beispiel #3
0
        public void LocalWebDriverFactoryWorks(Browser browser, BrowserVisibility browserVisibility)
        {
            IWebDriverConfiguration configuration = WebDriverConfigurationBuilder.Start()
                                                    .WithBrowser(browser)
                                                    .WithHeadless(browserVisibility == BrowserVisibility.Headless)
                                                    .Build();

            TestContext.WriteLine($"Configuration = {JsonConvert.SerializeObject(configuration, sizeJsonConverter)}");
            Driver = WebDriverFactory.GetWebDriver(configuration);
            Assertions.AssertThatPageCanBeLoaded(Driver);
        }
Beispiel #4
0
        public void RequestingUnsupportedHeadlessBrowserThrowsInformativeException(Browser browser)
        {
            IWebDriverConfiguration configuration = WebDriverConfigurationBuilder.Start()
                                                    .WithBrowser(browser)
                                                    .RunHeadless()
                                                    .Build();

            void Act() => WebDriverFactory.GetWebDriver(configuration);

            Assertions.AssertThatRequestingAnUnsupportedHeadlessBrowserThrowsCorrectException(Act, browser);
        }
Beispiel #5
0
        public void RequestingUnsupportedWebDriverThrowsInformativeException(Browser browser)
        {
            IWebDriverConfiguration configuration = WebDriverConfigurationBuilder.Start()
                                                    .WithBrowser(browser)
                                                    .Build();

            TestContext.WriteLine($"Configuration = {JsonConvert.SerializeObject(configuration, sizeJsonConverter)}");
            void Act() => WebDriverFactory.GetWebDriver(configuration);

            Assertions.AssertThatRequestingAnUnsupportedBrowserThrowsCorrectException(Act, browser, thisPlatform);
        }
Beispiel #6
0
        public void ConfigurationCorrectlySerialisesAndDeserialises(int width, int height)
        {
            // Arrange
            WebDriverConfiguration testConfig = WebDriverConfigurationBuilder.Start().WithCustomSize(new Size(width, height)).Build();

            // Act
            string serialisedConfig = testConfig.SerializeToJson();
            WebDriverConfiguration deserialisedConfig = WebDriverConfiguration.DeserializeFromJson(serialisedConfig);

            // Assert
            deserialisedConfig.Should().BeEquivalentTo(testConfig);
        }
Beispiel #7
0
        public void CustomSizeBrowserIsOfRequestedSize(WindowSize windowSize, int expectedWidth, int expectedHeight)
        {
            WebDriverConfiguration configuration = WebDriverConfigurationBuilder.Start()
                                                   .WithBrowser(Browser.Firefox)
                                                   .RunHeadless()
                                                   .WithCustomSize(new Size(expectedWidth, expectedHeight))
                                                   .Build();

            TestContext.WriteLine($"Configuration = {JsonConvert.SerializeObject(configuration, sizeJsonConverter)}");
            Driver = WebDriverFactory.GetWebDriver(configuration);
            Assertions.AssertThatBrowserWindowSizeIsCorrect(Driver, expectedWidth, expectedHeight);
        }
Beispiel #8
0
        public void CustomSizeConfigurationDeSerialisesWithCorrectWidthAndHeight(int width, int height)
        {
            // Arrange
            var webDriverConfigurationBuilder     = WebDriverConfigurationBuilder.Start().WithCustomSize(new Size(width, height));
            WebDriverConfiguration expectedConfig = webDriverConfigurationBuilder.Build();
            string requestedJson = expectedConfig.SerializeToJson();

            // Act
            WebDriverConfiguration returnedConfig = WebDriverConfiguration.DeserializeFromJson(requestedJson);

            // Assert
            returnedConfig.Should().BeEquivalentTo(expectedConfig);
        }
Beispiel #9
0
        private void CompareJsonEquivalence(WebDriverConfigurationBuilder webDriverConfigurationBuilder)
        {
            // Arrange
            string formattedString = webDriverConfigurationBuilder.GetJsonConfigString();
            WebDriverConfiguration expectedConfig = webDriverConfigurationBuilder.Build();
            string requestedJson = expectedConfig.SerializeToJson();

            // Act
            WebDriverConfiguration returnedConfig            = WebDriverConfiguration.DeserializeFromJson(requestedJson);
            WebDriverConfiguration configFromFormattedString =
                WebDriverConfiguration.DeserializeFromJson(formattedString);

            // Assert
            returnedConfig.Should().BeEquivalentTo(configFromFormattedString);
        }
Beispiel #10
0
 public void JsonNetSerialisationIsEquivalentToBuilderGetJsonConfigString(
     Browser browser,
     WindowSize windowSize,
     bool headless,
     bool isLocal,
     string gridUri,
     PlatformType platformType)
 {
     CompareJsonEquivalence(WebDriverConfigurationBuilder.Start()
                            .WithBrowser(browser)
                            .WithHeadless(headless)
                            .WithWindowSize(windowSize)
                            .WithIsLocal(isLocal)
                            .WithGridUri(new Uri(gridUri))
                            .WithPlatformType(platformType));
 }
Beispiel #11
0
        public void CustomSizeConfigurationSerialisesWithCorrectWidthAndHeight(int width, int height)
        {
            // Arrange
            WebDriverConfiguration testedConfig = WebDriverConfigurationBuilder.Start().WithCustomSize(new Size(width, height)).Build();

            // Act
            string actualJson = testedConfig.SerializeToJson();

            //Assert
            using (new AssertionScope())
            {
                actualJson.Should().Contain("\"PlatformType\":\"Windows\"");
                actualJson.Should().Contain("\"WindowSize\":\"Defined\"");
                actualJson.Should().Contain($"\"WindowDefinedSize\":{{\"width\":{width},\"height\":{height}}}");
                actualJson.Should().Contain("\"GridUri\":\"http://localhost:4444\"");
            }
        }
Beispiel #12
0
        public void RemoteWebDriverFactoryWorks(
            PlatformType platformType,
            Browser browser,
            BrowserVisibility browserVisibility = BrowserVisibility.OnScreen)
        {
            IWebDriverConfiguration configuration = WebDriverConfigurationBuilder.Start()
                                                    .WithBrowser(browser)
                                                    .WithHeadless(browserVisibility == BrowserVisibility.Headless)
                                                    .RunRemotelyOn(gridUrl)
                                                    .WithPlatformType(platformType)
                                                    .Build();

            TestContext.WriteLine($"Configuration = {JsonConvert.SerializeObject(configuration, sizeJsonConverter)}");
            Driver = WebDriverFactory.GetWebDriver(configuration);
            Assertions.AssertThatPageCanBeLoaded(Driver);
            Driver.IsRunningHeadless().Should()
            .Be(browserVisibility == BrowserVisibility.Headless,
                $"{browserVisibility.ToString()} was requested");
        }
Beispiel #13
0
        public static IServiceCollection GetDefaultServiceCollection(
            IWebDriverConfiguration driverConfig,
            DriverPath driverPath)
        {
            IServiceCollection services = new ServiceCollection();

            services.AddSingleton <IDriverOptionsFactory, DefaultDriverOptionsFactory>();
            services.AddSingleton <IWebDriverReSizer, WebDriverReSizer>();

            if (driverPath != null)
            {
                services.AddSingleton <DriverPath>(driverPath);
            }

            services.AddSingleton(driverConfig ?? WebDriverConfigurationBuilder.Start().Build());
            services.AddSingleton <ILocalWebDriverFactory, DefaultLocalWebDriverFactory>();
            services.AddSingleton <IRemoteWebDriverFactory, DefaultRemoteWebDriverFactory>();

            services.AddSingleton <IWebDriverFactory, DefaultWebDriverFactory>();
            services.AddSingleton <IWebDriverManager, WebDriverManager>();

            return(services);
        }
Beispiel #14
0
 private static IWebDriverConfiguration GetDefaultWebDriverConfigurationFromUri(Uri gridUri)
 {
     return(WebDriverConfigurationBuilder.Start().WithGridUri(gridUri).Build());
 }
Beispiel #15
0
 public void JsonNetSerialisationIsEquivalentToBuilderGetJsonConfigStringUndefinedSizeConfiguration(WindowSize windowSize)
 {
     CompareJsonEquivalence(WebDriverConfigurationBuilder.Start().WithWindowSize(windowSize));
 }
Beispiel #16
0
 public void JsonNetSerialisationIsEquivalentToBuilderGetJsonConfigStringCustomSizeConfiguration(int width, int height)
 {
     CompareJsonEquivalence(WebDriverConfigurationBuilder.Start().WithCustomSize(new Size(width, height)));
 }