示例#1
0
        public void SelectItem_ByIndexOnHtmlComboBox_Succeeds()
        {
            //Arrange
            using (var tempFile = new TempFile(
                       @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <select id=""selectId"">
            <option>Cricket</option>
            <option>Football</option>
            <option>Tennis</option>
        </select>
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                //Act
                EnhancedHtmlComboBox comboBox = window.Get <EnhancedHtmlComboBox>("Id=selectId");

                comboBox.SelectItem(1);

                //Assert
                Assert.AreEqual("Football", comboBox.SelectedItem);

                window.Close();
            }
        }
示例#2
0
        public void HtmlParagraph_InnertText_Succeeds()
        {
            WebPage bWin = WebPage.Launch(CurrentDirectory + "/TestHtmlPage.html", "A Test");

            Assert.IsTrue(bWin.Get <EnhancedHtmlParagraph>("Id=para1").InnerText.Contains("EnhancedHtmlParagraph"));
            bWin.Close();
        }
示例#3
0
        public void Launch_UsingNewInstanceOfABrowserWindow_CanUsePartialWindowTitle()
        {
            //Arrange
            using (var tempFile = new TempFile(
                       @"<html>
    <head>
        <title>test 1 2 3</title>
    </head>
    <body>
        <button id=""buttonId"" >Button</button>
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                //Act
                EnhancedHtmlButton button = window.Get <EnhancedHtmlButton>("id=buttonId");

                //Assert
                Assert.AreEqual(button.InnerText, "Button");

                Trace.WriteLine(window.Uri.ToString());

                window.Close();
            }
        }
示例#4
0
        public void HtmlInputButton_ClickInIFrame_Succeeds()
        {
            WebPage bWin = WebPage.Launch(CurrentDirectory + "/iframe_test.html", "iframe Test Main");

            bWin.Get <EnhancedHtmlInputButton>("Value=Log In").Click();
            bWin.Close();
        }
示例#5
0
        public void SelectItem_UsingHtmlComboBoxThatAlertsOnChange_Succeeds()
        {
            //Arrange
            using (var tempFile = new TempFile(
                       @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <select id=""selectId"" onchange=""alert('onchange');"">
            <option>Apple</option>
            <option>Banana</option>
            <option>Carrot</option>
        </select>
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                EnhancedHtmlComboBox comboBox = window.Get <EnhancedHtmlComboBox>("Id=selectId");

                //Act
                comboBox.SelectItem("Banana");

                window.PerformDialogAction(BrowserDialogAction.Ok);

                window.Close();
            }
        }
示例#6
0
        public void HtmlCheckBox_DisabledByStyle_ControlExistsAndCanGetCheckedState()
        {
            //Arrange
            using (var tempFile = new TempFile(
                       @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <input type=""checkbox"" id=""checkBoxId"" disabled=""disabled"" name=""checkBoxName"" checked=""checked"" />
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                //Act
                EnhancedHtmlCheckBox checkBox = window.Get <EnhancedHtmlCheckBox>("id=checkBoxId");

                //Assert
                Assert.IsTrue(checkBox.Exists);
                Assert.IsTrue(checkBox.Checked);

                window.Close();
            }
        }
示例#7
0
        public void SetText_OnHtmlEditWithOverlappedDiv_Succeeds()
        {
            //Arrange
            using (var tempFile = new TempFile(
                       @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <div class=""textbox"" id=""idDiv_PWD_UsernameTb"" style=""margin-bottom: 8px;"">
            <div style=""width: 100%; position: relative;"">
                <input name=""login"" id=""i0116"" style=""ime-mode: inactive;"" type=""email"" maxLength=""113""/>
                <div class=""phholder"" style=""left: 0px; top: 0px; width: 100%; position: absolute; z-index: 5;"">
                    <div class=""placeholder"" id=""idDiv_PWD_UsernameExample"" style=""cursor: text;"">
                    Text - [email protected]
                    </div>
                </div>
            </div>
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var bWin = new WebPage("test");
                EnhancedHtmlEdit txtUserName = bWin.Get <EnhancedHtmlEdit>("id=i0116");

                //Act
                txtUserName.SetText("hello");

                //Assert
                Assert.AreEqual("hello", txtUserName.GetText());

                bWin.Close();
            }
        }
示例#8
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();
            }
        }
示例#9
0
        public void Click_OnHtmlInputButtonWithEqualsSignInSearchParameterValue_Succeeds()
        {
            //Arrange
            using (var tempFile = new TempFile(
                       @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <input type=""submit"" value=""="" onclick=""alert('onclick');""/>
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                EnhancedHtmlInputButton button = window.Get <EnhancedHtmlInputButton>("Value==");

                //Act
                button.Click();

                window.PerformDialogAction(BrowserDialogAction.Ok);

                window.Close();
            }
        }
示例#10
0
        public void SelectedItems_OnHtmlList_Succeeds()
        {
            //Arrange
            using (var tempFile = new TempFile(
                       @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <select id=""selectId"" multiple=""multiple"">
            <option value=""1"">1</option>
            <option value=""2"">2</option>
            <option value=""3"">3</option>
        </select>
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var bWin = new WebPage("test");
                EnhancedHtmlList list = bWin.Get <EnhancedHtmlList>("id=selectId");

                var itemsToSelect = new[] { "1", "2" };

                //Act
                list.SelectedItems = itemsToSelect;

                //Assert
                CollectionAssert.AreEqual(itemsToSelect, list.SelectedItems);

                bWin.Close();
            }
        }
示例#11
0
        public void InnerText_OnHtmlComboBoxWithDisabledItems_Succeeds()
        {
            //Arrange
            using (var tempFile = new TempFile(
                       @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <select id=""selectId"">
            <option value=""1"">1</option>
            <option value=""2"" disabled=""disabled"">2</option>
            <option value=""3"" disabled=""disabled"">3</option>
        </select>
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                EnhancedHtmlComboBox comboBox = window.Get <EnhancedHtmlComboBox>("Id=selectId");

                //Assert
                Assert.AreEqual(3, comboBox.ItemCount);
                CollectionAssert.AreEqual(new[] { "1", "2", "3" }, comboBox.Items);
                Assert.AreEqual("1 2 3 ", comboBox.InnerText);

                window.Close();
            }
        }
示例#12
0
        public void LabelFor_OnHtmlLabel_Succeeds()
        {
            //Arrange
            using (var tempFile = new TempFile(
                       @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <form>
          <label for=""male"">Male</label>
          <input type=""radio"" name=""sex"" id=""male"" value=""male""><br>
          <label for=""female"">Female</label>
          <input type=""radio"" name=""sex"" id=""female"" value=""female""><br>
          <label id=""other"" for=""other"">Other</label>
          <input type=""radio"" name=""sex"" id=""other"" value=""other""><br>
          <input type=""submit"" value=""Submit"">
        </form> 
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                EnhancedHtmlLabel label = window.Get <EnhancedHtmlLabel>("id=other");

                //Assert
                Assert.AreEqual("other", label.LabelFor);

                window.Close();
            }
        }
示例#13
0
        public void ClickAllControlsOnPage_UsingReflection_Succeeds()
        {
            //Arrange
            using (var tempFile = new TempFile(
                       @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <a href=""#"">test</a>
        <button>test</button>
<input type=""text"" value=""test""/>
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                var a = (IEnhancedControlBase)window.Get <EnhancedHtmlHyperlink>("InnerText=test");
                a.Click();

                var list = new List <Type>();
                list.Add(typeof(EnhancedHtmlHyperlink));
                list.Add(typeof(EnhancedHtmlButton));
                list.Add(typeof(EnhancedHtmlEdit));

                MethodInfo getMethodInfo = typeof(WebPage).GetMethod("Get");

                foreach (Type t in list)
                {
                    MethodInfo test = getMethodInfo.MakeGenericMethod(t);

                    IEnhancedControlBase control;

                    if ((t == typeof(EnhancedHtmlEdit)) || (t == typeof(EnhancedHtmlTextArea)))
                    {
                        control = (IEnhancedControlBase)test.Invoke(window, new object[] { "Value=test" });
                    }
                    else
                    {
                        //window.Get<t>("InnerText=test");
                        control = (IEnhancedControlBase)test.Invoke(window, new object[] { "InnerText=test" });
                    }

                    //Act
                    control.Click();

                    if (control is EnhancedHtmlEdit)
                    {
                        (control as EnhancedHtmlEdit).SetText("text");
                    }
                    else if (control is EnhancedHtmlTextArea)
                    {
                        (control as EnhancedHtmlTextArea).SetText("text");
                    }
                }

                window.Close();
            }
        }
示例#14
0
        public void HtmlFileInput_SetFile_Succeeds()
        {
            //Arrange
            using (var tempFile = new TempFile(
                       @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <input name=""inputName"" type=""file"" id=""inputId"" />
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                EnhancedHtmlFileInput fileInput = window.Get <EnhancedHtmlFileInput>("Id=inputId");

                string tempInputFilePath = Path.GetTempFileName();

                //Act
                fileInput.SetFile(tempInputFilePath);

                window.Close();

                File.Delete(tempInputFilePath);
            }
        }
示例#15
0
        public void HtmlButton_HiddenByStyle_ControlExistsAndCanAssertOnStyle()
        {
            //Arrange
            using (var tempFile = new TempFile(
                       @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <button id=""buttonId"" style=""display: none;"" >Hidden</button>
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                //Act
                EnhancedHtmlButton button = window.Get <EnhancedHtmlButton>("id=buttonId");

                //Assert
                Assert.IsTrue(button.Exists);

                Assert.IsTrue(button.UnWrap().ControlDefinition.Contains("style=\"display: none;\""));

                window.Close();
            }
        }
示例#16
0
        public void Launch_TempHtmlFileWithInputWithMaxLength_CanSetTextWhichExceedsMaxLength()
        {
            // Arrange
            using (var tempFile = new TempFile(
                       @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <input id=""input"" type=""text"" maxlength=10 />
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                EnhancedHtmlEdit input = window.Get <EnhancedHtmlEdit>("id=input");

                // Act
                string inputText  = "12345678901";
                string outputText = "1234567890";
                Keyboard.SendKeys(input.UnWrap(), inputText);

                // Assert
                Assert.AreEqual(input.GetText(), outputText);

                window.Close();
            }
        }
示例#17
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();
            }
        }
示例#18
0
        public void Launch_TempHtmlFile_CanFindHyperlinkByHref()
        {
            // Arrange
            using (var tempFile = new TempFile(
                       @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <div class=""login"" style=""border: none;"">
        <div class=""member_box"">
            <span>APPLY FOR MEMBERSHIP</span> <a href=""/registration""> </a>
        </div>
    </body>
</html>"))
            {
                // Act
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                // Assert
                EnhancedHtmlHyperlink SignUpHyperLink = window.Get <EnhancedHtmlHyperlink>("href~registration");
                Assert.IsTrue(SignUpHyperLink.Exists, "SignUp not found");

                window.Close();
            }
        }
示例#19
0
        public void GetHtmlRow_ById_Succeeds()
        {
            // Arrange
            using (var tempFile = new TempFile(
                       @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <table class=""cart"" cellspacing=""0"">
          <tbody>
            <tr id=""555002_gp2"">
                <td>
                    banana
                </td>
            </tr>
          </tbody>
        </table>
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                // Act
                EnhancedHtmlRow row = window.Get <EnhancedHtmlRow>("id=555002_gp2");

                // Assert
                Assert.IsTrue(row.Exists);

                window.Close();
            }
        }
示例#20
0
        public void HtmlTable_ColumnCount_Succeeds()
        {
            WebPage.Launch(CurrentDirectory + "/TestHtmlPage.html");
            var bWin = new WebPage("A Test");
            EnhancedHtmlTable tbl = bWin.Get <EnhancedHtmlTable>("id=calcWithHeaders");

            Assert.AreEqual(3, tbl.ColumnCount);
            bWin.Close();
        }
示例#21
0
        public void HtmlTable_FindRowUsingTableWithoutRowHeaders_Succeeds()
        {
            WebPage           bWin = WebPage.Launch(CurrentDirectory + "/TestHtmlPage.html", "A Test");
            EnhancedHtmlTable tbl  = bWin.Get <EnhancedHtmlTable>("id=calcWithOutHeaders");

            tbl.FindRowAndClick(2, "9", EnhancedHtmlTableSearchOptions.NormalTight);
            Assert.AreEqual("9", tbl.GetCellValue(2, 2).Trim());
            bWin.Close();
        }
示例#22
0
        public void HtmlTable_ClickOnColumnHeader_Succeeds()
        {
            WebPage.Launch(CurrentDirectory + "/TestHtmlPage.html");
            var bWin = new WebPage("A Test");
            EnhancedHtmlTable tbl = bWin.Get <EnhancedHtmlTable>("id=tableWithAlertOnHeaderClick");

            tbl.FindHeaderAndClick(0, 0);
            bWin.PerformDialogAction(BrowserDialogAction.Ok);
            bWin.Close();
        }
示例#23
0
        public void HtmlTable_GetCellValueWithHeaderCell_Succeeds()
        {
            WebPage bWin = WebPage.Launch(CurrentDirectory + "/TestHtmlPage.html", "A Test");

            EnhancedHtmlTable termTable = bWin.Get <EnhancedHtmlTable>("Id=calcWithHeaderCells");

            Assert.AreEqual("3", termTable.GetCellValue(1, 1));

            bWin.Close();
        }
        public void GenericGet_WithHtmlControls_GetsControlsDynamically()
        {
            //Arrange
            WebPage bWin = WebPage.Launch("http://mail.google.com", "Gmail: Email from Google");

            //Act
            bWin.Get <EnhancedHtmlEdit>("Id=Email").SetText("*****@*****.**");
            bWin.Get <EnhancedHtmlPassword>("Id=Password").SetText("MyPa$$Word");
            bWin.Get <EnhancedHtmlInputButton>("Id=signIn").Click();
            bWin.Close();
        }
示例#25
0
        public void HtmlParagraph_TraverseSiblingsParentAndChildren_Succeeds()
        {
            WebPage bWin = WebPage.Launch(CurrentDirectory + "/TestHtmlPage.html", "A Test");
            var     p    = bWin.Get <EnhancedHtmlParagraph>("Id=para1");

            Assert.IsTrue(((EnhancedHtmlEdit)p.PreviousSibling).UnWrap().Name == "text1_test");
            Assert.IsTrue(((EnhancedHtmlInputButton)p.NextSibling).ValueAttribute == "sample button");
            Assert.IsTrue(((EnhancedHtmlDiv)p.Parent).UnWrap().Id == "parentdiv");
            Assert.IsTrue(((EnhancedHtmlPassword)p.Parent.FirstChild).UnWrap().Name == "pass");
            bWin.Close();
        }
示例#26
0
        public void HtmlTable_GetCellValueUsingTableWithTHInTBODY_Succeeds()
        {
            //Arrange
            using (var tempFile = new TempFile(
                       @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <table id=""tableId"" border=""1"">
            <tbody>
                <tr>
                    <th>Lun</th>
                    <th>Used Space</th>
                    <th>Free Space</th>
                    <th>Usage %</th>
                    <th>&nbsp;</th>
                </tr>
                <tr>
                    <td>LUN_04</td>
                    <td>26534605227</td>
                    <td>15405750418</td>
                    <td>
                        <dl>
                            <dd>
                                <dl>
                                    <dd>
                                        <span>64.27%</span>
                                    </dd>
                                </dl>
                            </dd>
                        </dl>
                    </td>
                    <td></td>
                </tr>
            </tbody>
        </table>
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                EnhancedHtmlTable table = window.Get <EnhancedHtmlTable>("id=tableId");

                //Act
                table.FindRowAndClick(0, "LUN_04", EnhancedHtmlTableSearchOptions.NormalTight);

                //Assert
                Assert.AreEqual("LUN_04", table.GetCellValue(1, 0).Trim());

                window.Close();
            }
        }
示例#27
0
        public void HtmlTable_GetColumnHeaders_Succeeds()
        {
            WebPage.Launch(CurrentDirectory + "/TestHtmlPage.html");
            var bWin = new WebPage("A Test");
            EnhancedHtmlTable tbl = bWin.Get <EnhancedHtmlTable>("id=calcWithHeaders");
            var saExpectedValues  = new[] { "Header1", "Header2", "Header3" };

            string[] saHeaders = tbl.GetColumnHeaders();
            Assert.AreEqual(saExpectedValues[0], saHeaders[0]);
            Assert.AreEqual(saExpectedValues[1], saHeaders[1]);
            Assert.AreEqual(saExpectedValues[2], saHeaders[2]);
            bWin.Close();
        }
示例#28
0
        public void HtmlControl_GetChildren_Succeeds()
        {
            WebPage bWin = WebPage.Launch(CurrentDirectory + "/TestHtmlPage.html", "A Test");
            var     div  = bWin.Get <EnhancedHtmlDiv>("id=calculatorContainer1");
            var     col  = div.GetChildren();

            Assert.IsTrue(col[0].GetBaseType().Name == "HtmlDiv");
            Assert.IsTrue(col[1].GetBaseType().Name == "HtmlTable");
            Assert.IsTrue(((EnhancedHtmlDiv)col[0]).InnerText == "calcWithHeaders");
            var tbl = (EnhancedHtmlTable)col[1];

            Assert.AreEqual("6", tbl.GetCellValue(2, 2).Trim());
            bWin.Close();
        }
示例#29
0
        public void HtmlUnorderedList_WithListItems_CanAssertOnListItems()
        {
            WebPage bWin = WebPage.Launch(CurrentDirectory + "/TestHtmlPage.html", "A Test");

            EnhancedHtmlUnorderedList list = bWin.Get <EnhancedHtmlUnorderedList>("id=unorderedList");

            List <EnhancedHtmlListItem> children = (from i in list.GetChildren()
                                                    select i as EnhancedHtmlListItem).ToList();

            Assert.AreEqual(3, children.Count());

            Assert.AreEqual(1, children.Count(x => x.InnerText == "List Item 1"));
            Assert.AreEqual(1, children.Count(x => x.InnerText == "List Item 2"));
            Assert.AreEqual(1, children.Count(x => x.InnerText == "List Item 3"));

            bWin.Close();
        }
示例#30
0
        public void GetChildren_UsingHyperlinks_CanFindHyperlinkByInnerText()
        {
            //Arrange
            using (var tempFile = new TempFile(
                       @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <div id=""div1"">
            <a href=""#"">A - B - C</a>
            <a href=""#"">A - F - E</a>
            <a href=""#"">A - D - E</a>
            <a href=""#"">Z - B - C</a>
            <a href=""#"">Z - D - E</a>
        </div>
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                //Act
                var collection = window.Get <EnhancedHtmlDiv>("id=div1").GetChildren();
                foreach (var control in collection)
                {
                    if (control is EnhancedHtmlHyperlink)
                    {
                        var link = (EnhancedHtmlHyperlink)control;
                        if (link.InnerText.StartsWith("A"))
                        {
                            Trace.WriteLine(string.Format("found: {0}", link.InnerText));
                        }
                    }
                }

                window.Close();
            }
        }
        public void HtmlInputButton_UsingSearchParameterWithValueAsKey_Succeeds()
        {
            //Internet Explorer may display the message: Internet Explorer restricted this webpage from running scripts or ActiveX controls.
            //This security restriction prevents the alert message to appear.
            //To enable running scripts on the local computer, go to Tools > Internet options > Advanced > Security > [checkmark] Allow active content to run in files on My Computer

            //Arrange
            using (var tempFile = new TempFile(
                @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <input type=""submit"" value=""Log In"" onclick=""alert('onclick');""/>
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                EnhancedHtmlInputButton button = window.Get<EnhancedHtmlInputButton>("Value=Log In");

                //Act
                button.Click();

                if (WebPage.GetCurrentBrowser() is InternetExplorer)
                {
                    //read JavaScript alert text
                    var popup = new EnhancedWinWindow("ClassName=#32770;Name=Message from webpage");
                    EnhancedWinText text = popup.Get<EnhancedWinText>();
                    Assert.AreEqual("onclick", text.DisplayText);
                }

                window.PerformDialogAction(BrowserDialogAction.Ok);

                window.Close();
            }
        }
        public void HtmlFileInput_SetFile_Succeeds()
        {
            //Arrange
            using (var tempFile = new TempFile(
                @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <input name=""inputName"" type=""file"" id=""inputId"" />
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                EnhancedHtmlFileInput fileInput = window.Get<EnhancedHtmlFileInput>("Id=inputId");

                string tempInputFilePath = Path.GetTempFileName();

                //Act
                fileInput.SetFile(tempInputFilePath);

                window.Close();

                File.Delete(tempInputFilePath);
            }
        }
        public void ClickAllControlsOnPage_UsingReflection_Succeeds()
        {
            //Arrange
            using (var tempFile = new TempFile(
                @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <a href=""#"">test</a>
        <button>test</button>
<input type=""text"" value=""test""/>
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                var a = (IEnhancedControlBase) window.Get<EnhancedHtmlHyperlink>("InnerText=test");
                a.Click();

                var list = new List<Type>();
                list.Add(typeof (EnhancedHtmlHyperlink));
                list.Add(typeof (EnhancedHtmlButton));
                list.Add(typeof (EnhancedHtmlEdit));

                MethodInfo getMethodInfo = typeof (WebPage).GetMethod("Get");

                foreach (Type t in list)
                {
                    MethodInfo test = getMethodInfo.MakeGenericMethod(t);

                    IEnhancedControlBase control;

                    if ((t == typeof (EnhancedHtmlEdit)) || (t == typeof (EnhancedHtmlTextArea)))
                    {
                        control = (IEnhancedControlBase) test.Invoke(window, new object[] {"Value=test"});
                    }
                    else
                    {
                        //window.Get<t>("InnerText=test");
                        control = (IEnhancedControlBase) test.Invoke(window, new object[] {"InnerText=test"});
                    }

                    //Act
                    control.Click();

                    if (control is EnhancedHtmlEdit)
                    {
                        (control as EnhancedHtmlEdit).SetText("text");
                    }
                    else if (control is EnhancedHtmlTextArea)
                    {
                        (control as EnhancedHtmlTextArea).SetText("text");
                    }
                }

                window.Close();
            }
        }
        public void Click_OnHtmlInputButtonWithEqualsSignInSearchParameterValue_Succeeds()
        {
            //Arrange
            using (var tempFile = new TempFile(
                @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <input type=""submit"" value=""="" onclick=""alert('onclick');""/>
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                EnhancedHtmlInputButton button = window.Get<EnhancedHtmlInputButton>("Value==");

                //Act
                button.Click();

                window.PerformDialogAction(BrowserDialogAction.Ok);

                window.Close();
            }
        }
        public void HtmlTable_FindHeaderAndClick_Succeeds()
        {
            //Arrange
            using (var tempFile = new TempFile(
                @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <table style=""width: 100%;"" id=""tableId"">
            <tbody>
                <tr>
                    <td>Commitment</td>
                    <th>September</th>
                    <th>October</th>
                    <th>November</th>
                    <td>Total</td>
                </tr>
                <tr>
                    <td>Beginning Balance</td>
                    <td>¥21,570,253</td>
                    <td>¥21,375,491</td>
                    <td>¥21,200,873</td>
                    <td></td>
                </tr>
                <tr>
                    <td>New Purchases</td>
                    <td>¥0</td>
                    <td>¥0</td>
                    <td>¥0</td>
                    <td></td>
                </tr>
                <tr>
                    <td>Utilized</td>
                    <td>¥194,762</td>
                    <td>¥174,618</td>
                    <td>¥0</td>
                    <td>¥369,380</td>
                </tr>
                <tr>
                    <td>Ending Balance</td>
                    <td>¥21,375,491</td>
                    <td>¥21,200,873</td>
                    <td>¥21,200,873</td>
                    <td></td>
                </tr>
                <tr>
                    <td><b>Overage</b></td> 
                    <td>¥0</td>
                    <td>¥0</td>
                    <td>¥0</td>
                    <td>¥0</td>
                    <td></td>
                </tr>
                <tr>
                    <td><b>Total Usage</b></td>
                    <td>¥194,762</td>
                    <td>¥174,618</td>
                    <td>¥0</td>
                    <td>¥369,380</td>
                </tr>
            </tbody>
        </table>
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                EnhancedHtmlTable table = window.Get<EnhancedHtmlTable>("id=tableId");

                //Act
                table.FindHeaderAndClick(0, 2);

                window.Close();
            }
        }
 public void HtmlTable_ClickOnColumnHeader_Succeeds()
 {
     WebPage.Launch(CurrentDirectory + "/TestHtmlPage.html");
     var bWin = new WebPage("A Test");
     EnhancedHtmlTable tbl = bWin.Get<EnhancedHtmlTable>("id=tableWithAlertOnHeaderClick");
     tbl.FindHeaderAndClick(0, 0);
     bWin.PerformDialogAction(BrowserDialogAction.Ok);
     bWin.Close();
 }
        public void HtmlButton_HiddenByStyle_ControlExistsAndCanAssertOnStyle()
        {
            //Arrange
            using (var tempFile = new TempFile(
                @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <button id=""buttonId"" style=""display: none;"" >Hidden</button>
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                //Act
                EnhancedHtmlButton button = window.Get<EnhancedHtmlButton>("id=buttonId");

                //Assert
                Assert.IsTrue(button.Exists);

                Assert.IsTrue(button.UnWrap().ControlDefinition.Contains("style=\"display: none;\""));

                window.Close();
            }
        }
        public void HtmlCheckBox_DisabledByStyle_ControlExistsAndCanGetCheckedState()
        {
            //Arrange
            using (var tempFile = new TempFile(
                @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <input type=""checkbox"" id=""checkBoxId"" disabled=""disabled"" name=""checkBoxName"" checked=""checked"" />
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                //Act
                EnhancedHtmlCheckBox checkBox = window.Get<EnhancedHtmlCheckBox>("id=checkBoxId");

                //Assert
                Assert.IsTrue(checkBox.Exists);
                Assert.IsTrue(checkBox.Checked);

                window.Close();
            }
        }
        public void SelectItem_UsingHtmlComboBoxThatAlertsOnChange_Succeeds()
        {
            //Arrange
            using (var tempFile = new TempFile(
                @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <select id=""selectId"" onchange=""alert('onchange');"">
            <option>Apple</option>
            <option>Banana</option>
            <option>Carrot</option>
        </select>
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                EnhancedHtmlComboBox comboBox = window.Get<EnhancedHtmlComboBox>("Id=selectId");

                //Act
                comboBox.SelectItem("Banana");

                window.PerformDialogAction(BrowserDialogAction.Ok);

                window.Close();
            }
        }
        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();
            }
        }
        public void InnerText_OnHtmlComboBoxWithDisabledItems_Succeeds()
        {
            //Arrange
            using (var tempFile = new TempFile(
                @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <select id=""selectId"">
            <option value=""1"">1</option>
            <option value=""2"" disabled=""disabled"">2</option>
            <option value=""3"" disabled=""disabled"">3</option>
        </select>
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                EnhancedHtmlComboBox comboBox = window.Get<EnhancedHtmlComboBox>("Id=selectId");

                //Assert
                Assert.AreEqual(3, comboBox.ItemCount);
                CollectionAssert.AreEqual(new[] {"1", "2", "3"}, comboBox.Items);
                Assert.AreEqual("1 2 3 ", comboBox.InnerText);

                window.Close();
            }
        }
        public void SetText_OnHtmlEditWithOverlappedDiv_Succeeds()
        {
            //Arrange
            using (var tempFile = new TempFile(
                @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <div class=""textbox"" id=""idDiv_PWD_UsernameTb"" style=""margin-bottom: 8px;"">
            <div style=""width: 100%; position: relative;"">
                <input name=""login"" id=""i0116"" style=""ime-mode: inactive;"" type=""email"" maxLength=""113""/>
                <div class=""phholder"" style=""left: 0px; top: 0px; width: 100%; position: absolute; z-index: 5;"">
                    <div class=""placeholder"" id=""idDiv_PWD_UsernameExample"" style=""cursor: text;"">
                    Text - [email protected]
                    </div>
                </div>
            </div>
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var bWin = new WebPage("test");
                EnhancedHtmlEdit txtUserName = bWin.Get<EnhancedHtmlEdit>("id=i0116");

                //Act
                txtUserName.SetText("hello");

                //Assert
                Assert.AreEqual("hello", txtUserName.GetText());

                bWin.Close();
            }
        }
        public void SelectedItems_OnHtmlList_Succeeds()
        {
            //Arrange
            using (var tempFile = new TempFile(
                @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <select id=""selectId"" multiple=""multiple"">
            <option value=""1"">1</option>
            <option value=""2"">2</option>
            <option value=""3"">3</option>
        </select>
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var bWin = new WebPage("test");
                EnhancedHtmlList list = bWin.Get<EnhancedHtmlList>("id=selectId");

                var itemsToSelect = new[] {"1", "2"};

                //Act
                list.SelectedItems = itemsToSelect;

                //Assert
                CollectionAssert.AreEqual(itemsToSelect, list.SelectedItems);

                bWin.Close();
            }
        }
        public void HtmlTable_GetCellValueUsingTableWithTHInTBODY_Succeeds()
        {
            //Arrange
            using (var tempFile = new TempFile(
                @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <table id=""tableId"" border=""1"">
            <tbody>
                <tr>
                    <th>Lun</th>
                    <th>Used Space</th>
                    <th>Free Space</th>
                    <th>Usage %</th>
                    <th>&nbsp;</th>
                </tr>
                <tr>
                    <td>LUN_04</td>
                    <td>26534605227</td>
                    <td>15405750418</td>
                    <td>
                        <dl>
                            <dd>
                                <dl>
                                    <dd>
                                        <span>64.27%</span>
                                    </dd>
                                </dl>
                            </dd>
                        </dl>
                    </td>
                    <td></td>
                </tr>
            </tbody>
        </table>
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                EnhancedHtmlTable table = window.Get<EnhancedHtmlTable>("id=tableId");

                //Act
                table.FindRowAndClick(0, "LUN_04", EnhancedHtmlTableSearchOptions.NormalTight);

                //Assert
                Assert.AreEqual("LUN_04", table.GetCellValue(1, 0).Trim());

                window.Close();
            }
        }
        public void GetHtmlRow_ById_Succeeds()
        {
            // Arrange
            using (var tempFile = new TempFile(
                @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <table class=""cart"" cellspacing=""0"">
          <tbody>
            <tr id=""555002_gp2"">
                <td>
                    banana
                </td>
            </tr>
          </tbody>
        </table>
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                // Act
                EnhancedHtmlRow row = window.Get<EnhancedHtmlRow>("id=555002_gp2");

                // Assert
                Assert.IsTrue(row.Exists);

                window.Close();
            }
        }
        public void Launch_TempHtmlFileWithInputWithMaxLength_CanSetTextWhichExceedsMaxLength()
        {
            // Arrange
            using (var tempFile = new TempFile(
                @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <input id=""input"" type=""text"" maxlength=10 />
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                EnhancedHtmlEdit input = window.Get<EnhancedHtmlEdit>("id=input");

                // Act
                string inputText = "12345678901";
                string outputText = "1234567890";
                Keyboard.SendKeys(input.UnWrap(), inputText);

                // Assert
                Assert.AreEqual(input.GetText(), outputText);

                window.Close();
            }
        }
 public void HtmlTable_ColumnCount_Succeeds()
 {
     WebPage.Launch(CurrentDirectory + "/TestHtmlPage.html");
     var bWin = new WebPage("A Test");
     EnhancedHtmlTable tbl = bWin.Get<EnhancedHtmlTable>("id=calcWithHeaders");
     Assert.AreEqual(3, tbl.ColumnCount);
     bWin.Close();
 }
        public void Launch_UsingNewInstanceOfABrowserWindow_CanUsePartialWindowTitle()
        {
            //Arrange
            using (var tempFile = new TempFile(
                @"<html>
    <head>
        <title>test 1 2 3</title>
    </head>
    <body>
        <button id=""buttonId"" >Button</button>
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                //Act
                EnhancedHtmlButton button = window.Get<EnhancedHtmlButton>("id=buttonId");

                //Assert
                Assert.AreEqual(button.InnerText, "Button");

                Trace.WriteLine(window.Uri.ToString());

                window.Close();
            }
        }
 public void HtmlTable_GetColumnHeaders_Succeeds()
 {
     WebPage.Launch(CurrentDirectory + "/TestHtmlPage.html");
     var bWin = new WebPage("A Test");
     EnhancedHtmlTable tbl = bWin.Get<EnhancedHtmlTable>("id=calcWithHeaders");
     var saExpectedValues = new[] {"Header1", "Header2", "Header3"};
     string[] saHeaders = tbl.GetColumnHeaders();
     Assert.AreEqual(saExpectedValues[0], saHeaders[0]);
     Assert.AreEqual(saExpectedValues[1], saHeaders[1]);
     Assert.AreEqual(saExpectedValues[2], saHeaders[2]);
     bWin.Close();
 }
        public void GetChildren_UsingHyperlinks_CanFindHyperlinkByInnerText()
        {
            //Arrange
            using (var tempFile = new TempFile(
                @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <div id=""div1"">
            <a href=""#"">A - B - C</a>
            <a href=""#"">A - F - E</a>
            <a href=""#"">A - D - E</a>
            <a href=""#"">Z - B - C</a>
            <a href=""#"">Z - D - E</a>
        </div>
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                //Act
                var collection = window.Get<EnhancedHtmlDiv>("id=div1").GetChildren();
                foreach (var control in collection)
                {
                    if (control is EnhancedHtmlHyperlink)
                    {
                        var link = (EnhancedHtmlHyperlink) control;
                        if (link.InnerText.StartsWith("A"))
                        {
                            Trace.WriteLine(string.Format("found: {0}", link.InnerText));
                        }
                    }
                }

                window.Close();
            }
        }
        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();
            }
        }
        public void HtmlInputButton_GetWithValueContainingWhitespace_Succeeds()
        {
            //Arrange
            using (var tempFile = new TempFile(
                @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <input name=""inputName"" type=""submit"" value=""   Search   "" />
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                EnhancedHtmlInputButton button = window.Get<EnhancedHtmlInputButton>("Value=   Search   ");

                //Act
                button.Click();

                window.Close();
            }
        }
        public void Launch_TempHtmlFile_CanFindHyperlinkByHref()
        {
            // Arrange
            using (var tempFile = new TempFile(
                @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <div class=""login"" style=""border: none;"">
        <div class=""member_box"">
            <span>APPLY FOR MEMBERSHIP</span> <a href=""/registration""> </a>
        </div>
    </body>
</html>"))
            {
                // Act
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                // Assert
                EnhancedHtmlHyperlink SignUpHyperLink = window.Get<EnhancedHtmlHyperlink>("href~registration");
                Assert.IsTrue(SignUpHyperLink.Exists, "SignUp not found");

                window.Close();
            }
        }
        public void SelectItem_ByIndexOnHtmlComboBox_Succeeds()
        {
            //Arrange
            using (var tempFile = new TempFile(
                @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <select id=""selectId"">
            <option>Cricket</option>
            <option>Football</option>
            <option>Tennis</option>
        </select>
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                //Act
                EnhancedHtmlComboBox comboBox = window.Get<EnhancedHtmlComboBox>("Id=selectId");

                comboBox.SelectItem(1);

                //Assert
                Assert.AreEqual("Football", comboBox.SelectedItem);

                window.Close();
            }
        }
        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;
            }
        }
        public void LabelFor_OnHtmlLabel_Succeeds()
        {
            //Arrange
            using (var tempFile = new TempFile(
                @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <form>
          <label for=""male"">Male</label>
          <input type=""radio"" name=""sex"" id=""male"" value=""male""><br>
          <label for=""female"">Female</label>
          <input type=""radio"" name=""sex"" id=""female"" value=""female""><br>
          <label id=""other"" for=""other"">Other</label>
          <input type=""radio"" name=""sex"" id=""other"" value=""other""><br>
          <input type=""submit"" value=""Submit"">
        </form> 
    </body>
</html>"))
            {
                WebPage.Launch(tempFile.FilePath);
                var window = new WebPage("test");

                EnhancedHtmlLabel label = window.Get<EnhancedHtmlLabel>("id=other");

                //Assert
                Assert.AreEqual("other", label.LabelFor);

                window.Close();
            }
        }