use of com.gargoylesoftware.htmlunit.Page in project Payara by payara.
the class MicroProfileRestClientFaultToleranceIT method testRetry.
@Test
public void testRetry() throws Exception {
Page page = webClient.getPage(base + "/api/client");
Assert.assertEquals(HttpServletResponse.SC_OK, page.getWebResponse().getStatusCode());
}
use of com.gargoylesoftware.htmlunit.Page in project support-core-plugin by jenkinsci.
the class SupportActionTest method takeSnapshotAndMakeSureSomethingHappens.
/*
* Integration test that simulates the user action of clicking the button to generate the bundle.
* <p>
* If any warning is reported to j.u.l logger, treat that as a sign of failure, because
* support-core plugin works darn hard to try to generate something in the presence of failing
* {@link Component} impls.
*/
@Test
public void takeSnapshotAndMakeSureSomethingHappens() throws Exception {
j.createSlave("agent1", "test", null).getComputer().connect(false).get();
j.createSlave("agent2", "test", null).getComputer().connect(false).get();
RingBufferLogHandler checker = new RingBufferLogHandler();
Logger logger = Logger.getLogger(SupportPlugin.class.getPackage().getName());
logger.addHandler(checker);
try {
WebClient wc = j.createWebClient();
HtmlPage p = wc.goTo(root.getUrlName());
HtmlForm form = p.getFormByName("bundle-contents");
HtmlButton submit = (HtmlButton) form.getElementsByTagName("button").get(0);
Page zip = submit.click();
File zipFile = File.createTempFile("test", "zip");
IOUtils.copy(zip.getWebResponse().getContentAsStream(), Files.newOutputStream(zipFile.toPath()));
ZipFile z = new ZipFile(zipFile);
// check the presence of files
// TODO: emit some log entries and see if it gets captured here
assertNotNull(z.getEntry("about.md"));
assertNotNull(z.getEntry("nodes.md"));
assertNotNull(z.getEntry("nodes/master/thread-dump.txt"));
if (SystemPlatform.LINUX == SystemPlatform.current()) {
List<String> files = Arrays.asList("proc/swaps.txt", "proc/cpuinfo.txt", "proc/mounts.txt", "proc/system-uptime.txt", "proc/net/rpc/nfs.txt", "proc/net/rpc/nfsd.txt", "proc/meminfo.txt", "proc/self/status.txt", "proc/self/cmdline", "proc/self/environ", "proc/self/limits.txt", "proc/self/mountstats.txt", "sysctl.txt", "dmesg.txt", "userid.txt", "dmi.txt");
for (String file : files) {
assertNotNull(file + " was not found in the bundle", z.getEntry("nodes/master/" + file));
}
}
} finally {
logger.removeHandler(checker);
for (LogRecord r : checker.getView()) {
if (r.getLevel().intValue() >= Level.WARNING.intValue()) {
Throwable thrown = r.getThrown();
if (thrown != null)
thrown.printStackTrace(System.err);
fail(r.getMessage());
}
}
}
}
use of com.gargoylesoftware.htmlunit.Page in project ats-framework by Axway.
the class HiddenHtmlElement method clickAndDownloadFile.
/**
* Click the element and download file
*/
protected void clickAndDownloadFile() {
WebWindow currentWindow = null;
Field currentWindowField = null;
boolean fieldAccessibleState = false;
try {
currentWindowField = htmlUnitDriver.getClass().getDeclaredField("currentWindow");
fieldAccessibleState = currentWindowField.isAccessible();
currentWindowField.setAccessible(true);
currentWindow = (WebWindow) currentWindowField.get(htmlUnitDriver);
} catch (Exception e) {
throw new SeleniumOperationException("Error retrieving internal Selenium web client", e);
} finally {
if (currentWindowField != null) {
currentWindowField.setAccessible(fieldAccessibleState);
}
}
String elementXPath = properties.getProperty("xpath");
// find element and download the file
HtmlPage page = (HtmlPage) currentWindow.getEnclosedPage();
List<?> foundElementsList = page.getByXPath(elementXPath);
if (foundElementsList != null && !foundElementsList.isEmpty()) {
InputStream in = null;
FileOutputStream fos = null;
try {
com.gargoylesoftware.htmlunit.html.HtmlElement element = (com.gargoylesoftware.htmlunit.html.HtmlElement) foundElementsList.get(0);
// Use generic Page. Exact page type returned depends on the MIME type set in response header
Page result = element.click();
String fileName = null;
String contentDisposition = result.getWebResponse().getResponseHeaderValue("Content-Disposition");
if (contentDisposition != null) {
Matcher m = contentDispositionPattern.matcher(contentDisposition);
if (m.matches()) {
fileName = m.group(1);
log.debug("Download file name extracted from the 'Content-Disposition' header is " + fileName);
}
}
if (fileName == null) {
String url = result.getWebResponse().getWebRequest().getUrl().getFile().trim();
Matcher m = urlFileNamePattern.matcher(url);
if (m.matches()) {
fileName = m.group(1);
log.debug("Download file name extracted from the request URL is " + fileName);
} else {
fileName = String.valueOf(new Date().getTime()) + ".bin";
log.debug("Downloaded file name constructed the current timestamp is " + fileName);
}
}
in = result.getWebResponse().getContentAsStream();
String fileAbsPath = UiEngineConfigurator.getInstance().getBrowserDownloadDir() + fileName;
fos = new FileOutputStream(new File(fileAbsPath), false);
byte[] buff = new byte[BUFFER_LENGTH];
int len;
while ((len = in.read(buff)) != -1) {
fos.write(buff, 0, len);
}
fos.flush();
log.info("Downloaded file: " + fileAbsPath);
} catch (IOException e) {
throw new SeleniumOperationException("Error downloading file", e);
} finally {
IoUtils.closeStream(fos);
IoUtils.closeStream(in);
}
} else {
throw new ElementNotFoundException("Can't find element by XPath: " + elementXPath);
}
}
use of com.gargoylesoftware.htmlunit.Page in project ats-framework by Axway.
the class HiddenHtmlPrompt method clickOk.
@Override
@PublicAtsApi
public void clickOk(final String promptValue) {
isProcessed = false;
webClient.setPromptHandler(new PromptHandler() {
@Override
public String handlePrompt(Page currentPage, String promptText, String defaultValue) {
isProcessed = true;
return promptValue;
}
});
}
use of com.gargoylesoftware.htmlunit.Page in project ats-framework by Axway.
the class HiddenHtmlPrompt method clickCancel.
@Override
@PublicAtsApi
public void clickCancel() {
isProcessed = false;
webClient.setPromptHandler(new PromptHandler() {
@Override
public String handlePrompt(Page currentPage, String promptText, String defaultValue) {
isProcessed = true;
return null;
}
});
}
Aggregations