Search in sources :

Example 56 with Alerts

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

the class HtmlCheckBoxInput2Test method onchangeFires2.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts("foo,change,boo,blur,")
public void onchangeFires2() throws Exception {
    final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>foo</title>\n" + "<script>\n" + "  function debug(string) {\n" + "    document.getElementById('myTextarea').value += string + ',';\n" + "  }\n" + "</script>\n" + "</head><body>\n" + "<form>\n" + "<input type='checkbox' id='chkbox'" + " onChange='debug(\"foo\");debug(event.type);'" + " onBlur='debug(\"boo\");debug(event.type);'" + ">\n" + "<input type='checkbox' id='chkbox2'>\n" + "</form>\n" + "<textarea id='myTextarea'></textarea>\n" + "</body></html>";
    final WebDriver driver = loadPage2(html);
    driver.findElement(By.id("chkbox")).click();
    driver.findElement(By.id("chkbox2")).click();
    assertEquals(Arrays.asList(getExpectedAlerts()).toString(), '[' + driver.findElement(By.id("myTextarea")).getAttribute("value") + ']');
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 57 with Alerts

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

the class HtmlCheckBoxInput2Test method setChecked2.

/**
 * @throws Exception if the test fails
 */
@Test
@Alerts("Second")
public void setChecked2() throws Exception {
    final String firstHtml = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title></head><body>\n" + "<form>\n" + "<input id='myCheckbox' type='checkbox' onchange=\"window.location.href='" + URL_SECOND + "'\">\n" + "<input id='myInput' type='text'>\n" + "</form>\n" + "</body></html>";
    final String secondHtml = "<html><head><title>Second</title></head><body></body></html>";
    getMockWebConnection().setDefaultResponse(secondHtml);
    final WebDriver driver = loadPage2(firstHtml);
    driver.findElement(By.id("myCheckbox")).click();
    assertTitle(driver, getExpectedAlerts()[0]);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 58 with Alerts

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

the class HtmlColorInputTest method clearInput.

/**
 * Verifies clear().
 * @throws Exception if the test fails
 */
@Test
@Alerts(DEFAULT = "#000000", IE = "")
public void clearInput() throws Exception {
    final String htmlContent = "<html>\n" + "<head></head>\n" + "<body>\n" + "<form id='form1'>\n" + "  <input type='color' name='tester' id='tester' value='#ff0000'>\n" + "</form>\n" + "</body></html>";
    final WebDriver driver = loadPage2(htmlContent);
    final WebElement element = driver.findElement(By.id("tester"));
    element.clear();
    assertEquals(getExpectedAlerts()[0], element.getAttribute("value"));
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 59 with Alerts

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

the class HtmlColorInputTest 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='color' name='tester' id='tester' value='#ff0000'>\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 60 with Alerts

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

the class HtmlDateInputTest method typeInto.

/**
 * @throws Exception if an error occurs
 */
@Test
@Alerts("2018-03-22")
@BuggyWebDriver(CHROME = "80322-02-01", EDGE = "80322-02-01")
public void typeInto() throws Exception {
    final String html = "<html>\n" + "<head>\n" + "<script>\n" + "  function test() {\n" + "    var input = document.getElementById('input');\n" + "    alert(input.value);\n" + "  }\n" + "</script>\n" + "</head>\n" + "<body>\n" + "  <input id='input' type='date'>\n" + "  <button id='tester' onclick='test()'>Test</button>\n" + "</body></html>";
    final WebDriver driver = loadPage2(html);
    driver.findElement(By.id("input")).sendKeys("2018-03-22");
    driver.findElement(By.id("tester")).click();
    verifyAlerts(driver, getExpectedAlerts());
}
Also used : BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) WebDriver(org.openqa.selenium.WebDriver) Test(org.junit.Test) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) 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