Ejemplo n.º 1
0
        private static void Feature_StaticCommand_ComboBoxSelectionChangedViewModel_Core(IBrowserWrapper browser)
        {
            browser.Wait();

            // select second value in the first combo box, the second one should select the second value too
            browser.ElementAt("select", 0).Select(1).Wait();
            browser.ElementAt("select", 1).Select(1).Wait();
            AssertUI.IsSelected(browser.ElementAt("select", 0).ElementAt("option", 1));
            AssertUI.IsSelected(browser.ElementAt("select", 1).ElementAt("option", 1));

            // select third value in the first combo box, the second one should select the third value too
            browser.ElementAt("select", 0).Select(2).Wait();
            browser.ElementAt("select", 1).Select(2).Wait();
            AssertUI.IsSelected(browser.ElementAt("select", 0).ElementAt("option", 2));
            AssertUI.IsSelected(browser.ElementAt("select", 1).ElementAt("option", 2));

            // select first value in the first combo box, the second one should select the first value too
            browser.ElementAt("select", 0).Select(0).Wait();
            browser.ElementAt("select", 1).Select(0).Wait();
            AssertUI.IsSelected(browser.ElementAt("select", 0).ElementAt("option", 0));
            AssertUI.IsSelected(browser.ElementAt("select", 1).ElementAt("option", 0));

            // click the first button - the second value should be selected in the first select, the second select should not change
            browser.ElementAt("input", 0).Click().Wait();
            AssertUI.IsSelected(browser.ElementAt("select", 0).ElementAt("option", 1));
            AssertUI.IsSelected(browser.ElementAt("select", 1).ElementAt("option", 0));

            // click the second button - the third value should be selected in the second select, the first select should not change
            browser.ElementAt("input", 1).Click().Wait();
            AssertUI.IsSelected(browser.ElementAt("select", 0).ElementAt("option", 1));
            AssertUI.IsSelected(browser.ElementAt("select", 1).ElementAt("option", 2));

            // click the third button - the first value should be selected in the second select, the first select should not change
            browser.ElementAt("input", 2).Click().Wait();
            AssertUI.IsSelected(browser.ElementAt("select", 0).ElementAt("option", 1));
            AssertUI.IsSelected(browser.ElementAt("select", 1).ElementAt("option", 0));
        }
Ejemplo n.º 2
0
        private void ValidatePostbackHandlersComplexSection(string sectionSelector, IBrowserWrapper browser)
        {
            IElementWrapper section = null;

            browser.WaitFor(() => {
                section = browser.First(sectionSelector);
            }, 2000, "Cannot find static commands section.");

            var index = browser.First("[data-ui=\"command-index\"]");

            // confirm first
            section.ElementAt("input[type=button]", 0).Click();
            AssertUI.AlertTextEquals(browser, "Confirmation 1");
            browser.ConfirmAlert();
            browser.Wait();
            AssertUI.InnerTextEquals(index, "1");

            // cancel second
            section.ElementAt("input[type=button]", 1).Click();
            AssertUI.AlertTextEquals(browser, "Confirmation 1");
            browser.ConfirmAlert();
            browser.Wait();

            AssertUI.AlertTextEquals(browser, "Confirmation 2");
            browser.DismissAlert();
            browser.Wait();
            AssertUI.InnerTextEquals(index, "1");
            // confirm second
            section.ElementAt("input[type=button]", 1).Click();
            AssertUI.AlertTextEquals(browser, "Confirmation 1");
            browser.ConfirmAlert();
            browser.Wait();
            AssertUI.AlertTextEquals(browser, "Confirmation 2");
            browser.ConfirmAlert();
            browser.Wait();
            AssertUI.InnerTextEquals(index, "2");

            // confirm third
            section.ElementAt("input[type=button]", 2).Click();
            Assert.IsFalse(browser.HasAlert());
            browser.Wait();
            AssertUI.InnerTextEquals(index, "3");

            // confirm fourth
            section.ElementAt("input[type=button]", 3).Click();
            AssertUI.AlertTextEquals(browser, "Generated 1");
            browser.ConfirmAlert();
            browser.Wait();
            AssertUI.InnerTextEquals(index, "4");

            // confirm fifth
            section.ElementAt("input[type=button]", 4).Click();
            AssertUI.AlertTextEquals(browser, "Generated 2");
            browser.ConfirmAlert();
            browser.Wait();
            AssertUI.InnerTextEquals(index, "5");

            // confirm conditional
            section.ElementAt("input[type=button]", 5).Click();
            Assert.IsFalse(browser.HasAlert());
            browser.Wait();
            AssertUI.InnerTextEquals(index, "6");

            browser.First("input[type=checkbox]").Click();

            section.ElementAt("input[type=button]", 5).Click();
            AssertUI.AlertTextEquals(browser, "Conditional 1");
            browser.ConfirmAlert();
            browser.Wait();
            AssertUI.InnerTextEquals(index, "6");

            browser.First("input[type=checkbox]").Click();

            section.ElementAt("input[type=button]", 5).Click();
            Assert.IsFalse(browser.HasAlert());
            browser.Wait();
            AssertUI.InnerTextEquals(index, "6");

            browser.First("input[type=checkbox]").Click();

            section.ElementAt("input[type=button]", 5).Click();
            AssertUI.AlertTextEquals(browser, "Conditional 1");
            browser.ConfirmAlert();
            browser.Wait();
            AssertUI.InnerTextEquals(index, "6");

            //localization - resource binding in confirm postback handler message

            section.ElementAt("input[type=button]", 6).Click();
            AssertUI.AlertTextEquals(browser, "EnglishValue");
            browser.ConfirmAlert();
            browser.Wait();
            AssertUI.InnerTextEquals(index, "7");

            browser.First("#ChangeLanguageCZ").Click();

            browser.WaitFor(() => {
                index = browser.First("[data-ui=\"command-index\"]");
                AssertUI.InnerTextEquals(index, "0");
            }, 1500, "Redirect to CZ localization failed.");

            section = browser.First(sectionSelector);

            //ChangeLanguageEN
            section.ElementAt("input[type=button]", 6).Click();
            AssertUI.AlertTextEquals(browser, "CzechValue");
            browser.DismissAlert();
            browser.Wait();
            AssertUI.InnerTextEquals(index, "0");

            section.ElementAt("input[type=button]", 6).Click();
            AssertUI.AlertTextEquals(browser, "CzechValue");
            browser.ConfirmAlert();
            browser.Wait();
            AssertUI.InnerTextEquals(index, "7");
        }
Ejemplo n.º 3
0
        /// <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);
            }
        }