Beispiel #1
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);
        }
Beispiel #2
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();
        }
Beispiel #3
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");
        }
Beispiel #4
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);
        }
Beispiel #5
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");
        }
Beispiel #6
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");
        }
Beispiel #7
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);
        }
Beispiel #8
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");
        }
Beispiel #9
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");
        }
Beispiel #10
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>();
        }
Beispiel #11
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");
        }
Beispiel #12
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");
        }
        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");
        }
        public void HasClassReturnsTrueWhenClassAttributeContainsSpecifiedClassTest()
        {
            const string Html = "<html class='stuff test works' />";

            var page = new HtmlPageStub(Html);

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

            target.HasClass("test").Should().BeTrue();
        }
Beispiel #15
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 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();
        }
        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();
        }
Beispiel #18
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();
        }
Beispiel #19
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();
        }
Beispiel #20
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>();
        }
Beispiel #21
0
        public void BuildGetLocationReturnsActionWithClickedButtonAndNoOtherFormElementsTest()
        {
            const string Html = @"
<html>
    <head />
    <body>
        <form name='Test' method='get' action='https://google.com/'>
            <button type='submit' name='Submit' value='Save'>Save</button>
        </form>
    </body>
</html>";

            var page = new HtmlPageStub(Html);

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

            var location = form.BuildGetLocation(button);

            location.ToString().Should().Be("https://google.com/?Submit=Save");
        }
Beispiel #22
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 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 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");
        }
Beispiel #25
0
        public void ByTextWithCaseSensitiveFlagExecutesCaseSensitiveQueryInNodeContextTest()
        {
            const string Html = @"
<html>
    <head />
    <body>
        <p id='target'>Stuff</p>
        <p>More</p>
    </body>
</html>
";

            var page = new HtmlPageStub(Html);

            var actual = page.Find <AnyHtmlElement>().ByText("Stuff", false);

            actual.Should().NotBeNull();
            actual.Should().BeAssignableTo <AnyHtmlElement>();
            actual.Id.Should().Be("target");

            Action action = () => page.Find <AnyHtmlElement>().ByText("stuff", false);

            action.ShouldThrow <InvalidHtmlElementMatchException>();
        }
Beispiel #26
0
        public void BuildPostEntriesIncludesClickedButtonTest()
        {
            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");
            var button = page.Find <HtmlButton>().Singular();

            var entries = form.BuildPostParameters(button).ToList();

            entries.Count.Should().Be(2);
            entries.Any(x => x.Name == "data").Should().BeTrue();
            entries.Any(x => x.Name == "Submit").Should().BeTrue();
        }
Beispiel #27
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 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 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 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();
        }
Beispiel #31
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);
        }
Beispiel #32
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();
        }
        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();
        }
Beispiel #34
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);
        }
Beispiel #35
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");
        }
Beispiel #36
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);
        }
Beispiel #37
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());
        }
Beispiel #38
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");
        }
Beispiel #39
0
        public void BuildGetLocationReturnsActionWithNoFormElementsTest()
        {
            const string Html = @"
<html>
    <head />
    <body>
        <form name='Test' method='get' action='https://google.com/'>
        </form>
    </body>
</html>";

            var page = new HtmlPageStub(Html);

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

            var location = form.BuildGetLocation(null);

            location.ToString().Should().Be("https://google.com/");
        }
Beispiel #40
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");
        }
Beispiel #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");
        }
Beispiel #42
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();
        }
        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();
        }
        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);
        }
        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);
        }
Beispiel #46
0
        public void BuildPostEntriesIncludesClickedButtonTest()
        {
            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");
            var button = page.Find<HtmlButton>().Singular();

            var entries = form.BuildPostParameters(button).ToList();

            entries.Count.Should().Be(2);
            entries.Any(x => x.Name == "data").Should().BeTrue();
            entries.Any(x => x.Name == "Submit").Should().BeTrue();
        }
Beispiel #47
0
        public void BuildGetLocationReturnsActionWithNoFormElementsTest()
        {
            const string Html = @"
            <html>
            <head />
            <body>
            <form name='Test' method='get' action='https://google.com/'>
            </form>
            </body>
            </html>";

            var page = new HtmlPageStub(Html);

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

            var location = form.BuildGetLocation(null);

            location.ToString().Should().Be("https://google.com/");
        }
Beispiel #48
0
        public void BuildGetLocationExcludesButtonWhenSubmittedDirectlyTest()
        {
            const string Html = @"
            <html>
            <head />
            <body>
            <form name='Test' method='get' action='https://google.com/'>
            <button type='submit' name='Submit' value='Save'>Save</button>
            </form>
            </body>
            </html>";

            var page = new HtmlPageStub(Html);

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

            var location = form.BuildGetLocation(null);

            location.ToString().Should().Be("https://google.com/");
        }
        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 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 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 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);
        }
Beispiel #53
0
        public void BuildGetLocationReturnsActionWithClickedButtonAndNoOtherFormElementsTest()
        {
            const string Html = @"
            <html>
            <head />
            <body>
            <form name='Test' method='get' action='https://google.com/'>
            <button type='submit' name='Submit' value='Save'>Save</button>
            </form>
            </body>
            </html>";

            var page = new HtmlPageStub(Html);

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

            var location = form.BuildGetLocation(button);

            location.ToString().Should().Be("https://google.com/?Submit=Save");
        }
Beispiel #54
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");
        }
Beispiel #55
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();
        }
Beispiel #56
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");
        }
        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);
        }
Beispiel #58
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);
        }
Beispiel #59
0
        public void BuildGetLocationReturnsActionWithUrlEncodedPostElementsTest()
        {
            const string Html = @"
            <html>
            <head />
            <body>
            <form name='Test' method='get' action='https://google.com/'>
            <input type='text' name='da ta' value='he re' />
            <button type='submit' name='Submit' value='Save'>Save</button>
            </form>
            </body>
            </html>";

            var page = new HtmlPageStub(Html);

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

            var location = form.BuildGetLocation(null);

            location.ToString().Should().Be("https://google.com/?da+ta=he+re");
        }
Beispiel #60
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");
        }