Exemple #1
0
        public void ShouldReturnLikeJavaScriptObjectResultWhenExecuteReturnFunctionJavaScript()
        {
            var value = GetExecutor().ExecuteScript(@"
const f = function() { return 123; }; 
f.A = 'a';
f.B = function() {
  return 345;
}
f.B.AA = 'aa';
f.B.BB = 345;
return f;");

            AssertCompatible.IsInstanceOfType(value, typeof(Dictionary <string, object>));

            var resultValue = (Dictionary <string, object>)value;

            Assert.AreEqual(2, resultValue.Count);
            Assert.AreEqual("a", resultValue["A"]);

            AssertCompatible.IsInstanceOfType(resultValue["B"], typeof(Dictionary <string, object>));
            var bValue = (Dictionary <string, object>)resultValue["B"];

            Assert.AreEqual("aa", bValue["AA"]);
            Assert.AreEqual(345L, bValue["BB"]);
        }
Exemple #2
0
        public void FindElementByPartialLinkText_ShouldThrowExceptionWhenElementNotFound()
        {
            var context = GetDriver().FindElement(By.ClassName("bytest"));

            AssertCompatible.ThrowsException <NoSuchElementException>(() => context.FindElement(By.PartialLinkText("Notransfer")));
            AssertCompatible.ThrowsException <NoSuchElementException>(() => ((IFindsByPartialLinkText)context).FindElementByPartialLinkText("Notransfer"));
        }
Exemple #3
0
        public void FindElementByXPath_ShouldThrowExceptionWhenElementNotFound()
        {
            var context = GetDriver().FindElement(By.XPath("/html/body/div[1]"));

            AssertCompatible.ThrowsException <NoSuchElementException>(() => context.FindElement(By.XPath("tagtest1")));
            AssertCompatible.ThrowsException <NoSuchElementException>(() => ((IFindsByXPath)context).FindElementByXPath("tagtest1"));
        }
Exemple #4
0
        public void FindElementByCssSelector_ShouldThrowExceptionWhenElementNotFound()
        {
            var context = GetDriver().FindElement(By.ClassName("bytest"));

            AssertCompatible.ThrowsException <NoSuchElementException>(() => context.FindElement(By.CssSelector("#idtest[name='nametest_no']")));
            AssertCompatible.ThrowsException <NoSuchElementException>(() => ((IFindsByCssSelector)context).FindElementByCssSelector("#idtest[name='nametest_no']"));
        }
Exemple #5
0
        public void FindElementByTagName_ShouldThrowExceptionWhenElementNotFound()
        {
            var context = GetDriver().FindElement(By.ClassName("bytest"));

            AssertCompatible.ThrowsException <NoSuchElementException>(() => context.FindElement(By.TagName("tagtest_no")));
            AssertCompatible.ThrowsException <NoSuchElementException>(() => ((IFindsByTagName)context).FindElementByTagName("tagtest_no"));
        }
Exemple #6
0
        public void ShouldNotDefinedToGlobalScopeIfValiableDefinedJavaScript()
        {
            var funcName = "___test_define_func";

            GetExecutor().ExecuteScript($"function {funcName}() {{return 1;}}");
            AssertCompatible.ThrowsException <WebDriverException>(() => GetExecutor().ExecuteScript($"return {funcName}();"),
                                                                  $"javascript error: {funcName} is not defined");
        }
        public void SelectedOption_ShouldThrowExeceptionWhenHasNoSelected()
        {
            InitializeSelect();

            var select = GetDriver().FindElement(By.Id("singleSelect"));
            var elem   = new SelectElement(select);

            AssertCompatible.ThrowsException <NoSuchElementException>(() => elem.SelectedOption);
        }
Exemple #8
0
        public void ShouldReturnReadOnlyCollectionWithObjectWhenReturnExecuteReturnArrayIncludeWithVariousTypes()
        {
            var value = GetExecutor().ExecuteScript("return [123, 'AAA', true, document.querySelector('input')];");

            Assert.AreEqual(typeof(ReadOnlyCollection <object>), value.GetType());
            var results = (ReadOnlyCollection <object>)value;

            Assert.AreEqual(123L, results[0]);
            Assert.AreEqual("AAA", results[1]);
            Assert.AreEqual(true, results[2]);
            AssertCompatible.IsInstanceOfType(results[3], typeof(IWebElement));
        }
        public void Locatable()
        {
            var element   = GetDriver().FindElement(By.Id("textBoxName"));
            var locatable = (ILocatable)element;
            var locationOnScreenOnceScrolledIntoView = locatable.LocationOnScreenOnceScrolledIntoView;
            var coordinates = locatable.Coordinates;

            var id                 = coordinates.AuxiliaryLocator;
            var locationInDom      = coordinates.LocationInDom;
            var locationInViewport = coordinates.LocationInViewport;

            AssertCompatible.ThrowsException <Exception>(() => coordinates.LocationOnScreen);
        }
Exemple #10
0
        private void IEnumerableParameterShouldPassedInArrayType(IEnumerable <object> paramValue)
        {
            var value = ExecuteParameterCheckString(new object[] { paramValue });

            Assert.AreEqual(1, value.Count);
            Assert.AreEqual("[object Array]", value[0].type);

            AssertCompatible.IsInstanceOfType(value[0].value, typeof(ReadOnlyCollection <object>));

            var values = value[0].value as ReadOnlyCollection <object>;
            var param  = paramValue.ToList();

            Assert.AreEqual(Convert.ToInt64(param[0]), values[0]);
            Assert.AreEqual(param[1], values[1]);
            Assert.AreEqual(param[2], values[2]);
        }
        public void ShouldThrowExceptionWhenReferenceTheRemovedElement()
        {
            var element = GetDriver().FindElement(By.Id("textBoxName"));

            AssertCompatible.IsInstanceOfType(element, typeof(IWebElement));
            element.SendKeys("ABC");
            GetExecutor().ExecuteScript("const elem = document.querySelector('#textBoxName'); elem.parentNode.removeChild(elem);");
            AssertCompatible.ThrowsException <StaleElementReferenceException>(() => element.SendKeys("DEF"));

            GetExecutor().ExecuteScript(@"
const elem = document.createElement('input');
elem.setAttribute('id', 'textBoxName');
document.body.appendChild(elem);");

            AssertCompatible.ThrowsException <StaleElementReferenceException>(() => element.SendKeys("DEF"));

            element = GetDriver().FindElement(By.Id("textBoxName"));
            AssertCompatible.IsInstanceOfType(element, typeof(IWebElement));
            element.SendKeys("ABC");
        }
Exemple #12
0
        public void ShouldReturnWebElementWhenExecuteReturnElementScript()
        {
            var value = GetExecutor().ExecuteScript("return document.querySelector('#textBoxName');");

            AssertCompatible.IsInstanceOfType(value, typeof(IWebElement));
        }
 public void ShouldThrowExceptionWhenMissingElementUsedFindElementById()
 {
     AssertCompatible.ThrowsException <NoSuchElementException>(() => GetDriver().FindElement(By.Id("idtest_no")));
     AssertCompatible.ThrowsException <NoSuchElementException>(() => GetDriver <IFindsById>().FindElementById("idtest_no"));
 }
Exemple #14
0
 public void ShouldThrowExceptionWhenMissingElementUsedFindElementByName()
 {
     AssertCompatible.ThrowsException <NoSuchElementException>(() => GetDriver().FindElement(By.Name("nametest_no")));
 }
 public void ShouldThrowExceptionWhenMissingElementUsedFindElementByCssSelector()
 {
     AssertCompatible.ThrowsException <NoSuchElementException>(() => GetDriver().FindElement(By.CssSelector(".bytest > #idtest_no[name='nametest']")));
     AssertCompatible.ThrowsException <NoSuchElementException>(() => GetDriver <IFindsByCssSelector>().FindElementByCssSelector(".bytest > #idtest_no[name='nametest']"));
 }
Exemple #16
0
        public virtual void ShouldReturnWebElementWhenExecuteReturnDocumentScript()
        {
            var value = GetExecutor().ExecuteScript("return document;");

            AssertCompatible.IsInstanceOfType(value, typeof(IWebElement));
        }
Exemple #17
0
 public void ShouldRaiseExceptionWhenExecuteReturnWindowScript()
 {
     AssertCompatible.ThrowsException <WebDriverException>(() => GetExecutor().ExecuteScript("return window;"));
 }
 public void ShouldThrowExceptionWhenMissingElementUsedFindElementByXPath()
 {
     AssertCompatible.ThrowsException <NoSuchElementException>(() => GetDriver().FindElement(By.XPath("/html/body/div[1]/tagtest_no")));
     AssertCompatible.ThrowsException <NoSuchElementException>(() => GetDriver <IFindsByXPath>().FindElementByXPath("/html/body/div[1]/tagtest_no"));
 }
Exemple #19
0
 public void ShouldThrowExeceptionWhenReturnNonElementNode()
 {
     AssertCompatible.ThrowsException <WebDriverException>(() => GetExecutor().ExecuteScript(
                                                               "return Array.prototype.slice.call(document.querySelector('form').childNodes)" +
                                                               ".filter(n => n.nodeType !== Node.ELEMENT_NODE)[0]"));
 }
 public void ShouldThrowExceptionWhenMissingElementUsedFindElementByPartialLinkText()
 {
     AssertCompatible.ThrowsException <NoSuchElementException>(() => GetDriver().FindElement(By.PartialLinkText("No Frame")));
     AssertCompatible.ThrowsException <NoSuchElementException>(() => GetDriver <IFindsByPartialLinkText>().FindElementByPartialLinkText("No Frame"));
 }
Exemple #21
0
        public void ShouldThrowExceptionWhenPassedUnsupportedParameterType()
        {
            var paramValue = new Regex("[ABC]");

            AssertCompatible.ThrowsException <ArgumentException>(() => ExecuteParameterCheckString(paramValue));
        }
Exemple #22
0
 public void ShouldThrowExceptionWhenMissingElementUsedFindElementByLinkText()
 {
     AssertCompatible.ThrowsException <NoSuchElementException>(() => GetDriver().FindElement(By.LinkText("No transfer to Frame.html")));
 }