use of com.gargoylesoftware.htmlunit.WebClient in project Payara by payara.
the class InplantedTest method testWeb.
@Test
public void testWeb() throws Exception {
System.out.println("test web");
File f = new File(System.getProperty("basedir"));
f = new File(f, "target");
f = new File(f, "test-classes");
ScatteredArchive.Builder builder = new ScatteredArchive.Builder("hello", f);
builder.addClassPath(f.toURI().toURL());
builder.resources(f);
ScatteredArchive war = builder.buildWar();
System.out.println("War content");
Enumeration<String> contents = war.entries();
while (contents.hasMoreElements()) {
System.out.println(contents.nextElement());
}
Port http = server.createPort(8080);
ContainerBuilder b = server.createConfig(ContainerBuilder.Type.web);
server.addContainer(b);
EmbeddedWebContainer embedded = (EmbeddedWebContainer) b.create(server);
embedded.bind(http, "http");
DeployCommandParameters dp = new DeployCommandParameters(f);
String appName = server.getDeployer().deploy(war, dp);
WebClient webClient = new WebClient();
Page page = webClient.getPage("http://localhost:8080/test-classes/hello");
System.out.println("Got response " + page.getWebResponse().getContentAsString());
Assert.assertTrue("Servlet returned wrong content", page.getWebResponse().getContentAsString().startsWith("Hello World"));
server.getDeployer().undeploy(appName, null);
}
use of com.gargoylesoftware.htmlunit.WebClient in project archiva by apache.
the class WebdriverUtility method newWebDriver.
public static WebDriver newWebDriver(String seleniumBrowser, String seleniumHost, int seleniumPort, boolean seleniumRemote) {
log.info("WebDriver {}, {}, {}, {}", seleniumBrowser, seleniumHost, seleniumPort, seleniumRemote);
if (seleniumRemote && StringUtils.isEmpty(seleniumHost)) {
throw new IllegalArgumentException("seleniumHost must be set, when seleniumRemote=true");
}
try {
if (StringUtils.contains(seleniumBrowser, "chrome")) {
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
if (seleniumRemote) {
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"), capabilities);
} else {
return new ChromeDriver(options);
}
}
if (StringUtils.contains(seleniumBrowser, "safari")) {
if (seleniumRemote) {
return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"), DesiredCapabilities.safari());
} else {
return new SafariDriver();
}
}
if (StringUtils.contains(seleniumBrowser, "iexplore")) {
if (seleniumRemote) {
return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"), DesiredCapabilities.internetExplorer());
} else {
new InternetExplorerDriver();
}
}
if (StringUtils.contains(seleniumBrowser, "firefox")) {
if (seleniumRemote) {
return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"), DesiredCapabilities.firefox());
} else {
return new FirefoxDriver();
}
}
DesiredCapabilities capabilities = DesiredCapabilities.htmlUnit();
capabilities.setJavascriptEnabled(true);
capabilities.setVersion("firefox-52");
WebDriver driver;
if (seleniumRemote) {
driver = new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"), capabilities);
} else {
driver = new HtmlUnitDriver(capabilities) {
@Override
protected WebClient modifyWebClient(WebClient client) {
client.getOptions().setThrowExceptionOnFailingStatusCode(false);
client.getOptions().setThrowExceptionOnScriptError(false);
client.getOptions().setCssEnabled(true);
return client;
}
};
}
return driver;
} catch (MalformedURLException e) {
throw new RuntimeException("Initializion of remote driver failed");
}
}
use of com.gargoylesoftware.htmlunit.WebClient in project archiva by apache.
the class AbstractRepositoryServletProxiedTestCase method assertServerSetupCorrectly.
protected void assertServerSetupCorrectly(RemoteRepoInfo remoteRepo) throws Exception {
WebClient client = newClient();
int status = client.getPage(remoteRepo.url).getWebResponse().getStatusCode();
assertThat(status).isEqualTo(HttpServletResponse.SC_OK);
}
use of com.gargoylesoftware.htmlunit.WebClient in project JSCover by tntim96.
the class HtmlUnitMergeTest method saveUnloadedJS.
private void saveUnloadedJS() throws IOException {
WebClient webClient = new WebClient();
HtmlPage page = webClient.getPage("http://localhost:9001/jscoverage.html");
storeReport(webClient, page);
}
use of com.gargoylesoftware.htmlunit.WebClient in project JSCover by tntim96.
the class HtmlUnitMergeTest method shouldMergeUnloadedButtonSavedAndJSSavedReports.
@Test
public void shouldMergeUnloadedButtonSavedAndJSSavedReports() throws Exception {
File jsonFile = new File(reportDir + "/jscoverage.json");
if (jsonFile.exists())
jsonFile.delete();
saveUnloadedJS();
saveReportByJavaScript();
saveReportByButton();
String json = ioUtils.toString(jsonFile);
assertThat(json, containsString("/root.js"));
assertThat(json, containsString("/level1/level2/level2.js"));
String url = "file:///" + new File(reportDir + "/jscoverage.html").getAbsolutePath();
WebClient webClient = new WebClient();
HtmlPage page = webClient.getPage(url);
webClient.waitForBackgroundJavaScript(1000);
assertEquals("53%", page.getElementById("summaryTotal").getTextContent());
assertEquals("33%", page.getElementById("branchSummaryTotal").getTextContent());
assertEquals("50%", page.getElementById("functionSummaryTotal").getTextContent());
verifyCoverage(page, "/root.js", "80%", "50%", "100%");
verifyCoverage(page, "/root-empty.js", "N/A", "N/A", "N/A");
verifyCoverage(page, "/level1/level1.js", "75%", "50%", "N/A");
verifyCoverage(page, "/level1/level2/level2.js", "0%", "0%", "0%");
verifyCoverage(page, "/level1/level2/level2-empty.js", "N/A", "N/A", "N/A");
}
Aggregations