/// <summary> /// Waits for dotvvm postback to be finished. /// </summary> /// <param name="browser"></param> /// <param name="timeout">Timeout in ms.</param> public static void WaitForPostback(this IBrowserWrapper browser, int timeout = 20000) { if (browser.IsDotvvmPage()) { browser.WaitFor(() => string.Equals("false", browser.GetJavaScriptExecutor().ExecuteScript("return dotvvm.isPostbackRunning()").ToString(), StringComparison.OrdinalIgnoreCase) , timeout, "DotVVM postback still running."); } }
private void CheckSelectAllOnFocus(IBrowserWrapper browser, string textBoxDataUi, bool isSelectAllOnFocusTrue = true) { var textBox = browser.Single(textBoxDataUi, SelectByDataUi); textBox.Click(); var selectedText = (string)browser.GetJavaScriptExecutor().ExecuteScript($"return window.getSelectionText('{textBoxDataUi}');"); var expectedText = isSelectAllOnFocusTrue ? "Testing text" : ""; Assert.AreEqual(expectedText, selectedText); }
/// <summary> /// Determines whether tested page is dotvvm. /// </summary> /// <param name="browser"></param> /// <returns></returns> public static bool IsDotvvmPage(this IBrowserWrapper browser) { try { return(string.Equals("true", browser.GetJavaScriptExecutor().ExecuteScript("return dotvvm instanceof DotVVM").ToString(), StringComparison.OrdinalIgnoreCase)); } catch (Exception ex) { return(false); } }
private void ReturnedFileDownload(IBrowserWrapper browser, string fileContent) { browser.NavigateToUrl(SamplesRouteUrls.FeatureSamples_ReturnedFile_ReturnedFileSample); var jsexec = browser.GetJavaScriptExecutor(); jsexec.ExecuteScript("window.downloadURL = \"\";"); jsexec.ExecuteScript("DotVVM.prototype.performRedirect = function(url){window.downloadURL = url};"); browser.First("textarea").SendKeys(fileContent); browser.First("input").SendKeys(Keys.Enter); var downloadURL = (string)jsexec.ExecuteScript("return window.downloadURL;"); Assert.IsNotNull(downloadURL); string returnedFile; using (var client = new WebClient()) { returnedFile = client.DownloadString(browser.GetAbsoluteUrl(downloadURL)); } Assert.AreEqual(fileContent, returnedFile); }
/// <summary> /// Determines whether tested page is dotvvm. /// The detection is ensured by waiting for invocation of DotVVM Init. /// </summary> /// <param name="browser"></param> /// <param name="maxDotvvmLoadTimeout">is the maximum time interval in which the DotVVM has to be loaded.</param> public static bool IsDotvvmPage(this IBrowserWrapper browser, long maxDotvvmLoadTimeout = 8000) { try { var result = "loading"; var stopwatch = new Stopwatch(); stopwatch.Start(); var isFirstRun = true; while (stopwatch.ElapsedMilliseconds < maxDotvvmLoadTimeout && result == "loading") { if (!isFirstRun) { browser.Wait(30); } isFirstRun = false; var executor = browser.GetJavaScriptExecutor(); result = executor.ExecuteScript( @"return (function seleniumUtils_IsDotvvmPageLoaded() { var state = (window.__riganti_selenium_utils_dotvvm || (window.__riganti_selenium_utils_dotvvm = {})); if (state.inited) { return true; } if (window.dotvvm != null) { dotvvm.events.init.subscribe(function () { state.inited = true }); state.loaded = true; } if (!state.loaded && document.scripts.length > 0) { for (var key in document.scripts) { if (document.scripts.hasOwnProperty(key)) { var script = document.scripts[key]; if (script.src.indexOf('/dotvvm--internal') > -1) { state.loaded = true; return 'loading'; } else { if (document.readyState === 'complete') { return false; } } } } } if (!state.loaded && document.readyState !== 'complete') { state.loaded = false; return 'loading'; } return state.inited || 'loading'; })();" )?.ToString(); } stopwatch.Stop(); if (result == "loading") { return(false); } else { return(string.Equals(result, "true", StringComparison.OrdinalIgnoreCase)); } } catch (Exception ex) { return(false); } }