Exemplo n.º 1
0
        public async Task BrowserIsAlwaysDisposed()
        {
            var(driver, exceptionInfo) = WebDriverFactory.CreateAndInitialize(fakeConfig, (cfg, x) => { });
            using (driver)
            {
                var i = 1;
            }

            fakeWebDriver.Received().Dispose();
        }
Exemplo n.º 2
0
        public void SetUp()
        {
            var log  = this.CreateLogger();
            var args = new NameValueCollection();

            fakeWebDriver = Substitute.For <IWebDriver>();
            args.Add("selenium.baseUrl", $"http://localhost:{TcpPort.NextFreePort()}");
            args.Add("webdriver.browser.type", "fake-webdriver");
            fakeConfig = WebDriver.Configure(cfg => cfg.WithDefaultOptions().Providers(x => args[x]), log).Build();
            WebDriverFactory.AddDriverBuilder("fake-webdriver", c => fakeWebDriver);
        }
        public async Task ImportsCookiesForDomain()
        {
            string actualCookieValue = null;

            var expectedCookieValue = "Bar";
            var url             = $"http://localhost:{TcpPort.NextFreePort()}";
            var cookieContainer = new CookieContainer();
            var log             = this.CreateLogger();

            var args = new NameValueCollection();

            args.Add("selenium.baseUrl", url);
            var browserConfig = WebDriver
                                .Configure(cfg => cfg.WithDefaultOptions().Providers(x => args[x]), log)
                                .Build();

            using (WebHost.Start(
                       url,
                       router => router
                       .MapGet(
                           "",
                           (req, res, data) =>
            {
                res.Cookies.Append("Foo", expectedCookieValue);
                res.ContentType = "text/html";
                return(res.WriteAsync(""));
            })
                       .MapGet(
                           "checkcookie",
                           (req, res, data) =>
            {
                actualCookieValue = req.Cookies["Foo"];
                return(res.WriteAsync(""));
            })))
                using (var cookieHandler = new HttpClientHandler {
                    CookieContainer = cookieContainer,
                    UseCookies = true,
                    AllowAutoRedirect = false
                })
                    using (var httpClient = new HttpClient(cookieHandler)
                    {
                        BaseAddress = new Uri(url)
                    })
                        using (var driver = WebDriverFactory.Create(browserConfig))
                        {
                            driver.Navigate().GoToUrl(url);
                            driver.ImportCookies(cookieContainer, new Uri(url));
                            driver.Navigate().GoToUrl(url + "/checkcookie");
                            actualCookieValue.Should().Be(expectedCookieValue);
                        }
        }
        public async Task CreatesAChromeDriver()
        {
            var args = new NameValueCollection();

            args.Add("selenium.baseUrl", $"http://localhost:{TcpPort.NextFreePort()}");
            var browserConfig = WebDriver
                                .Configure(cfg => cfg.WithDefaultOptions().Providers(x => args[x]), log)
                                .Build();

            using (var driver = WebDriverFactory.Create(browserConfig))
            {
                driver.Should().BeOfType <ChromeDriver>();
            }
        }
        public async Task SetsBrowserSize()
        {
            var args = new NameValueCollection();

            args.Add("webdriver.browser.size", "1280,1024");
            args.Add("selenium.baseUrl", $"http://localhost:{TcpPort.NextFreePort()}");
            var browserConfig = WebDriver
                                .Configure(cfg => cfg.WithDefaultOptions().Providers(x => args[x]), log)
                                .Build();

            using (var driver = WebDriverFactory.Create(browserConfig))
            {
                driver.Manage().Window.Size.Should().Be(new Size(1280, 1024));
            }
        }
        public async Task SavesFileToDirectory()
        {
            var log  = this.CreateLogger();
            var url  = $"http://*****:*****@"attachment; filename =""download.txt""");
                return(res.WriteAsync("file content"));
            })))
                using (var driver = WebDriverFactory.Create(browserConfig))
                {
                    driver.Navigate().GoToUrl(url);
                    driver.FindElement(By.LinkText("download")).Click();
                    var fileInfo = driver.WaitForFileDownload(
                        DownloadDirectory,
                        "download.txt",
                        log,
                        TimeSpan.FromSeconds(10));

                    fileInfo.Exists.Should()
                    .BeTrue("file '{0}' should exist", fileInfo.FullName);
                }
        }
        public void ThrowsNotImplementedExceptionForUnknownDriver()
        {
            Action act = () =>
            {
                var args = new NameValueCollection();
                args.Add("selenium.baseUrl", $"http://localhost:{TcpPort.NextFreePort()}");
                args.Add("webdriver.browser.type", "no-factory-method");

                var browserConfig = WebDriver
                                    .Configure(cfg => cfg.WithDefaultOptions().Providers(x => args[x]), log)
                                    .Build();
                var temp = WebDriverFactory.Create(browserConfig);
            };

            act
            .Should()
            .Throw <Exception>()
            .WithMessage("No browser configured for type 'no-factory-method'");
        }
Exemplo n.º 8
0
        public async Task SavesScreenShot()
        {
            var screenShotPath = @"Screenshots\TakingScreenShots\SavesScreenShot.png";
            var log            = this.CreateLogger();
            var args           = new NameValueCollection();

            args.Add("selenium.baseUrl", "https://www.google.com");
            var browserConfig = WebDriver
                                .Configure(cfg => cfg.WithDefaultOptions().Providers(x => args[x]), log)
                                .Build();

            using (var driver = WebDriverFactory.Create(browserConfig))
            {
                driver.Navigate().GoToUrl("https://www.google.com");
                driver.SaveScreenshotForEachTab(screenShotPath, log);
            }

            var screenShotFile = new FileInfo(screenShotPath);

            screenShotFile.Exists.Should()
            .BeTrue("file '{0}' should exist", screenShotPath);
        }