Search in sources :

Example 26 with BuggyWebDriver

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

the class HtmlAnchorTest method ctrlClick.

/**
 * @exception Exception If the test fails
 */
@Test
@Alerts({ "1", "First" })
@BuggyWebDriver(IE = { "0", "Second" })
public void ctrlClick() throws Exception {
    final String html = "<html><head><title>First</title></head><body>\n" + "<a href='" + URL_SECOND + "'>Click Me</a>\n" + "</form></body></html>";
    getMockWebConnection().setResponse(URL_SECOND, "<head><title>Second</title>");
    final WebDriver driver = loadPage2(html);
    final WebElement link = driver.findElement(By.linkText("Click Me"));
    final int windowsSize = driver.getWindowHandles().size();
    new Actions(driver).moveToElement(link).keyDown(Keys.CONTROL).click().keyUp(Keys.CONTROL).perform();
    Thread.sleep(DEFAULT_WAIT_TIME);
    assertEquals("Should have opened a new window", windowsSize + Integer.parseInt(getExpectedAlerts()[0]), driver.getWindowHandles().size());
    assertEquals("Should not have navigated away", getExpectedAlerts()[1], driver.getTitle());
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) Actions(org.openqa.selenium.interactions.Actions) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 27 with BuggyWebDriver

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

the class HtmlSelect2Test method select.

/**
 * @exception Exception If the test fails
 */
@Test
@Alerts({ "false", "false", "false", "true" })
@BuggyWebDriver(IE = { "false", "false", "true", "false" })
public void select() throws Exception {
    final String html = "<html><head><title>foo</title></head><body>\n" + "<form id='form1'><select name='select1' multiple>\n" + "  <option value='option1'>Option1</option>\n" + "  <option value='option2'>Option2</option>\n" + "  <option value='option3' selected='selected'>Option3</option>\n" + "  <option value='option4'>Option4</option>\n" + "</select>\n" + "<input type='submit' name='button' value='foo'/>\n" + "</form></body></html>";
    final WebDriver driver = loadPage2(html);
    final List<WebElement> options = driver.findElements(By.tagName("option"));
    final Actions actions = new Actions(driver);
    final Action selectThreeOptions = actions.click(options.get(1)).click(options.get(2)).click(options.get(3)).build();
    selectThreeOptions.perform();
    assertEquals(Boolean.parseBoolean(getExpectedAlerts()[0]), options.get(0).isSelected());
    assertEquals(Boolean.parseBoolean(getExpectedAlerts()[1]), options.get(1).isSelected());
    assertEquals(Boolean.parseBoolean(getExpectedAlerts()[2]), options.get(2).isSelected());
    assertEquals(Boolean.parseBoolean(getExpectedAlerts()[3]), options.get(3).isSelected());
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) Action(org.openqa.selenium.interactions.Action) Actions(org.openqa.selenium.interactions.Actions) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 28 with BuggyWebDriver

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

the class HtmlSelect2Test method controlClick.

/**
 * @exception Exception If the test fails
 */
@Test
@Alerts({ "false", "true", "false", "true" })
@BuggyWebDriver(IE = { "false", "false", "true", "false" })
public void controlClick() throws Exception {
    final String html = "<html><head><title>foo</title></head><body>\n" + "<form id='form1'><select name='select1' multiple>\n" + "  <option value='option1'>Option1</option>\n" + "  <option value='option2'>Option2</option>\n" + "  <option value='option3' selected='selected'>Option3</option>\n" + "  <option value='option4'>Option4</option>\n" + "</select>\n" + "<input type='submit' name='button' value='foo'/>\n" + "</form></body></html>";
    final WebDriver driver = loadPage2(html);
    final List<WebElement> options = driver.findElements(By.tagName("option"));
    final Actions actions = new Actions(driver);
    final Action selectThreeOptions = actions.click(options.get(1)).keyDown(Keys.CONTROL).click(options.get(3)).keyUp(Keys.CONTROL).build();
    selectThreeOptions.perform();
    assertEquals(Boolean.parseBoolean(getExpectedAlerts()[0]), options.get(0).isSelected());
    assertEquals(Boolean.parseBoolean(getExpectedAlerts()[1]), options.get(1).isSelected());
    assertEquals(Boolean.parseBoolean(getExpectedAlerts()[2]), options.get(2).isSelected());
    assertEquals(Boolean.parseBoolean(getExpectedAlerts()[3]), options.get(3).isSelected());
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) Action(org.openqa.selenium.interactions.Action) Actions(org.openqa.selenium.interactions.Actions) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 29 with BuggyWebDriver

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

the class HtmlSelect2Test method shiftClick.

/**
 * @exception Exception If the test fails
 */
@Test
@Alerts({ "false", "true", "true", "true" })
@BuggyWebDriver(IE = { "false", "false", "true", "false" })
public void shiftClick() throws Exception {
    final String html = "<html><head><title>foo</title></head><body>\n" + "<form id='form1'><select name='select1' multiple>\n" + "  <option value='option1'>Option1</option>\n" + "  <option value='option2'>Option2</option>\n" + "  <option value='option3' selected='selected'>Option3</option>\n" + "  <option value='option4'>Option4</option>\n" + "</select>\n" + "<input type='submit' name='button' value='foo'/>\n" + "</form></body></html>";
    final WebDriver driver = loadPage2(html);
    final List<WebElement> options = driver.findElements(By.tagName("option"));
    final Actions actions = new Actions(driver);
    final Action selectThreeOptions = actions.click(options.get(1)).keyDown(Keys.SHIFT).click(options.get(3)).keyUp(Keys.SHIFT).build();
    selectThreeOptions.perform();
    assertEquals(Boolean.parseBoolean(getExpectedAlerts()[0]), options.get(0).isSelected());
    assertEquals(Boolean.parseBoolean(getExpectedAlerts()[1]), options.get(1).isSelected());
    assertEquals(Boolean.parseBoolean(getExpectedAlerts()[2]), options.get(2).isSelected());
    assertEquals(Boolean.parseBoolean(getExpectedAlerts()[3]), options.get(3).isSelected());
}
Also used : WebDriver(org.openqa.selenium.WebDriver) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) Action(org.openqa.selenium.interactions.Action) Actions(org.openqa.selenium.interactions.Actions) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 30 with BuggyWebDriver

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

the class ConsoleTest method assertObjects.

/**
 * @throws Exception if the test fails
 */
@Test
@BuggyWebDriver
public void assertObjects() throws Exception {
    final String html = "<html>\n" + "<body>\n" + "<script>\n" + "  number = 1;\n" + "  console.assert(number % 2 === 0, {number: number}, {errorMsg: 'the # is not even'});\n" + "</script>\n" + "</body></html>";
    final WebDriver driver = loadPage2(html);
    final Logs logs = driver.manage().logs();
    final LogEntries logEntries = logs.get(LogType.BROWSER);
    final List<LogEntry> logEntryList = logEntries.getAll();
    assertEquals(1, logEntryList.size());
    final LogEntry logEntry = logEntryList.get(0);
    assertTrue(logEntry.getMessage(), logEntry.getMessage().contains("Assertion failed: ({number: 1.0}) ({errorMsg: \"the # is not even\"})"));
}
Also used : BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver) WebDriver(org.openqa.selenium.WebDriver) LogEntries(org.openqa.selenium.logging.LogEntries) Logs(org.openqa.selenium.logging.Logs) LogEntry(org.openqa.selenium.logging.LogEntry) Test(org.junit.Test) BuggyWebDriver(com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver)

Aggregations

BuggyWebDriver (com.gargoylesoftware.htmlunit.junit.BrowserRunner.BuggyWebDriver)43 Test (org.junit.Test)42 WebDriver (org.openqa.selenium.WebDriver)41 Alerts (com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)35 WebElement (org.openqa.selenium.WebElement)15 HtmlPageTest (com.gargoylesoftware.htmlunit.html.HtmlPageTest)11 Actions (org.openqa.selenium.interactions.Actions)8 LogEntries (org.openqa.selenium.logging.LogEntries)8 LogEntry (org.openqa.selenium.logging.LogEntry)8 Logs (org.openqa.selenium.logging.Logs)8 URL (java.net.URL)7 NameValuePair (com.gargoylesoftware.htmlunit.util.NameValuePair)6 LinkedList (java.util.LinkedList)5 HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)5 NotYetImplemented (com.gargoylesoftware.htmlunit.junit.BrowserRunner.NotYetImplemented)4 InputStream (java.io.InputStream)4 Page (com.gargoylesoftware.htmlunit.Page)3 Action (org.openqa.selenium.interactions.Action)3 HtmlUnitNYI (com.gargoylesoftware.htmlunit.junit.BrowserRunner.HtmlUnitNYI)2 MockWebConnection (com.gargoylesoftware.htmlunit.MockWebConnection)1