The HtmlPageStub class is used to test HTML page functionality.
Inheritance: HtmlPage
Esempio n. 1
0
        public void DeselectShouldMatchItemByTextWhenItHasValueTest()
        {
            const string Html = @"
<html>
    <head />
    <body>
        <form name='Test'>
            <select name='Data' multiple>
               <option value='1' selected>Test</option>
               <option value='2' selected>Next</option>
            </select>
        </form>
    </body>
</html>";

            var page = new HtmlPageStub(Html);

            var form = page.Find <HtmlForm>().ByName("Test");
            var list = form.Find <HtmlList>().ByName("Data");

            var selectedValues = list.SelectedValues.ToList();

            selectedValues.Count.Should().Be(2);

            list.Deselect("Next");

            selectedValues = list.SelectedValues.ToList();

            selectedValues.Count.Should().Be(1);
            selectedValues[0].Should().Be("1");
        }
Esempio n. 2
0
        public void SelectedValuesShouldReturnTextWhenSelectedValueIsEmptyTest()
        {
            const string Html     = @"
<html>
    <head />
    <body>
        <form name='Test'>
            <select name='Data'>
               <option>1</option>
            </select>
        </form>
    </body>
</html>";
            const string Expected = "1";

            var page = new HtmlPageStub(Html);

            var list = page.Find <HtmlList>().ByName("Data");

            list.Value = Expected;

            var values = list.SelectedValues.ToList();

            values.Count.Should().Be(1);
            values[0].Should().Be(Expected);
        }
Esempio n. 3
0
        public void ValueShouldSelectOptionMatchingTextWhenValueIsEmptyTest()
        {
            const string Html = @"
<html>
    <head />
    <body>
        <form name='Test'>
            <select name='Data'>
               <option>1</option>
            </select>
        </form>
    </body>
</html>";

            var page = new HtmlPageStub(Html);

            var list = page.Find <HtmlList>().ByName("Data");

            list.Value = "1";

            var option = list.Find <AnyHtmlElement>().ByText("1");

            var actual = option.AttributeExists("selected");

            actual.Should().BeTrue();
        }
Esempio n. 4
0
        public void SelectedValuesReturnsImplicitlySelectedItemInDropDownListTest()
        {
            const string Html = @"
<html>
    <head />
    <body>
        <form name='Test'>
            <select name='Data'>
               <option>1</option>
               <option>2</option>
            </select>
        </form>
    </body>
</html>";

            var page = new HtmlPageStub(Html);

            var form = page.Find <HtmlForm>().ByName("Test");
            var list = form.Find <HtmlList>().ByName("Data");

            var values = list.SelectedValues.ToList();

            values.Count.Should().Be(1);
            values[0].Should().Be("1");
        }
Esempio n. 5
0
        public void ByNameExecutesCaseInsensitiveQueryInNodeContextTest()
        {
            const string Html = @"
<html>
    <head />
    <body>
        <form name='Test'>
            <input type='text' id='DataId' name='Data' />
        </form>
        <form name='SecondTest'>
            <input type='checkbox' name='IsSet' />
        </form>
    </body>
</html>
";

            var page = new HtmlPageStub(Html);

            var form = page.Find <HtmlForm>().ByName("Test");

            var actual = form.Find <HtmlFormElement>().ByName("DATA");

            actual.Should().NotBeNull();
            actual.Should().BeAssignableTo <HtmlInput>();
            actual.Name.Should().Be("Data");
        }
Esempio n. 6
0
        public void ByNameWithCaseSensitiveFlagExecutesCaseSensitiveQueryInNodeContextTest()
        {
            const string Html = @"
<html>
    <head />
    <body>
        <form name='Test'>
            <input type='text' id='DataId' name='Data' />
        </form>
        <form name='SecondTest'>
            <input type='checkbox' name='IsSet' />
        </form>
    </body>
</html>
";

            var page = new HtmlPageStub(Html);

            var form = page.Find <HtmlForm>().ByName("Test");

            var actual = form.Find <HtmlFormElement>().ByName("Data", false);

            actual.Should().NotBeNull();
            actual.Should().BeAssignableTo <HtmlInput>();
            actual.Name.Should().Be("Data");

            Action action = () => form.Find <HtmlFormElement>().ByName("DATA", false);

            action.ShouldThrow <InvalidHtmlElementMatchException>();
        }
Esempio n. 7
0
        public void BuildPostDataUsesOptionTextWhenValueIsEmptyTest()
        {
            const string Html = @"
<html>
    <head />
    <body>
        <form name='Test'>
            <select name='Data'>
               <option>1</option>
            </select>
        </form>
    </body>
</html>";

            var page = new HtmlPageStub(Html);

            var form = page.Find <HtmlForm>().ByName("Test");
            var list = form.Find <HtmlList>().ByName("Data");

            list.Value = "1";

            var parameters = form.BuildPostParameters(null).ToList();

            parameters.Should().Contain(x => x.Name == "Data" && x.Value == "1");
        }
Esempio n. 8
0
        public void AllByAttributeWithCaseSensitiveFlagExecutesCaseSensitiveQueryTest()
        {
            const string Html = @"
<html>
    <head />
    <body>
        <form name='Test'>
            <input type='text' name='Data' />
        </form>
        <form name='SecondTest'>
            <input type='checkbox' name='IsSet' />
        </form>
    </body>
</html>";

            var page = new HtmlPageStub(Html);

            var actual = page.Find <HtmlFormElement>().AllByAttribute("name", "IsSet", false).ToList();

            actual.Count.Should().Be(1);
            actual[0].Should().BeAssignableTo <HtmlCheckBox>();
            actual[0].Name.Should().Be("IsSet");

            actual = page.Find <HtmlFormElement>().AllByAttribute("name", "IsSET", false).ToList();

            actual.Count.Should().Be(0);
        }
Esempio n. 9
0
        public void DeselectShouldMatchItemByTextWhenItHasValueTest()
        {
            const string Html = @"
            <html>
            <head />
            <body>
            <form name='Test'>
            <select name='Data' multiple>
               <option value='1' selected>Test</option>
               <option value='2' selected>Next</option>
            </select>
            </form>
            </body>
            </html>";

            var page = new HtmlPageStub(Html);

            var form = page.Find<HtmlForm>().ByName("Test");
            var list = form.Find<HtmlList>().ByName("Data");

            var selectedValues = list.SelectedValues.ToList();

            selectedValues.Count.Should().Be(2);

            list.Deselect("Next");

            selectedValues = list.SelectedValues.ToList();

            selectedValues.Count.Should().Be(1);
            selectedValues[0].Should().Be("1");
        }
Esempio n. 10
0
        public void AllByValueWithCaseSensitiveFlagExecutesCaseSensitiveQueryWithValueFilterTest()
        {
            const string Html = @"
<html>
    <head />
    <body>
        <form value='Test'>
            <input type='text' value='Data' />
        </form>
        <form value='SecondTest'>
            <input type='checkbox' value='IsSet' />
        </form>
    </body>
</html>
";

            var page = new HtmlPageStub(Html);

            var form = page.Find <HtmlForm>().ByValue("Test");

            var actual = form.Find <HtmlFormElement>().AllByValue("Data", false).ToList();

            actual.Count.Should().Be(1);
            actual[0].Should().BeAssignableTo <HtmlInput>();
            actual[0].Value.Should().Be("Data");

            actual = form.Find <HtmlFormElement>().AllByValue("DATA", false).ToList();

            actual.Count.Should().Be(0);
        }
        public void ExecuteOnMultipleTagsReturnsElementsFromTypeHierarchyFromRootTest()
        {
            const string Html = @"
<html>
    <head />
    <body>
        <form name='Test'>
            <input type='text' name='Data' /><input type='checkbox' name='IsSet' />
        </form>
        <form name='Second'>
            <input type='text' name='Data2' /><input type='checkbox' name='IsSet3' />
        </form>
    </body>
</html>
";

            var page = new HtmlPageStub(Html);

            var target = new DefaultHtmlElementFinder <HtmlInput>(page);

            var query = target.BuildElementQuery();

            var actual = target.Execute(query).ToList();

            actual.Count.Should().Be(2);
        }
        public void AllByAttributeExecutesCaseInsensitiveQueryInNodeContextTest()
        {
            const string Html = @"
            <html>
            <head />
            <body>
            <form name='Test'>
            <input type='text' name='Data' />
            </form>
            <form name='SecondTest'>
            <input type='checkbox' name='IsSet' />
            </form>
            </body>
            </html>";

            var page = new HtmlPageStub(Html);

            var form = page.Find<HtmlForm>().ByName("Test");

            var actual = form.Find<HtmlFormElement>().AllByAttribute("name", "data").ToList();

            actual.Count.Should().Be(1);
            actual[0].Should().BeAssignableTo<HtmlInput>();
            actual[0].Name.Should().Be("Data");
        }
Esempio n. 13
0
        public void BuildPostDataUsesOptionTextWhenValueIsEmptyTest()
        {
            const string Html = @"
            <html>
            <head />
            <body>
            <form name='Test'>
            <select name='Data'>
               <option>1</option>
            </select>
            </form>
            </body>
            </html>";

            var page = new HtmlPageStub(Html);

            var form = page.Find<HtmlForm>().ByName("Test");
            var list = form.Find<HtmlList>().ByName("Data");

            list.Value = "1";

            var parameters = form.BuildPostParameters(null).ToList();

            parameters.Should().Contain(x => x.Name == "Data" && x.Value == "1");
        }
Esempio n. 14
0
        public void AllByAttributeExecutesCaseInsensitiveQueryInNodeContextTest()
        {
            const string Html = @"
<html>
    <head />
    <body>
        <form name='Test'>
            <input type='text' name='Data' />
        </form>
        <form name='SecondTest'>
            <input type='checkbox' name='IsSet' />
        </form>
    </body>
</html>";

            var page = new HtmlPageStub(Html);

            var form = page.Find <HtmlForm>().ByName("Test");

            var actual = form.Find <HtmlFormElement>().AllByAttribute("name", "data").ToList();

            actual.Count.Should().Be(1);
            actual[0].Should().BeAssignableTo <HtmlInput>();
            actual[0].Name.Should().Be("Data");
        }
Esempio n. 15
0
        public void CanCreateFromPageTest()
        {
            const string Html = "<html><head /><body><form name='Test' /></body></html>";

            var page = new HtmlPageStub(Html);

            Action action = () => new AncestorHtmlElementFinder <HtmlForm>(page);

            action.ShouldNotThrow();
        }
Esempio n. 16
0
        public void HasClassReturnsFalseWhenElementLacksExactMatchOnClassTest()
        {
            const string Html = "<html class='test-stuff test_more tested' />";

            var page = new HtmlPageStub(Html);

            var target = page.Find<AnyHtmlElement>().Singular();

            target.HasClass("test").Should().BeFalse();
        }
Esempio n. 17
0
        public void HasClassReturnsFalseWhenElementLacksExactMatchOnClassTest()
        {
            const string Html = "<html class='test-stuff test_more tested' />";

            var page = new HtmlPageStub(Html);

            var target = page.Find <AnyHtmlElement>().Singular();

            target.HasClass("test").Should().BeFalse();
        }
Esempio n. 18
0
        public void HasClassReturnsTrueWhenClassAttributeEndsWithSpecifiedClassTest()
        {
            const string Html = "<html class='stuff test' />";

            var page = new HtmlPageStub(Html);

            var target = page.Find<AnyHtmlElement>().Singular();

            target.HasClass("test").Should().BeTrue();
        }
        public void CanCreateFromPageTest()
        {
            const string Html = "<html><head /><body><form name='Test' /></body></html>";

            var page = new HtmlPageStub(Html);

            Action action = () => new DefaultHtmlElementFinder<HtmlForm>(page);

            action.ShouldNotThrow();
        }
Esempio n. 20
0
        public void HasClassReturnsTrueWhenClassAttributeStartsWithSpecifiedClassTest()
        {
            const string Html = "<html class='test stuff' />";

            var page = new HtmlPageStub(Html);

            var target = page.Find <AnyHtmlElement>().Singular();

            target.HasClass("test").Should().BeTrue();
        }
Esempio n. 21
0
        public void HasClassReturnsFalseWhenElementLacksSpecifiedClassTest()
        {
            const string Html = "<html class='haha' />";

            var page = new HtmlPageStub(Html);

            var target = page.Find <AnyHtmlElement>().Singular();

            target.HasClass("test").Should().BeFalse();
        }
Esempio n. 22
0
        public void HasClassReturnsFalseWhenElementLacksSpecifiedClassTest()
        {
            const string Html = "<html class='haha' />";

            var page = new HtmlPageStub(Html);

            var target = page.Find<AnyHtmlElement>().Singular();

            target.HasClass("test").Should().BeFalse();
        }
        public void CanCreateFromHtmlElementTest()
        {
            const string Html = "<form name='Test'></form>";

            var page = new HtmlPageStub(Html);

            var element = new HtmlForm(page, ((IHtmlPage)page).Node);

            Action action = () => new DefaultHtmlElementFinder<HtmlForm>(element);

            action.ShouldNotThrow();
        }
Esempio n. 24
0
        public void CanCreateFromHtmlElementTest()
        {
            const string Html = "<form name='Test'></form>";

            var page = new HtmlPageStub(Html);

            var element = new HtmlForm(page, ((IHtmlPage)page).Node);

            Action action = () => new AncestorHtmlElementFinder <HtmlForm>(element);

            action.ShouldNotThrow();
        }
Esempio n. 25
0
        public void HasClassThrowsExceptionWhenClassNameIsWhiteSpaceTest()
        {
            const string Html = "<html class='test stuff' />";

            var page = new HtmlPageStub(Html);

            var target = page.Find <AnyHtmlElement>().Singular();

            Action action = () => target.HasClass("  ");

            action.ShouldThrow <ArgumentException>();
        }
        public void InputsCanBeFoundOnXHtmlPages()
        {
            // the namespace on the html forces the xml to use namespaces in xpath queries, or use local-name
            const string Html =
                @"<html xmlns=""http://www.w3.org/1999/xhtml""><body><input type=""submit"" name=""test"" value=""foo"" /></body></html>";

            var page = new HtmlPageStub(Html);

            var button = page.Find <HtmlButton>().AllByName("test").ToList();

            button.Count.Should().Be(1);
            button[0].Value.Should().Be("foo");
        }
Esempio n. 27
0
        public void BuildPostDataReturnsEmptySetWhenItemIsSelectedTest()
        {
            const string Html = "<form><select name='data'><option selected='selected' value='test'/></select></form>";

            var page = new HtmlPageStub(Html);

            var form = page.Find<HtmlForm>().Singular();

            var parameters = form.BuildPostParameters(null).ToList();

            // Should only contain an entry for the select, not the option as well
            parameters.Count.Should().Be(1);
        }
Esempio n. 28
0
        public void BuildPostDataReturnsEmptySetWhenItemIsSelectedTest()
        {
            const string Html = "<form><select name='data'><option selected='selected' value='test'/></select></form>";

            var page = new HtmlPageStub(Html);

            var form = page.Find <HtmlForm>().Singular();

            var parameters = form.BuildPostParameters(null).ToList();

            // Should only contain an entry for the select, not the option as well
            parameters.Count.Should().Be(1);
        }
        public void ElementsCanBeFoundOnXHtmlPagesTest()
        {
            // the namespace on the html forces the xml to use namespaces in xpath queries, or use local-name
            const string Html =
                @"<html xmlns=""http://www.w3.org/1999/xhtml""><body><input type=""submit"" name=""test"" value=""foo"" /></body></html>";

            var page = new HtmlPageStub(Html);

            var input = page.Find<HtmlButton>().ByName("test");

            var target = new AncestorHtmlElementFinder<AnyHtmlElement>(input);

            var button = target.AllByTagName("body").ToList();

            button.Count.Should().Be(1);
        }
        public void ExecuteOnSingleTagReturnsSpecificElementTypeTest()
        {
            const string Html = "<html><head /><body><form name='Test' /></body></html>";

            var page = new HtmlPageStub(Html);

            var target = new DefaultHtmlElementFinder <HtmlForm>(page);

            var query = target.BuildElementQuery();

            var actual = target.Execute(query).ToList();

            actual.Count.Should().Be(1);

            actual[0].Name.Should().Be("Test");
        }
Esempio n. 31
0
        public void ElementsCanBeFoundOnXHtmlPagesTest()
        {
            // the namespace on the html forces the xml to use namespaces in xpath queries, or use local-name
            const string Html =
                @"<html xmlns=""http://www.w3.org/1999/xhtml""><body><input type=""submit"" name=""test"" value=""foo"" /></body></html>";

            var page = new HtmlPageStub(Html);

            var input = page.Find <HtmlButton>().ByName("test");

            var target = new AncestorHtmlElementFinder <AnyHtmlElement>(input);

            var button = target.AllByTagName("body").ToList();

            button.Count.Should().Be(1);
        }
        public void ExecuteOnWildcardTagNameDoesNotReturnNodeInContextTest()
        {
            const string Html =
                "<html><head /><body><form name='Test'><input type='text' name='Data' /><input type='checkbox' name='IsSet' /></form></body></html>";

            var page = new HtmlPageStub(Html);

            var form = page.Find <HtmlForm>().ByName("Test");

            var target = new DefaultHtmlElementFinder <AnyHtmlElement>(form);

            var query = target.BuildElementQuery();

            var actual = target.Execute(query).ToList();

            actual.Any(x => x.TagName == "form").Should().BeFalse();
        }
        public void ExecuteOnSingleTagReturnsFilteredRadioButtonsTest()
        {
            const string Html =
                "<html><head /><body><form name='Test'><input type='radio' name='Data' /><input type='radio' name='Data' /></form></body></html>";

            var page = new HtmlPageStub(Html);

            var target = new DefaultHtmlElementFinder <HtmlRadioButton>(page);

            var query = target.BuildElementQuery();

            var actual = target.Execute(query).ToList();

            actual.Count.Should().Be(1);

            actual[0].Name.Should().Be("Data");
        }
        public void ExecuteOnMultipleTagsReturnsElementsFromTypeHierarchyFromSpecificNodeTest()
        {
            const string Html =
                "<html><head /><body><form name='Test'><input type='text' name='Data' /><input type='checkbox' name='IsSet' /></form></body></html>";

            var page = new HtmlPageStub(Html);

            var form = page.Find <HtmlForm>().ByName("Test");

            var target = new DefaultHtmlElementFinder <HtmlInput>(form);

            var query = target.BuildElementQuery();

            var actual = target.Execute(query).ToList();

            actual.Count.Should().Be(1);
        }
        public void ExecuteOnMultipleTagsDoesNotReturnNodeInContextTest()
        {
            const string Html =
                "<html><head /><body><form name='Test'><input type='text' name='Data' /><input type='checkbox' name='IsSet' /></form></body></html>";

            var page = new HtmlPageStub(Html);

            var form = page.Find<HtmlForm>().ByName("Test");

            var target = new DefaultHtmlElementFinder<HtmlElement>(form);

            var query = target.BuildElementQuery();

            var actual = target.Execute(query).ToList();

            actual.Any(x => x.TagName == "form").Should().BeFalse();
        }
Esempio n. 36
0
        public void ExecuteOnMultipleTagsDoesNotReturnNodeInContextTest()
        {
            const string Html =
                "<html><head /><body><form name='Test'><input type='text' name='Data' /><input type='checkbox' name='IsSet' /></form></body></html>";

            var page = new HtmlPageStub(Html);

            var input = page.Find <HtmlInput>().ByName("Data");

            var target = new AncestorHtmlElementFinder <HtmlElement>(input);

            var query = target.BuildElementQuery();

            var actual = target.Execute(query).ToList();

            actual.Any(x => x.TagName == "input").Should().BeFalse();
        }
Esempio n. 37
0
        public void ExecuteOnSingleTagReturnsSpecificElementTypeTest()
        {
            const string Html =
                "<html><head /><body><form name='Test'><input type='text' name='Data' /><input type='checkbox' name='IsSet' /></form></body></html>";

            var page = new HtmlPageStub(Html);

            var input = page.Find <HtmlInput>().ByName("Data");

            var target = new AncestorHtmlElementFinder <HtmlForm>(input);

            var query = target.BuildElementQuery();

            var actual = target.Execute(query).ToList();

            actual.Count.Should().Be(1);
        }
Esempio n. 38
0
        public void ExecuteOnMultipleTagsReturnsElementsFromTypeHierarchyFromSpecificNodeTest()
        {
            const string Html =
                "<html><head /><body><form name='Test'><select name='Data'><option>First</option></select></form></body></html>";

            var page = new HtmlPageStub(Html);

            var input = page.Find <HtmlListItem>().Singular();

            var target = new AncestorHtmlElementFinder <HtmlFormElement>(input);

            var query = target.BuildElementQuery();

            var actual = target.Execute(query).ToList();

            actual.Count.Should().Be(1);
            actual.OfType <HtmlList>().Count().Should().Be(1);
        }
Esempio n. 39
0
        public void AllByTextWithNullCriteriaMatchesEmptyHtmlElementsTest()
        {
            const string Html = @"
<html>
    <body>
        <p id='pascal'></p>
        <p id='lower'>first</p>
    </body>
</html>
";

            var page = new HtmlPageStub(Html);

            var actual = page.Find <HtmlElement>().AllByText(null).ToList();

            actual.Count.Should().Be(1);
            actual[0].Id.Should().Be("pascal");
        }
Esempio n. 40
0
        public void AllByTextWithCaseInsensitiveFlagExecutesCaseInsensitiveSearchTest()
        {
            const string Html = @"
<html>
    <head />
    <body>
        <p id='pascal'>First</p>
        <p id='lower'>first</p>
    </body>
</html>
";

            var page = new HtmlPageStub(Html);

            var actual = page.Find <HtmlElement>().AllByText("first", true).ToList();

            actual.Count.Should().Be(2);
        }
Esempio n. 41
0
        public void ActionTargetReturnsAbsoluteFormActionTest()
        {
            const string Html = @"
            <html>
            <head />
            <body>
            <form name='Test' method='get' action='https://google.com/?existing=stuff'>
            <input type='text' name='data' value='here' />
            <button type='submit' name='Submit' value='Save'>Save</button>
            </form>
            </body>
            </html>";

            var page = new HtmlPageStub(Html);

            var form = page.Find<HtmlForm>().ByName("Test");

            form.ActionTarget.ToString().Should().Be("https://google.com/?existing=stuff");
        }
Esempio n. 42
0
        public void ActionTargetReturnsTargetLocationWhenWithNoActionAttributeTest()
        {
            const string Html = @"
<html>
    <head />
    <body>
        <form name='Test' method='get'>
            <input type='text' name='data' value='here' />
            <button type='submit' name='Submit' value='Save'>Save</button>
        </form>
    </body>
</html>";

            var page = new HtmlPageStub(Html);

            var form = page.Find <HtmlForm>().ByName("Test");

            form.ActionTarget.ToString().Should().Be(page.TargetLocation.ToString());
        }
Esempio n. 43
0
        public void ActionTargetReturnsTargetLocationCombinedWithRelativeActionAttributeTest()
        {
            const string Html = @"
            <html>
            <head />
            <body>
            <form name='Test' method='get' action='more/here'>
            <input type='text' name='data' value='here' />
            <button type='submit' name='Submit' value='Save'>Save</button>
            </form>
            </body>
            </html>";

            var page = new HtmlPageStub(Html);

            var form = page.Find<HtmlForm>().ByName("Test");

            form.ActionTarget.ToString().Should().Be(page.TargetLocation + "more/here");
        }
        public void ExecuteOnMultipleTagsReturnsAnyElementsFromTypeHierarchyFromRootTest()
        {
            const string Html =
                "<html><head /><body><form name='Test'><input type='text' name='Data' /><input type='checkbox' name='IsSet' /></form></body></html>";

            var page = new HtmlPageStub(Html);

            var target = new DefaultHtmlElementFinder<HtmlElement>(page);

            var query = target.BuildElementQuery();

            var actual = target.Execute(query).ToList();

            actual.Count.Should().Be(6);

            actual.OfType<HtmlInput>().Any().Should().BeTrue();
            actual.OfType<HtmlCheckBox>().Any().Should().BeTrue();
            actual.OfType<HtmlForm>().Any().Should().BeTrue();
            actual.OfType<AnyHtmlElement>().Count().Should().Be(3);
        }
        public void ExecuteOnSingleTagReturnsSpecificElementTypeTest()
        {
            const string Html =
                "<html><head /><body><form name='Test'><input type='text' name='Data' /><input type='checkbox' name='IsSet' /></form></body></html>";

            var page = new HtmlPageStub(Html);

            var input = page.Find<HtmlInput>().ByName("Data");

            var target = new AncestorHtmlElementFinder<HtmlForm>(input);

            var query = target.BuildElementQuery();

            var actual = target.Execute(query).ToList();

            actual.Count.Should().Be(1);
        }
Esempio n. 46
0
        public void IndexerShouldMatchListItemByTextWhenItHasValueTest()
        {
            const string Html = @"
            <html>
            <head />
            <body>
            <form name='Test'>
            <select name='Data'>
               <option value='1'>Test</option>
            </select>
            </form>
            </body>
            </html>";

            var page = new HtmlPageStub(Html);

            var form = page.Find<HtmlForm>().ByName("Test");
            var list = form.Find<HtmlList>().ByName("Data");

            var item = list["Test"];

            item.Should().NotBeNull();
            item.Value.Should().Be("1");
        }
        public void InputsCanBeFoundOnXHtmlPages()
        {
            // the namespace on the html forces the xml to use namespaces in xpath queries, or use local-name
            const string Html =
                @"<html xmlns=""http://www.w3.org/1999/xhtml""><body><input type=""submit"" name=""test"" value=""foo"" /></body></html>";

            var page = new HtmlPageStub(Html);

            var button = page.Find<HtmlButton>().AllByName("test").ToList();

            button.Count.Should().Be(1);
            button[0].Value.Should().Be("foo");
        }
        public void ExecuteOnSingleTagReturnsFilteredRadioButtonsTest()
        {
            const string Html =
                "<html><head /><body><form name='Test'><input type='radio' name='Data' /><input type='radio' name='Data' /></form></body></html>";

            var page = new HtmlPageStub(Html);

            var target = new DefaultHtmlElementFinder<HtmlRadioButton>(page);

            var query = target.BuildElementQuery();

            var actual = target.Execute(query).ToList();

            actual.Count.Should().Be(1);

            actual[0].Name.Should().Be("Data");
        }
        public void ExecuteOnSingleTagReturnsSpecificElementTypeTest()
        {
            const string Html = "<html><head /><body><form name='Test' /></body></html>";

            var page = new HtmlPageStub(Html);

            var target = new DefaultHtmlElementFinder<HtmlForm>(page);

            var query = target.BuildElementQuery();

            var actual = target.Execute(query).ToList();

            actual.Count.Should().Be(1);

            actual[0].Name.Should().Be("Test");
        }
        public void ExecuteOnMultipleTagsReturnsAnyElementsFromTypeHierarchyFromSpecificNodeTest()
        {
            const string Html =
                "<html><head /><body><form name='Test'><input type='text' name='Data' /><input type='checkbox' name='IsSet' /></form><form name='other'><input type='hidden' name='source' value'here' /></form></body></html>";

            var page = new HtmlPageStub(Html);

            var input = page.Find<HtmlInput>().ByName("Data");

            var target = new AncestorHtmlElementFinder<HtmlElement>(input);

            var query = target.BuildElementQuery();

            var actual = target.Execute(query).ToList();

            actual.Count.Should().Be(3);

            actual.OfType<HtmlForm>().Count().Should().Be(1);
            actual.OfType<AnyHtmlElement>().Count(x => x.TagName == "body").Should().Be(1);
            actual.OfType<AnyHtmlElement>().Count(x => x.TagName == "html").Should().Be(1);
        }
        public void ExecuteOnMultipleTagsReturnsElementsFromTypeHierarchyFromSpecificNodeTest()
        {
            const string Html =
                "<html><head /><body><form name='Test'><input type='text' name='Data' /><input type='checkbox' name='IsSet' /></form></body></html>";

            var page = new HtmlPageStub(Html);

            var form = page.Find<HtmlForm>().ByName("Test");

            var target = new DefaultHtmlElementFinder<HtmlInput>(form);

            var query = target.BuildElementQuery();

            var actual = target.Execute(query).ToList();

            actual.Count.Should().Be(1);
        }
Esempio n. 52
0
        public void ValuesShouldReturnTextWhenValueIsEmptyTest()
        {
            const string Html = @"
            <html>
            <head />
            <body>
            <form name='Test'>
            <select name='Data'>
               <option>1</option>
            </select>
            </form>
            </body>
            </html>";
            const string Expected = "1";

            var page = new HtmlPageStub(Html);

            var list = page.Find<HtmlList>().ByName("Data");

            var values = list.Values.ToList();

            values.Count.Should().Be(1);
            values[0].Should().Be(Expected);
        }
Esempio n. 53
0
        public void SelectedValuesReturnsExplicitlySelectedItemTest()
        {
            const string Html = @"
            <html>
            <head />
            <body>
            <form name='Test'>
            <select name='Data'>
               <option>1</option>
               <option selected>2</option>
            </select>
            </form>
            </body>
            </html>";

            var page = new HtmlPageStub(Html);

            var form = page.Find<HtmlForm>().ByName("Test");
            var list = form.Find<HtmlList>().ByName("Data");

            var values = list.SelectedValues.ToList();

            values.Count.Should().Be(1);
            values[0].Should().Be("2");
        }
Esempio n. 54
0
        public void HasClassReturnsTrueWhenElementHasClassTest()
        {
            const string Html = "<html class='test' />";

            var page = new HtmlPageStub(Html);

            var target = page.Find<AnyHtmlElement>().Singular();

            target.HasClass("test").Should().BeTrue();
        }
        public void ExecuteOnMultipleTagsReturnsElementsFromTypeHierarchyFromSpecificNodeTest()
        {
            const string Html =
                "<html><head /><body><form name='Test'><select name='Data'><option>First</option></select></form></body></html>";

            var page = new HtmlPageStub(Html);

            var input = page.Find<HtmlListItem>().Singular();

            var target = new AncestorHtmlElementFinder<HtmlFormElement>(input);

            var query = target.BuildElementQuery();

            var actual = target.Execute(query).ToList();

            actual.Count.Should().Be(1);
            actual.OfType<HtmlList>().Count().Should().Be(1);
        }
Esempio n. 56
0
        public void ValueReturnsEmptyWithMultiselectAndNoExplicitlySelectedItemsTest()
        {
            const string Html = @"
            <html>
            <head />
            <body>
            <form name='Test'>
            <select name='Data' multiple>
               <option>1</option>
               <option>2</option>
            </select>
            </form>
            </body>
            </html>";

            var page = new HtmlPageStub(Html);

            var form = page.Find<HtmlForm>().ByName("Test");
            var list = form.Find<HtmlList>().ByName("Data");

            list.Value.Should().BeEmpty();
        }
Esempio n. 57
0
        public void ValueReturnsImplicitlySelectedItemInDropDownListTest()
        {
            const string Html = @"
            <html>
            <head />
            <body>
            <form name='Test'>
            <select name='Data'>
               <option>1</option>
               <option>2</option>
            </select>
            </form>
            </body>
            </html>";

            var page = new HtmlPageStub(Html);

            var form = page.Find<HtmlForm>().ByName("Test");
            var list = form.Find<HtmlList>().ByName("Data");

            list.Value.Should().Be("1");
        }
Esempio n. 58
0
        public void HasClassThrowsExceptionWhenClassNameIsWhiteSpaceTest()
        {
            const string Html = "<html class='test stuff' />";

            var page = new HtmlPageStub(Html);

            var target = page.Find<AnyHtmlElement>().Singular();

            Action action = () => target.HasClass("  ");

            action.ShouldThrow<ArgumentException>();
        }
        public void ExecuteOnWildcardTagNameDoesNotReturnNodeInContextTest()
        {
            const string Html =
                "<html><head /><body><form name='Test'><input type='text' name='Data' /><input type='checkbox' name='IsSet' /></form></body></html>";

            var page = new HtmlPageStub(Html);

            var input = page.Find<HtmlInput>().ByName("Data");

            var target = new AncestorHtmlElementFinder<HtmlInput>(input);

            var query = target.BuildElementQuery();

            var actual = target.Execute(query).ToList();

            actual.Any(x => x.TagName == "input").Should().BeFalse();
        }
Esempio n. 60
0
        public void ValueShouldSelectOptionMatchingTextWhenValueIsEmptyTest()
        {
            const string Html = @"
            <html>
            <head />
            <body>
            <form name='Test'>
            <select name='Data'>
               <option>1</option>
            </select>
            </form>
            </body>
            </html>";

            var page = new HtmlPageStub(Html);

            var list = page.Find<HtmlList>().ByName("Data");

            list.Value = "1";

            var option = list.Find<AnyHtmlElement>().ByText("1");

            var actual = option.AttributeExists("selected");

            actual.Should().BeTrue();
        }