public void SetTextOnHtmlEdit(string browser)
        {
            //Arrange
            IBrowser previousBrowser = BrowserWindowUnderTest.GetCurrentBrowser();

            try
            {
                string tempFilePath = Path.GetTempFileName();

                File.WriteAllText(tempFilePath,
                                  @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <div id=""div1"">
            <input type=""text""/>
        </div>
    </body>
</html>");

                BrowserWindow.CurrentBrowser = browser;

                BrowserWindowUnderTest window = BrowserWindowUnderTest.Launch(tempFilePath);
                var div          = window.Find <HtmlDiv>(By.Id("div1"));
                var inputTextBox = div.Find <HtmlEdit>();

                //Act
                inputTextBox.Text = "text";

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

                window.Close();

                File.Delete(tempFilePath);
            }
            finally
            {
                BrowserWindow.CurrentBrowser = previousBrowser.Name;
            }
        }
Beispiel #2
0
        public void HtmlInputButton_UsingSearchPropertyWithValueAsKey_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 (TempFile tempFile = new TempFile(
                       @"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <input type=""submit"" value=""Log In"" onclick=""alert('onclick');""/>
    </body>
</html>"))
            {
                BrowserWindow.Launch(tempFile.FilePath);
                var window = new BrowserWindowUnderTest("test");

                HtmlInputButton button = window.Find <HtmlInputButton>(By.ValueAttribute("Log In"));

                //Act
                button.Click();

                if (BrowserWindowUnderTest.GetCurrentBrowser() is InternetExplorer)
                {
                    //read JavaScript alert text
                    WinWindow popup = new WinWindow(By.Name("Message from webpage").AndSearchProperties("ClassName=#32770"));
                    WinText   text  = popup.Find <WinText>();
                    Assert.AreEqual("onclick", text.DisplayText);
                }

                window.PerformDialogAction(BrowserDialogAction.Ok);

                window.Close();
            }
        }