예제 #1
0
        public void GetHtmlDiv_ByClass_Succeeds()
        {
            // Arrange
            using (var tempFile = new TempFile(
                       @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <div class=""button""><a href=""/main"">main text</a></div>
        <div class=""button""><a href=""/about"">about text</a></div>
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                // Act
                EnhancedHtmlDiv div = window.Get <EnhancedHtmlDiv>("class=button");

                EnhancedHtmlHyperlink about = window.Get <EnhancedHtmlHyperlink>("InnerText=about text;href~about");
                var div2 = about.Parent as EnhancedHtmlDiv;

                // Assert
                Assert.IsTrue(div.Exists);
                Assert.AreEqual("main text", div.UnWrap().InnerText);

                Assert.IsTrue(about.Exists);

                Assert.IsTrue(div2.Exists);
                Assert.AreEqual("about text", div2.UnWrap().InnerText);

                window.Close();
            }
        }
예제 #2
0
        public void SetText_OnHtmlEdit_Succeeds()
        {
            //Arrange
            using (var tempFile = new TempFile(
                       @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <div id=""div1"">
            <input type=""text""/>
        </div>
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var              window       = new WebPage("test");
                EnhancedHtmlDiv  div          = window.Get <EnhancedHtmlDiv>("id=div1");
                EnhancedHtmlEdit inputTextBox = div.Get <EnhancedHtmlEdit>();

                //Act
                inputTextBox.SetText("text");

                //Assert
                Assert.AreEqual("text", inputTextBox.GetText());

                window.Close();
            }
        }
예제 #3
0
        public void HtmlControl_NonExistent_DoesNotExist()
        {
            //Arrange
            var smartMatchOptions = SmartMatchOptions.Control;

            try
            {
                //set SmartMatchOptions to None because we are using .Exists on an invalid control
                //remember previous setting so that it can be reset
                smartMatchOptions = Playback.PlaybackSettings.SmartMatchOptions;
                Playback.PlaybackSettings.SmartMatchOptions = SmartMatchOptions.None;

                using (var tempFile = new TempFile(
                           @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
    </body>
</html>"))
                {
                    WebPage.Launch(tempFile.FilePath);
                    var window = new WebPage("test");

                    //Act
                    EnhancedHtmlDiv div = window.Get <EnhancedHtmlDiv>("Id=invalid");

                    //Assert
                    Assert.IsFalse(div.Exists);

                    window.Close();
                }
            }
            finally
            {
                //reset default setting
                Playback.PlaybackSettings.SmartMatchOptions = smartMatchOptions;
            }
        }