示例#1
0
        public void FindElement()
        {
            var htmlNode = new HtmlNodeBuilder("<html><body><div id=\"page-body\">Hello world</div></body></html>").Build();

            var document = new WebElement(htmlNode, null);
            var div = document.FindElement(By.Id("page-body"));

            Assert.That(div.TagName, Is.EqualTo("div"));
            Assert.That(div.Text, Is.EqualTo("Hello world"));
        }
示例#2
0
        public void FindElementShouldReturnNullIfNoElementsAreReturned()
        {
            var htmlNode = new HtmlNodeBuilder("<html><body>" +
                   "<a href=\"http://www.google.com\">google</a>" +
                   "</body></html>").Build();

            var document = new WebElementFinder(htmlNode,null);
            var paragraph = document.FindElement(By.TagName("p"));

            Assert.That(paragraph, Is.EqualTo(null));
        }
示例#3
0
        public void ClickShouldFollowHrefs()
        {
            var nav = new Mock<INavigation>();

            var htmlNode = new HtmlNodeBuilder("<a href=\"http://www.google.com\">google</a>").Build();

            var webElement = new WebElement(htmlNode, nav.Object);
            webElement.Click();

            nav.Verify( x => x.GoToUrl(htmlNode.Attributes["href"].Value), Times.Once(), "Click() should cause INavigator to go to the url.");
        }
示例#4
0
        public void ClickShouldBeIgnoredWhenNotApplicable()
        {
            var nav = new Mock<INavigation>();

            var htmlNode = new HtmlNodeBuilder("<div>This is not a link</div>").Build();

            var webElement = new WebElement(htmlNode, nav.Object);
            webElement.Click();

            nav.Verify(x => x.GoToUrl(It.IsAny<string>()), Times.Never(),
                "Click should not do anything when not applied to a link.");
        }
示例#5
0
        public void FindElements()
        {
            var htmlNode = new HtmlNodeBuilder("<html><body>" +
                                           "<ul><li class=\"nav-item\">Item 1</li><li class=\"nav-item\">Item 2</li></ul>" +
                                           "</body></html>").Build();

            var document = new WebElement(htmlNode, null);
            var list = document.FindElements(By.ClassName("nav-item"));

            Assert.That(list.Count, Is.EqualTo(2));
            Assert.That(list[0].TagName, Is.EqualTo("li"));
            Assert.That(list[1].TagName, Is.EqualTo("li"));
        }
示例#6
0
        public void GetAttribute()
        {
            var htmlNode = new HtmlNodeBuilder("<a href=\"http://www.google.com\">Google</a>").Build();

            var element = new WebElement(htmlNode, null);

            Assert.That(element.GetAttribute("href"), Is.EqualTo("http://www.google.com"));
        }
示例#7
0
        public void Text()
        {
            var htmlNode = new HtmlNodeBuilder("<div>\r\nHello World        \r\n</div>").Build();

            var element = new WebElement(htmlNode, null);
            var textInAnElement = element.Text;

            Assert.That(textInAnElement, Is.EqualTo("Hello World"));
        }
示例#8
0
        public void TagName()
        {
            var htmlNode = new HtmlNodeBuilder("<div>Hello DIV Tag</div>").Build();

            var element = new WebElement(htmlNode, null);

            Assert.That(element.TagName, Is.EqualTo("div"));
        }
        public void ReadMethodFromForm()
        {
            var formHtml = new HtmlNodeBuilder("<form method=\"post\" action=\"result.aspx\"></form>").Build();
            var reader = new FormPostDataReader(formHtml);

            Assert.That(reader.Method, Is.EqualTo("post"));
        }
示例#10
0
        public void ReadPostDataFromSelectFieldsWithOptionsWithValueAttribute()
        {
            var formHtml = new HtmlNodeBuilder("<form method=\"post\" action=\"result.aspx\">" +
                                               "<select id=\"salary\">" +
                                               "<option value=\"20000\">£20,000</option>" +
                                               "<option value=\"30000\">£30,000</option>" +
                                               "<option value=\"40000+\" selected>£40,000+</option>" +
                                               "</select>" +
                                               "</form>").Build();
            var reader = new FormPostDataReader(formHtml);
            var postData = reader.PostData;

            Assert.That(postData["salary"], Is.EqualTo("40000+"));
        }
示例#11
0
        public void ReadPostDataFromInputFields()
        {
            var formHtml = new HtmlNodeBuilder("<form method=\"post\" action=\"result.aspx\">" +
                                               "<input id=\"login\" type=\"text\" value=\"helephant\" />" +
                                               "<input id=\"password\" type=\"password\" value=\"i love joe\" />" +
                                               "</form>").Build();
            var reader = new FormPostDataReader(formHtml);
            var postData = reader.PostData;

            Assert.That(postData["login"], Is.EqualTo("helephant"));
            Assert.That(postData["password"], Is.EqualTo("i love joe"));
        }