Search in sources :

Example 71 with Alerts

use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.

the class HtmlPasswordInputTest method maxLengthValidationInvalid.

/**
 * @throws Exception if an error occurs
 */
@Test
@Alerts({ "abcde", "§§URL§§second/", "2" })
public void maxLengthValidationInvalid() throws Exception {
    final String html = "<!DOCTYPE html>\n" + "<html><head></head>\n" + "<body>\n" + "  <form id='myForm' action='" + URL_SECOND + "' method='" + HttpMethod.POST + "'>\n" + "    <input type='password' maxlength='5' id='foo'>\n" + "    <button id='myButton' type='submit'>Submit</button>\n" + "  </form>\n" + "</body></html>";
    final String secondContent = "<html><head><title>second</title></head><body>\n" + "  <p>hello world</p>\n" + "</body></html>";
    getMockWebConnection().setResponse(URL_SECOND, secondContent);
    expandExpectedAlertsVariables(URL_FIRST);
    final WebDriver driver = loadPage2(html, URL_FIRST);
    final WebElement foo = driver.findElement(By.id("foo"));
    foo.sendKeys("abcdefghi");
    assertEquals(getExpectedAlerts()[0], foo.getAttribute("value"));
    // valid data
    driver.findElement(By.id("myButton")).click();
    assertEquals(getExpectedAlerts()[1], getMockWebConnection().getLastWebRequest().getUrl());
    assertEquals(Integer.parseInt(getExpectedAlerts()[2]), getMockWebConnection().getRequestCount());
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 72 with Alerts

use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.

the class HtmlPasswordInputTest method getVisibleText.

/**
 * Verifies getVisibleText().
 * @throws Exception if the test fails
 */
@Test
@Alerts("")
public void getVisibleText() throws Exception {
    final String htmlContent = "<html>\n" + "<head></head>\n" + "<body>\n" + "<form id='form1'>\n" + "  <input type='password' name='tester' id='tester' value='bla'>\n" + "</form>\n" + "</body></html>";
    final WebDriver driver = loadPage2(htmlContent);
    final String text = driver.findElement(By.id("tester")).getText();
    assertEquals(getExpectedAlerts()[0], text);
    if (driver instanceof HtmlUnitDriver) {
        final HtmlPage page = (HtmlPage) getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage();
        assertEquals(getExpectedAlerts()[0], page.getBody().getVisibleText());
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 73 with Alerts

use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.

the class HtmlOrderedList2Test method getVisibleText.

/**
 * Verifies getVisibleText().
 * @throws Exception if the test fails
 */
@Test
@Alerts("first item\nsecond item\nsomething without li node\nthird item")
public void getVisibleText() throws Exception {
    final String htmlContent = "<html>\n" + "<head></head>\n" + "<body>\n" + "  <ol id='tester'>\n" + "    <li>first item</li>\n" + "    <li>second item</li>\n" + "something without li node\n" + "    <li>third item</li>\n" + "  </ol>\n" + "</body></html>";
    final WebDriver driver = loadPage2(htmlContent);
    final String text = driver.findElement(By.id("tester")).getText();
    assertEquals(getExpectedAlerts()[0], text);
    if (driver instanceof HtmlUnitDriver) {
        final HtmlPage page = (HtmlPage) getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage();
        assertEquals(getExpectedAlerts()[0], page.getBody().getVisibleText());
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 74 with Alerts

use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.

the class HtmlPage2Test method save.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts("Hello there")
public void save() throws Exception {
    final String html = "<html><head><script src='" + URL_SECOND + "'>\n</script></head></html>";
    final String js = "alert('Hello there')";
    final WebClient webClient = getWebClient();
    final MockWebConnection webConnection = new MockWebConnection();
    webConnection.setResponse(URL_FIRST, html);
    webConnection.setResponse(URL_SECOND, js);
    webClient.setWebConnection(webConnection);
    final List<String> collectedAlerts = new ArrayList<>();
    webClient.setAlertHandler(new CollectingAlertHandler(collectedAlerts));
    final HtmlPage page = webClient.getPage(URL_FIRST);
    assertEquals(getExpectedAlerts(), collectedAlerts);
    final HtmlScript sript = page.getFirstByXPath("//script");
    assertEquals(URL_SECOND.toString(), sript.getSrcAttribute());
    final File tmpFolder = tmpFolderProvider_.newFolder("hu");
    final File file = new File(tmpFolder, "hu_HtmlPageTest_save.html");
    page.save(file);
    assertTrue(file.exists());
    assertTrue(file.isFile());
    final String content = FileUtils.readFileToString(file, ISO_8859_1);
    assertFalse(content.contains("<script"));
    assertEquals(URL_SECOND.toString(), sript.getSrcAttribute());
}
Also used : ArrayList(java.util.ArrayList) MockWebConnection(com.gargoylesoftware.htmlunit.MockWebConnection) CollectingAlertHandler(com.gargoylesoftware.htmlunit.CollectingAlertHandler) WebClient(com.gargoylesoftware.htmlunit.WebClient) File(java.io.File) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 75 with Alerts

use of com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts in project htmlunit by HtmlUnit.

the class HtmlPage3Test method shouldBeAbleToFindElementByXPathInXmlDocument.

/**
 * @throws Exception if an error occurs
 */
@Test
@Alerts(DEFAULT = "error", CHROME = "Something", EDGE = "Something")
@NotYetImplemented({ IE, FF, FF_ESR })
public void shouldBeAbleToFindElementByXPathInXmlDocument() throws Exception {
    final String html = "<?xml version='1.0' encoding='UTF-8'?>\n" + "<html xmlns='http://www.w3.org/1999/xhtml'\n" + "      xmlns:svg='http://www.w3.org/2000/svg'\n" + "      xmlns:xlink='http://www.w3.org/1999/xlink'>\n" + "<body>\n" + "  <svg:svg id='chart_container' height='220' width='400'>\n" + "    <svg:text y='16' x='200' text-anchor='middle'>Something</svg:text>\n" + "  </svg:svg>\n" + "</body>\n" + "</html>\n";
    final WebDriver driver = loadPage2(html, URL_FIRST, "application/xhtml+xml", ISO_8859_1, null);
    String actual;
    try {
        final WebElement element = driver.findElement(By.xpath("//svg:svg//svg:text"));
        actual = element.getText();
    } catch (final NoSuchElementException e) {
        actual = "error";
    }
    assertEquals(getExpectedAlerts()[0], actual);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebElement(org.openqa.selenium.WebElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException) NotYetImplemented(com.gargoylesoftware.htmlunit.junit.BrowserRunner.NotYetImplemented) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Aggregations

Alerts (com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)1266 Test (org.junit.Test)1261 WebDriver (org.openqa.selenium.WebDriver)894 HtmlPageTest (com.gargoylesoftware.htmlunit.html.HtmlPageTest)398 URL (java.net.URL)238 HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)206 BuggyWebDriver (com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver)159 WebElement (org.openqa.selenium.WebElement)146 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)128 MSXMLTestHelper.callLoadXMLDOMDocumentFromString (com.gargoylesoftware.htmlunit.activex.javascript.msxml.MSXMLTestHelper.callLoadXMLDOMDocumentFromString)101 NameValuePair (com.gargoylesoftware.htmlunit.util.NameValuePair)97 ArrayList (java.util.ArrayList)90 HtmlUnitNYI (com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI)72 NotYetImplemented (com.gargoylesoftware.htmlunit.junit.BrowserRunner.NotYetImplemented)54 MockWebConnection (com.gargoylesoftware.htmlunit.MockWebConnection)48 XMLDocumentTest.callLoadXMLDocumentFromString (com.gargoylesoftware.htmlunit.javascript.host.xml.XMLDocumentTest.callLoadXMLDocumentFromString)47 XMLDocumentTest.callSerializeXMLDocumentToString (com.gargoylesoftware.htmlunit.javascript.host.xml.XMLDocumentTest.callSerializeXMLDocumentToString)44 File (java.io.File)30 WebClient (com.gargoylesoftware.htmlunit.WebClient)29 InputStream (java.io.InputStream)29