Esempio n. 1
0
        public async Task ReturnsTrueForExpectedMatch()
        {
            var log  = this.CreateLogger();
            var args = new NameValueCollection();
            var url  = $"http://localhost:{TcpPort.NextFreePort()}";

            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.ContentType = "text/html";
                return(res.WriteAsync("<body></body>"));
            })))
                using (var driver = WebDriverFactory.Create(browserConfig))
                {
                    driver.Navigate().GoToUrl(url);
                    driver.WaitForJavascriptResult("6 / 3", 2, log, TimeSpan.FromMilliseconds(100));
                }
        }
        public async Task SetUp()
        {
            this.log = this.CreateLogger();
            var args = new NameValueCollection();

            url = new Uri($"http://localhost:{TcpPort.NextFreePort()}");
            args.Add("selenium.baseUrl", url.ToString());

            browserConfig = WebDriver
                            .Configure(cfg => cfg.WithDefaultOptions().Providers(x => args[x]), log)
                            .Build();

            webHost = WebHost.Start(
                url.ToString(),
                router => router
                .MapGet(
                    "/page1",
                    (req, res, data) =>
            {
                res.ContentType = "text/html";
                return(res.WriteAsync("<body><a href='page2'>Page 2</a></body>"));
            })
                .MapGet(
                    "/page2",
                    (req, res, data) =>
            {
                res.ContentType = "text/html";
                return(res.WriteAsync("<body><label><input type='radio' />Foo</label></body>"));
            }));
            webDriver = WebDriverFactory.Create(browserConfig);
        }
Esempio n. 3
0
        public async Task SetUp()
        {
            this.log = this.CreateLogger();
            var args = new NameValueCollection();

            url = $"http://localhost:{TcpPort.NextFreePort()}";
            args.Add("selenium.baseUrl", url);

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

            webHost = WebHost.Start(
                url,
                router => router
                .MapGet(
                    "",
                    (req, res, data) =>
            {
                res.ContentType = "text/html; charset=utf-8";
                return(res.WriteAsync(
                           "<html><body><script type=\"text/javascript\">alert('Hello! I am an alert box!');</script></body></html>"));
            }));
            webDriver = WebDriverFactory.Create(browserConfig);
        }
Esempio n. 4
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'");
        }
        public async Task SetUp()
        {
            var log  = this.CreateLogger();
            var args = new NameValueCollection();

            url = $"http://localhost:{TcpPort.NextFreePort()}";
            args.Add("selenium.baseUrl", url);

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

            webHost = WebHost.Start(
                url,
                router => router
                .MapGet(
                    "",
                    (req, res, data) =>
            {
                res.ContentType = "text/html";
                return(res.WriteAsync("<body><div id='Foo' /></body>"));
            }));
            webDriver = WebDriverFactory.Create(browserConfig);
        }