/// <summary> /// /// This one is a tricky one. I will preface it by saying that for the most part you should not need this method. /// Most Selenium methods (Click, Submit, FindElement, etc) use the implicit timeout to wait for an element to appear /// and then wait until the page finishes loading before returning control back to your program. Usually if you feel /// like you need to wait for the page to load, it is better to try adjusting the implicit wait time first or use the /// WaitWebDriver class. Now, with those disclamers, sometimes it can be useful to have the ability to wait for the page /// to finish loading.For example, SendKeys does not wait for the page to finish loading. /// /// element.SendKeys(Keys.Enter); /// driver.WaitForPageToLoad(); /// Same thing as /// element.Click(); /// /// </summary> /// <param name="driver">Current Web Driver</param> public static void WaitForPageToLoad(this IWebDriver driver) { if (!(driver is IJavaScriptExecutor javascript)) { throw new ArgumentException("Driver must support javascript execution", nameof(driver)); } //To get around the pop up issue, particualrly in internet explorer //https://stackoverflow.com/questions/6852732/selenium-webdriver-how-to-close-browser-popup javascript.ExecuteScript("window.onbeforeunload = function(e){};"); WebTestManager.Instance().BrowserWait.Until((d) => { try { string readyState = javascript.ExecuteScript("if (document.readyState) return document.readyState;").ToString(); return(readyState.ToLower() == "complete"); } catch (InvalidOperationException e) { //Window is no longer available return(e.Message.ToLower().Contains("unable to get browser")); } catch (WebDriverException e) { //Browser is no longer available return(e.Message.ToLower().Contains("unable to connect")); } catch { return(false); } }); }
/// <summary> /// This method figures out what tests, environments and sites are to be tested and runs them separately in their own threads /// </summary> protected void btnSubmitTests_Click(object sender, EventArgs e) { WebTestManager manager = new WebTestManager(this); IEnumerable <TestEnvironment> envs = from ListItem li in cblEnv.Items.Cast <ListItem>() where li.Selected select Environments[int.Parse(li.Value)]; IEnumerable <TestSite> sites = from ListItem li in cblSites.Items.Cast <ListItem>() where li.Selected select Sites[int.Parse(li.Value)]; foreach (ListItem li in cblTests.Items.Cast <ListItem>().Where(a => a.Selected)) { TestFixture tf = Fixtures[li.Value]; manager.RunTest(tf, envs, sites); } }
void RegisterServiceImplementors() { if (WebTestManager.IsTddExecutionMode()) { // TODO: Add real service implementors: // e.g. CurrencyService.RegisterImplementor<European.Central.Bank.FakeCurrencyServiceImplementor>(); } else { // TODO: Register fake service implementors: // e.g. CurrencyService.RegisterImplementor<European.Central.Bank.CurrencyServiceImplementor>(); } }
public static bool TryWait(this IWebDriver driver, By by) { try { WebTestManager.Instance().BrowserWait .Until(d => d.FindElement(by)); return(true); } catch { return(false); } }
public static HtmlString ResetDatabaseLink(this IHtmlHelper html) { if (!WebTestManager.IsTddExecutionMode()) { return(null); } if (html.Request().IsAjaxCall()) { return(null); } if (WebTestManager.IsSanityExecutionMode()) { html.RunJavascript("page.skipNewWindows();"); } return(new HtmlString(WebTestManager.GetWebTestWidgetHtml(Context.Http.Request))); }
public static HtmlString WebTestWidget(this IHtmlHelper html) { if (!WebTestConfig.IsActive()) { return(null); } if (Context.Current.Request().IsAjaxCall()) { return(null); } if (WebTestConfig.IsAutoExecMode) { html.RunJavascript("page.skipNewWindows();"); } return(new HtmlString(WebTestManager.GetWebTestWidgetHtml())); }
public static bool VisibleWait(this IWebElement elm, uint timeOut = 10, uint polling = 550) { try { var wait = new DefaultWait <IWebElement>(elm) { Timeout = TimeSpan.FromSeconds(timeOut), PollingInterval = TimeSpan.FromMilliseconds(polling) }; wait.IgnoreExceptionTypes(typeof(NoSuchElementException), typeof(WebDriverException), typeof(StaleElementReferenceException)); return(wait.Until(element => element.Displayed && element.Enabled)); } catch (System.Exception exp) { var loggingUtility = WebTestManager.Instance().LoggingUtility; loggingUtility.Warning(exp.Message + exp.StackTrace); return(false); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public virtual void Configure(IApplicationBuilder app, IHostingEnvironment env) { InitializeDatabase(app, env); app.ConfigureOliveDependencies(env); ConfigureExceptionPage(app, env); if (WebTestManager.IsTddExecutionMode()) { app.UseWebTestMiddleware(); } app.UseAuthentication() .UseStaticFiles() .UseRequestLocalization(RequestLocalizationOptions) .UseSession() .UseMvc(ConfigureRoutes); WebTestManager.CreateReferenceDataBy(CreateReferenceData); Task.Factory.RunSync(() => WebTestManager.InitiateTempDatabase(enforceRestart: false, mustRenew: false)); }
public void Global_ASAX() { // The actual service implementation will be registerd here once for live use (non-test mode). // Throughout the development period when the application is in TDD mode, this service is essentially not registered, so // there is no dependency on the external service. // Perhaps only once when the ServiceImplementation is created during development cycle, // you can remove the condition to test it once or twice. if (WebTestManager.IsTddExecutionMode() == false) { MyService.RegisterImplementor <My.VSProject.MyServiceImplementor>(); // Optional: Add an Automated Task to call the following. // It will frequently process all outstanding items in the queue. // Mainly relevant for multi-try situations in live operations. Avoid unless necessary. IntegrationManager.ProcessOutstandingItems(); } else { // Note: In case you need to provide a Mock implementation for the service, instead of manually injecting the responses // through sanity, you can create a class that fakes responses to requests and inject it here: // e.g: MyService.Register<My.VSProject.MyServiceMockImplementation>(); } }
public static void Cleanup() { WebTestManager.Instance().OnDisposeAssemblyDependencies(); }
public static void Initialise(TestContext testContext) { WebTestManager.Instance().OnInitialiseAssemblyDependencies(testContext); }
public void SetUp() { WebTestManager.Initialize <TestHostStartup>("CustomerService"); }
static void RunWebTest(string[] args) { //params 1 = test assembly string testAssembly = string.Empty; if (args.Length > 1) { testAssembly = args[1]; } else { Console.WriteLine("You need to specify an assembly."); return; } //params 2 = test name string testName = string.Empty; if (args.Length > 2) { testName = args[2]; } else { Console.WriteLine("You need to specify a test."); return; } //params 3 = environments Dictionary <int, TestEnvironment> Environments = new Dictionary <int, TestEnvironment>(); if (args.Length > 3) { IEnumerable <TestEnvironment> prEnv = EnvironmentProvider.GetEnvironments(); foreach (string s in GetStrings(args[3])) { foreach (TestEnvironment fenv in prEnv.Where(a => a.ID.Equals(int.Parse(s)))) { if (!Environments.ContainsKey(fenv.ID)) { Console.WriteLine(string.Format("Adding '{0}' Environment.", fenv.Name)); Environments.Add(fenv.ID, fenv); } } } } // params 4 = systems // params 5 = sites // will look for sites by system unless systems is an empty string then it looks for them by site Dictionary <int, TestSite> Sites = new Dictionary <int, TestSite>(); IEnumerable <TestSite> prSites = SiteProvider.GetEnabledSites(); if (args.Length > 4 && !string.IsNullOrEmpty(args[4])) { foreach (string s in GetStrings(args[4])) { foreach (TestSite fsite in prSites.Where(a => a.SystemID.Equals(int.Parse(s)))) { if (!Sites.ContainsKey(fsite.ID)) { Console.WriteLine(string.Format("Adding '{0}' Site.", fsite.Name)); Sites.Add(fsite.ID, fsite); } } } } if (args.Length > 5) { foreach (string s in GetStrings(args[5])) { foreach (TestSite fsite in prSites.Where(a => a.ID.Equals(int.Parse(s)))) { if (!Sites.ContainsKey(fsite.ID)) { Console.WriteLine(string.Format("Adding '{0}' Site.", fsite.Name)); Sites.Add(fsite.ID, fsite); } } } } //setup for testing CoreExtensions.Host.InitializeService(); //get the test suite TestSuite suite = TestUtility.GetTestSuite(testAssembly); IEnumerable <TestFixture> Fixtures = suite.GetFixtures().Where(a => a.ClassName.EndsWith(string.Format(".{0}", testName))); if (!Fixtures.Any()) { Console.WriteLine("There were no Test Fixtures found. Make sure the class has the [TestFixture] attribute."); return; } TestFixture tf = Fixtures.First(); WebTestManager manager = new WebTestManager(new WebConsoleTestHandler()); manager.RunTest(tf, Environments.Values, Sites.Values); }
public void Init() { WebTestManager.Instance().OnInitialiseAssemblyDependencies(TestContext.Parameters); }
public static void Wait(this IWebDriver driver, By by) { WebTestManager.Instance().BrowserWait .Until(d => d.FindElement(by)); }
/// <summary> /// Waits for a specified function to be satisfied within the specified timeout. /// </summary> /// <param name="driver">The Web Driver</param> /// <param name="func">The function to be satisfied</param> public static void Wait(this IWebDriver driver, Func <IWebDriver, IWebElement> func) { WebTestManager.Instance().BrowserWait .Until(func); }