Пример #1
0
        public void Can_create_webdriver_then_connect_to_Google_and_read_the_window_title()
        {
            // Arrange
            var    driverFactory = GetWebDriverFactory.FromConfiguration();
            string result;

            // Act
            using (var webDriver = driverFactory.CreateWebDriver(scenarioName: ConnectToGoogleScenarioName))
            {
                webDriver.Navigate().GoToUrl(GoogleHomeUrl);
                var wait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(TimeoutSecondsToConnectToGoogleHomePage))
                           .Until(ExpectedConditions.TitleContains(Google));

                result = webDriver.Title;

                // Assert
                var statusDriver = webDriver as ICanReceiveScenarioOutcome;

                try { Assert.That(result, Contains.Substring(Google)); }
                catch (AssertionException)
                {
                    if (statusDriver != null)
                    {
                        statusDriver.MarkScenarioAsFailure();
                    }
                    throw;
                }

                if (statusDriver != null)
                {
                    statusDriver.MarkScenarioAsSuccess();
                }
            }
        }
        public void GetIdentification_integration_creates_useful_version_numbers(string platform, string browserName, string browserVersion)
        {
            // Arrange
            var scenarioName = nameof(GetIdentification_integration_creates_useful_version_numbers);
            var caps         = GetCapabilities(platform, browserName, browserVersion);
            var factory      = GetWebDriverFactory.FromConfiguration();

            BrowserIdentification result;

            // Act
            using (var webDriver = factory.CreateWebDriver(caps, scenarioName: scenarioName))
            {
                result = webDriver.GetIdentification();

                // This line is required because remote web driver providers may consider the test an error
                // if we never sent any commands to the web driver.  Otherwise it's irrelevant.
                webDriver.Navigate().GoToUrl("http://google.com/");

                SendScenarioStatus(webDriver, IsUsefulVersion(result.Version));
            }

            // Assert
            var isUsable = IsUsefulVersion(result.Version);

            Assert.That(isUsable, Is.True, "Browser version was not useful:{0}", result);
        }
        public static void UseAgiilWebDriverFromConfiguration(this IIntegrationConfigBuilder builder,
                                                              string name = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.ServiceRegistrations.PerTestRun.Add(b => {
                b.RegisterFactory(() => GetWebDriverFactory.FromConfiguration())
                .AsOwnType()
                .WithName(name);
            });

            builder.ServiceRegistrations.PerScenario.Add(b => {
                b.RegisterDynamicFactory(GetLazyWebDriverTracker(name))
                .As <ITracksWebDriverCreation>()
                .WithName(name);

                b.RegisterDynamicFactory(resolver => resolver.Resolve <ITracksWebDriverCreation>().GetWebDriver())
                .AsOwnType()
                .WithName(name);
            });

            builder.AfterScenario.Add(MarkWebDriverWithOutcome(name));
        }
        public void GetIdentification_integration_successfully_identifies_supported_web_drivers(string platform,
                                                                                                string browserName,
                                                                                                string browserVersion)
        {
            // Arrange
            var scenarioName = nameof(GetIdentification_integration_successfully_identifies_supported_web_drivers);
            var caps         = GetCapabilities(platform, browserName, browserVersion);
            var factory      = GetWebDriverFactory.FromConfiguration();

            BrowserIdentification result;

            // Act
            using (var webDriver = factory.CreateWebDriver(caps, scenarioName: scenarioName))
            {
                result = webDriver.GetIdentification();

                // This line is required because remote web driver providers may consider the test an error
                // if we never sent any commands to the web driver.  Otherwise it's irrelevant.
                webDriver.Navigate().GoToUrl("http://google.com/");

                SendScenarioStatus(webDriver, !(result.Version is UnrecognisedVersion));
            }

            // Assert
            Assert.That(result.Version,
                        Is.Not.InstanceOf <UnrecognisedVersion>(),
                        "Browser was not recognised:{0}",
                        result);
        }