use of com.gargoylesoftware.htmlunit.MockWebConnection in project arquillian-extension-drone by arquillian.
the class HtmlUnitDriverTest method shouldOverrideWebClientOptions.
@Test
public void shouldOverrideWebClientOptions() throws IOException {
final HtmlUnitDriverFactory htmlUnitDriverFactory = new HtmlUnitDriverFactory();
final WebDriverConfiguration configuration = getMockedConfiguration("ThrowExceptionOnFailingStatusCode=true");
final WebDriver driver = htmlUnitDriverFactory.createInstance(configuration);
final DroneHtmlUnitDriver htmlUnitDriver = (DroneHtmlUnitDriver) driver;
MockWebConnection webConnection = new MockWebConnection();
webConnection.setDefaultResponse("http://foo.com", 503, "Service Unavailable", "text/plain");
WebClient webClient = htmlUnitDriver.getWebClient();
webClient.setWebConnection(webConnection);
thrown.expect(WebDriverException.class);
thrown.expectMessage("com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException: 503 Service Unavailable for http://foo.com/");
driver.get("http://foo.com");
driver.quit();
}
use of com.gargoylesoftware.htmlunit.MockWebConnection in project htmlunit by HtmlUnit.
the class HtmlAnchorTest method click.
/**
* @throws Exception if the test fails
*/
@Test
public void click() throws Exception {
final String html = "<html>\n" + "<head><title>foo</title></head>\n" + "<body>\n" + "<a href='http://www.foo1.com' id='a1'>link to foo1</a>\n" + "<a href='" + URL_SECOND + "' id='a2'>link to foo2</a>\n" + "</body></html>";
final String secondContent = "<html><head><title>Second</title></head><body></body></html>";
final MockWebConnection webConnection = getMockWebConnection();
webConnection.setDefaultResponse(secondContent);
final WebDriver driver = loadPage2(html);
assertEquals(1, webConnection.getRequestCount());
// Test that the correct value is being passed back up to the server
driver.findElement(By.id("a2")).click();
assertEquals(URL_SECOND.toExternalForm(), driver.getCurrentUrl());
assertSame("method", HttpMethod.GET, webConnection.getLastMethod());
assertTrue(webConnection.getLastParameters().isEmpty());
assertEquals(2, webConnection.getRequestCount());
}
use of com.gargoylesoftware.htmlunit.MockWebConnection in project htmlunit by HtmlUnit.
the class HtmlAnchor2Test method click_onClickHandler.
/**
* @throws Exception if the test fails
*/
@Test
public void click_onClickHandler() throws Exception {
final String firstContent = "<html><head><title>First</title></head><body>\n" + "<a href='http://www.foo1.com' id='a1'>link to foo1</a>\n" + "<a href='" + URL_SECOND + "' id='a2' " + "onClick='alert(\"clicked\")'>link to foo2</a>\n" + "<a href='http://www.foo3.com' id='a3'>link to foo3</a>\n" + "</body></html>";
final String secondContent = "<html><head><title>Second</title></head><body></body></html>";
final WebClient client = getWebClient();
final List<String> collectedAlerts = new ArrayList<>();
client.setAlertHandler(new CollectingAlertHandler(collectedAlerts));
final MockWebConnection webConnection = new MockWebConnection();
webConnection.setResponse(URL_FIRST, firstContent);
webConnection.setResponse(URL_SECOND, secondContent);
client.setWebConnection(webConnection);
final HtmlPage page = client.getPage(URL_FIRST);
final HtmlAnchor anchor = page.getHtmlElementById("a2");
assertEquals(Collections.EMPTY_LIST, collectedAlerts);
final HtmlPage secondPage = anchor.click();
assertEquals(new String[] { "clicked" }, collectedAlerts);
assertEquals("Second", secondPage.getTitleText());
}
use of com.gargoylesoftware.htmlunit.MockWebConnection in project htmlunit by HtmlUnit.
the class HtmlAnchor2Test method clickShiftCtrlJavascript.
/**
* @throws Exception if the test fails
*/
@Test
public void clickShiftCtrlJavascript() throws Exception {
final String first = "<html><head><title>First</title></head><body>\n" + " <a href='javascript: window.location=\"" + URL_SECOND + "\"' id='a2'>link to foo2</a>\n" + "</body></html>";
final String second = "<html><head><title>Second</title></head><body></body></html>";
final WebClient client = getWebClient();
final List<String> collectedAlerts = new ArrayList<>();
client.setAlertHandler(new CollectingAlertHandler(collectedAlerts));
final MockWebConnection webConnection = new MockWebConnection();
webConnection.setResponse(URL_FIRST, first);
webConnection.setResponse(URL_SECOND, second);
client.setWebConnection(webConnection);
assertEquals(1, getWebClient().getTopLevelWindows().size());
final HtmlPage page = client.getPage(URL_FIRST);
final HtmlAnchor anchor = page.getHtmlElementById("a2");
final HtmlPage secondPage = anchor.click(true, true, false);
assertEquals(2, getWebClient().getTopLevelWindows().size());
assertEquals("First", secondPage.getTitleText());
}
use of com.gargoylesoftware.htmlunit.MockWebConnection in project htmlunit by HtmlUnit.
the class HtmlAnchor2Test method clickCtrlShift.
/**
* @throws Exception if the test fails
*/
@Test
public void clickCtrlShift() throws Exception {
final String first = "<html><head><title>First</title></head><body>\n" + " <a href='" + URL_SECOND + "' id='a2'>link to foo2</a>\n" + "</body></html>";
final String second = "<html><head><title>Second</title></head><body></body></html>";
final WebClient client = getWebClient();
final List<String> collectedAlerts = new ArrayList<>();
client.setAlertHandler(new CollectingAlertHandler(collectedAlerts));
final MockWebConnection webConnection = new MockWebConnection();
webConnection.setResponse(URL_FIRST, first);
webConnection.setResponse(URL_SECOND, second);
client.setWebConnection(webConnection);
assertEquals(1, getWebClient().getTopLevelWindows().size());
final HtmlPage page = client.getPage(URL_FIRST);
final HtmlAnchor anchor = page.getHtmlElementById("a2");
final HtmlPage secondPage = anchor.click(true, true, false);
assertEquals(2, getWebClient().getTopLevelWindows().size());
assertEquals("First", secondPage.getTitleText());
}
Aggregations