Exemplo n.º 1
0
    public static bool IsElementInView(this IElementWrapper element)
    {
        var executor = element.BrowserWrapper.GetJavaScriptExecutor();

        var result = executor.ExecuteScript(@"
function elementInViewport2(el) {
  var top = el.offsetTop;
  var left = el.offsetLeft;
  var width = el.offsetWidth;
  var height = el.offsetHeight;

  while(el.offsetParent) {
    el = el.offsetParent;
    top += el.offsetTop;
    left += el.offsetLeft;
  }

  return (
    top < (window.pageYOffset + window.innerHeight) &&
    left < (window.pageXOffset + window.innerWidth) &&
    (top + height) > window.pageYOffset &&
    (left + width) > window.pageXOffset
  );
}

return elementInViewport2(arguments[0]);
                ", element.WebElement);

        return((bool)result);
    }
Exemplo n.º 2
0
        public static void UploadFile(IElementWrapper element, string fullFileName)
        {
            if (element.BrowserWrapper.IsDotvvmPage())
            {
                element.BrowserWrapper.LogVerbose("Selenium.DotVVM : Uploading file");
                var name = element.GetTagName();
                if (name == "a" && element.HasAttribute("onclick") && (element.GetAttribute("onclick")?.Contains("showUploadDialog") ?? false))
                {
                    UploadFileByA(element, fullFileName);
                    return;
                }

                if (name == "div" && element.FindElements("iframe", SelectBy.CssSelector).Count == 1)
                {
                    UploadFileByDiv(element, fullFileName);
                    return;
                }
                else
                {
                    element.BrowserWrapper.LogVerbose("Selenium.DotVVM : Cannot identify DotVVM scenario. Uploading over standard procedure.");

                    element.BrowserWrapper.OpenInputFileDialog(element, fullFileName);
                    return;
                }
            }

            element.BrowserWrapper.OpenInputFileDialog(element, fullFileName);
        }
Exemplo n.º 3
0
        public static void HasClass(IElementWrapper wrapper, string value, bool caseSensitive = true)
        {
            var values = value.Split(' ');

            Attribute(wrapper, "class", p => values.All(v => p.Split(' ').Any(c => string.Equals(c, v,
                                                                                                 caseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase))), $"Expected value: '{value}'.");
        }
Exemplo n.º 4
0
 public static void CheckIfIsElementNotInView(this IElementWrapper element)
 {
     if (IsElementInView(element))
     {
         throw new UnexpectedElementStateException($"Element is in browser view. {element.ToString()}");
     }
 }
Exemplo n.º 5
0
        protected void SetTextBoxValue(IElementWrapper textBox, string value)
        {
            textBox.Click();
            textBox.Clear();
            textBox.SendKeys(Keys.Escape);

            textBox.SendKeys(value);
            textBox.SendEnterKey();
        }
Exemplo n.º 6
0
        public static void IsNotChecked(IElementWrapper wrapper)
        {
            TagName(wrapper, "input", "Function IsNotChecked() can be used on input element only.");
            Attribute(wrapper, "type", new[] { "checkbox", "radio" }, failureMessage: "Input element must be type of checkbox or radio.");

            var isNotChecked = new IsNotCheckedValidator();

            EvaluateValidator <UnexpectedElementStateException, IElementWrapper>(wrapper, isNotChecked);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Sets file to input dialog.
 /// </summary>
 ///<exception cref="UnexpectedElementException">The element is not input or type is not file.</exception>
 public void OpenInputFileDialog(IElementWrapper fileInputElement, string file)
 {
     if (!IsFileInput(fileInputElement))
     {
         throw new UnexpectedElementException("Tag name of the element has to be input and type has to be file.");
     }
     fileInputElement.SendKeys(file);
     Wait();
 }
Exemplo n.º 8
0
        public IBrowserWrapper DragAndDrop(IElementWrapper elementWrapper, IElementWrapper dropToElement, int offsetX = 0, int offsetY = 0)
        {
            Actions dragAndDrop = new Actions(_GetInternalWebDriver());

            dragAndDrop.ClickAndHold(elementWrapper.WebElement)
            .MoveToElement(dropToElement.WebElement, offsetX, offsetY)
            .Release(dropToElement.WebElement).Build().Perform();

            return(this);
        }
Exemplo n.º 9
0
        protected void SetDatePickerValue(IElementWrapper datePicker, DateTime value)
        {
            var textBox = datePicker.Single("input");

            textBox.Click();
            textBox.Clear();
            textBox.SendKeys(Keys.Escape);

            textBox.SendKeys(value.ToString("D"));
            textBox.SendEnterKey();
        }
Exemplo n.º 10
0
        private int ParentElementsCount(IElementWrapper element, string tagName)
        {
            if (element.GetTagName().Equals("body", StringComparison.InvariantCultureIgnoreCase))
            {
                return(0);
            }

            return(element.GetTagName() == tagName
                ? ParentElementsCount(element.ParentElement, tagName) + 1
                : ParentElementsCount(element.ParentElement, tagName));
        }
Exemplo n.º 11
0
        public void OpenFileDialog(IElementWrapper fileInputElement, string file)
        {
            // open file dialog
            fileInputElement.Click();
            Wait();

            //Another wait is needed because without it sometimes few chars from file path are skipped.
            Wait(1000);

            // write the full path to the dialog
            System.Windows.Forms.SendKeys.SendWait(file);
            Wait();
            SendEnterKey();
        }
        /// <summary>
        /// Opens file dialog and sends keys with full path to file, that should be uploaded.
        /// </summary>
        /// <param name="fileUploadOpener">Element that opens file dialog after it is clicked.</param>
        /// <param name="fullFileName">Full path to file that is intended to be uploaded.</param>
        public virtual IBrowserWrapperFluentApi FileUploadDialogSelect(IElementWrapper fileUploadOpener, string fullFileName)
        {
            try
            {
                OpenInputFileDialog(fileUploadOpener, fullFileName);
            }
            catch (UnexpectedElementException)
            {
#if net461
                base.OpenFileDialog(fileUploadOpener, fullFileName);
#else
                throw;
#endif
            }

            return(this);
        }
Exemplo n.º 13
0
        private static void UploadFileByA(IElementWrapper element, string fullFileName)
        {
            element.BrowserWrapper.GetJavaScriptExecutor()
            .ExecuteScript("dotvvm.fileUpload.createUploadId(arguments[0])", element.WebElement);

            var iframe = element.ParentElement.ParentElement.First("iframe", SelectBy.CssSelector).WebElement;

            element.BrowserWrapper.Driver.SwitchTo().Frame(iframe);

            var fileInput = element.BrowserWrapper._GetInternalWebDriver()
                            .FindElement(SelectBy.CssSelector("input[type=file]"));

            fileInput.SendKeys(fullFileName);

            element.Wait(element.ActionWaitTime);
            element.ActivateScope();
        }
Exemplo n.º 14
0
        public void Control_GridView_InvalidCssClass_TextBox_Attached()
        {
            RunInAllBrowsers(browser => {
                browser.NavigateToUrl(SamplesRouteUrls.ControlSamples_GridView_InvalidCssClass);
                browser.WaitUntilDotvvmInited();

                var gridview = browser.Single("gridview", SelectByDataUi);
                gridview.First("edit-button", SelectByDataUi).Click();

                IElementWrapper textbox       = null;
                browser.WaitFor(() => textbox = browser.First(".name-attached > input"), 1000);
                AssertUI.HasNotClass(textbox, "invalid");
                textbox.Clear();

                gridview.First("save-button", SelectByDataUi).Click();
                browser.WaitFor(() => AssertUI.HasClass(textbox, "invalid"), 1000);
            });
        }
Exemplo n.º 15
0
    public static IElementWrapper ScrollTo(this IElementWrapper element)
    {
        var javascript = @"
            function findPosition(element) {
                var curtop = 0;
                if (element.offsetParent) {
                    do {
                        curtop += element.offsetTop;
                    } while (element = element.offsetParent);
                return [curtop];
                }
            }

            window.scroll(0,findPosition(arguments[0]));
        ";
        var executor   = element.BrowserWrapper.GetJavaScriptExecutor();

        executor.ExecuteScript(javascript, element.WebElement);
        return(element);
    }
Exemplo n.º 16
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");
        }
Exemplo n.º 17
0
        protected DateTime GetDatePickerValue(IElementWrapper datePicker)
        {
            var datePickerText = GetTextBoxValue(datePicker.Single("input"));

            return(DateTime.ParseExact(datePickerText, "D", CultureInfo.CurrentCulture));
        }
Exemplo n.º 18
0
        public static void HasNotAttribute(IElementWrapper wrapper, string name)
        {
            var hasNotAttribute = new HasNotAttributeValidator(name);

            EvaluateValidator <UnexpectedElementStateException, IElementWrapper>(wrapper, hasNotAttribute);
        }
Exemplo n.º 19
0
 public static void ClassAttribute(IElementWrapper wrapper, Expression <Func <string, bool> > expression, string failureMessage = "")
 {
     Attribute(wrapper, "class", expression, failureMessage);
 }
Exemplo n.º 20
0
        public static void CssStyle(IElementWrapper wrapper, string styleName, string value, bool caseSensitive = false, bool trimValue = true, string failureMessage = null)
        {
            var checkCssStyle = new CssStyleValidator(styleName, value, caseSensitive, trimValue, failureMessage);

            EvaluateValidator <UnexpectedElementStateException, IElementWrapper>(wrapper, checkCssStyle);
        }
Exemplo n.º 21
0
 /// <summary>
 /// Determinates whether element is file dialog. (input[type=file])
 /// </summary>
 public bool IsFileInput(IElementWrapper fileInputElement)
 {
     return(fileInputElement.GetTagName() == "input" && fileInputElement.HasAttribute("type") && fileInputElement.GetAttribute("type") == "file");
 }
Exemplo n.º 22
0
        public static void TextNotEquals(IElementWrapper wrapper, string text, bool caseSensitive = false, bool trim = true, string failureMessage = null)
        {
            var textNotEquals = new TextNotEqualsValidator(text, caseSensitive, trim);

            EvaluateValidator <UnexpectedElementStateException, IElementWrapper>(wrapper, textNotEquals);
        }
Exemplo n.º 23
0
        public static void Text(IElementWrapper wrapper, Expression <Func <string, bool> > rule, string failureMessage = null)
        {
            var text = new TextValidator(rule, failureMessage);

            EvaluateValidator <UnexpectedElementStateException, IElementWrapper>(wrapper, text);
        }
 public new IBrowserWrapperFluentApi DragAndDrop(IElementWrapper elementWrapper, IElementWrapper dropToElement, int offsetX = 0,
                                                 int offsetY = 0)
 {
     return((IBrowserWrapperFluentApi)base.DragAndDrop(elementWrapper, dropToElement, offsetX, offsetY));
 }
Exemplo n.º 25
0
        public static void IsNotSelected(IElementWrapper wrapper)
        {
            var isNotSelected = new IsNotSelectedValidator();

            EvaluateValidator <UnexpectedElementStateException, IElementWrapper>(wrapper, isNotSelected);
        }
Exemplo n.º 26
0
 protected string GetTextBoxValue(IElementWrapper textBox)
 {
     return(textBox.GetText());
 }
Exemplo n.º 27
0
 public static void ClassAttribute(IElementWrapper wrapper, string value, bool caseSensitive = true, bool trimValue = true)
 {
     Attribute(wrapper, "class", value, caseSensitive, trimValue);
 }
Exemplo n.º 28
0
 protected string GetComboBoxValue(IElementWrapper comboBox)
 {
     return(GetTextBoxValue(comboBox.Single("input")));
 }
Exemplo n.º 29
0
 protected void SetComboBoxValue(IElementWrapper comboBox, string value)
 {
     SetTextBoxValue(comboBox.Single("input"), value);
 }
Exemplo n.º 30
0
        public static void Attribute(IElementWrapper wrapper, string attributeName, Expression <Func <string, bool> > expression, string failureMessage = null)
        {
            var attribute = new AttributeValidator(attributeName, expression, failureMessage);

            EvaluateValidator <UnexpectedElementStateException, IElementWrapper>(wrapper, attribute);
        }