Exemple #1
0
        public async Task ShouldAllowTheUserToGetTheTextOfAPrompt()
        {
            await driver.GoToUrl(CreatePromptPage(null));

            await driver.FindElement(By.Id("prompt")).Click();

            IAlert alert = await WaitFor(AlertToBePresent(), "No alert found");

            string value = await alert.Text();

            await alert.Accept();

            Assert.AreEqual("Enter something", value);
        }
Exemple #2
0
        public async Task ShouldAllowTheUserToGetTheTextOfAnAlert()
        {
            await driver.GoToUrl(CreateAlertPage("cheese"));

            await driver.FindElement(By.Id("alert")).Click();

            IAlert alert = await WaitFor(AlertToBePresent(), "No alert found");

            string value = await alert.Text();

            await alert.Accept();

            Assert.AreEqual("cheese", value);
        }
Exemple #3
0
        public async Task ShouldHandleAlertOnPageLoadUsingGet()
        {
            await driver.GoToUrl(EnvironmentManager.Instance.UrlBuilder.CreateInlinePage(new InlinePage()
                                                                                         .WithOnLoad("javascript:alert(\"onload\")")
                                                                                         .WithBody("<p>Page with onload event handler</p>")));

            IAlert alert = await WaitFor(AlertToBePresent(), "No alert found");

            string value = await alert.Text();

            await alert.Accept();

            Assert.AreEqual("onload", value);
            await WaitFor(ElementTextToEqual(await driver.FindElement(By.TagName("p")), "Page with onload event handler"), "Could not find element with text 'Page with onload event handler'");
        }
Exemple #4
0
        public async Task AlertShouldNotAllowAdditionalCommandsIfDimissed()
        {
            await driver.GoToUrl(CreateAlertPage("cheese"));

            await driver.FindElement(By.Id("alert")).Click();

            IAlert alert = await WaitFor(AlertToBePresent(), "No alert found");

            await alert.Dismiss();

            string text;
            //Assert.That(async () => text = await alert.Text(), Throws.InstanceOf<NoAlertPresentException>());
            await AssertEx.ThrowsAsync <WebBrowserException>(async() => text = await alert.Text(),
                                                             exception => Assert.AreEqual("no such element", exception.Error));
        }
Exemple #5
0
        public async Task ShouldHandleAlertOnFormSubmit()
        {
            await driver.GoToUrl(EnvironmentManager.Instance.UrlBuilder.CreateInlinePage(new InlinePage()
                                                                                         .WithTitle("Testing Alerts").
                                                                                         WithBody("<form id='theForm' action='javascript:alert(\"Tasty cheese\");'>",
                                                                                                  "<input id='unused' type='submit' value='Submit'>",
                                                                                                  "</form>")));

            IWebElement element = await driver.FindElement(By.Id("theForm"));

            await element.Submit();

            IAlert alert = await driver.SwitchTo().Alert();

            string text = await alert.Text();

            await alert.Accept();

            Assert.AreEqual("Tasty cheese", text);
            Assert.AreEqual("Testing Alerts", await driver.Title());
        }
Exemple #6
0
        public async Task ShouldHandleAlertOnPageLoad()
        {
            string pageWithOnLoad = EnvironmentManager.Instance.UrlBuilder.CreateInlinePage(new InlinePage()
                                                                                            .WithOnLoad("javascript:alert(\"onload\")")
                                                                                            .WithBody("<p>Page with onload event handler</p>"));
            await driver.GoToUrl(EnvironmentManager.Instance.UrlBuilder.CreateInlinePage(new InlinePage()
                                                                                         .WithBody(string.Format("<a id='open-page-with-onload-alert' href='{0}'>open new page</a>", pageWithOnLoad))));

            await driver.FindElement(By.Id("open-page-with-onload-alert")).Click();

            IAlert alert = await WaitFor(AlertToBePresent(), "No alert found");

            string value = await alert.Text();

            await alert.Accept();

            Assert.AreEqual("onload", value);
            IWebElement element = await driver.FindElement(By.TagName("p"));

            await WaitFor(ElementTextToEqual(element, "Page with onload event handler"), "Element text was not 'Page with onload event handler'");
        }
Exemple #7
0
        public async Task HandleFormWithJavascriptAction()
        {
            string url = EnvironmentManager.Instance.UrlBuilder.WhereIs("form_handling_js_submit.html");
            await driver.GoToUrl(url);

            IWebElement element = await driver.FindElement(By.Id("theForm"));

            await element.Submit();

            IAlert alert = await WaitFor(async() => {
                try {
                    return(await driver.SwitchTo().Alert());
                } catch (NoAlertPresentException) {
                    return(null);
                }
            }, "No alert found before timeout.");

            string text = await alert.Text();

            await alert.Dismiss();

            Assert.AreEqual("Tasty cheese", text);
        }