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); }
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); }
/// <inheritdoc /> public void BeforeTest(ITest test) { this.log = this.CreateLogger(); var pageType = GetFixturePage(test); var configBuilder = test.Fixture as IProvideWebDriverConfigBuilder; var configHolder = test.Fixture as IRequireCurrentWebDriverConfig; var authentication = test.Fixture as IRequireAuthentication; var screenshots = test.Fixture as IRequireScreenshots; var downloads = test.Fixture as IRequireDownloadDirectory; var config = configBuilder?.Builder.Build() ?? WebDriver .Configure( builder => { builder.WithDefaultOptions(); if (downloads != null) { builder.DownloadDirectory(downloads.DownloadDirectory); } return(builder); }, log) .Build(); if (configHolder != null) { configHolder.Config = config; } /* lazy initialized */ authHelper = new AuthenticationHelper(config, log); var init = authentication != null ? (Action <IWebDriverConfig, IWebDriver, IAuthenticationHelper>)AuthenticatedInitialize : Initialize; ExceptionDispatchInfo initializationException = null; (webDriver, initializationException) = WebDriverFactory.CreateAndInitialize(config, (cfg, drv) => init(cfg, drv, authHelper)); initializationException?.Throw(); var requiresWebForPageType = RequiresWebType.MakeGenericType(pageType); var page = GetPage(pageType, config); requiresWebForPageType.GetProperty("StartPage")?.SetValue(test.Fixture, page); if (screenshots != null) { page.WaitForPageToLoad(); SaveScreenshotForEachTab(TestContext.CurrentContext, "_pre"); } }
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); }