Java Examples for com.gargoylesoftware.htmlunit.html.HtmlTable
The following java examples will help you to understand the usage of com.gargoylesoftware.htmlunit.html.HtmlTable. These source code samples are taken from different open source projects.
Example 1
| Project: mojarra-master File: Issue3308IT.java View source code |
@Test
public void testFindChildByTagIdFacet() throws Exception {
HtmlPage page = webClient.getPage(webUrl + "faces/findChildByTagIdFacets.xhtml");
HtmlTable table = (HtmlTable) page.getElementById("table");
String matchingRegex = "(?s).*<table.*>\\s+<caption>.*table:captionFacet.*My Caption.*</caption>.*background-color:red.*background-color:yellow.*<thead>.*My Header.*</thead>\\s+<tfoot>.*My Footer.*</tfoot>\\s+<tbody>.*";
String tableXml = table.asXml();
assertTrue(tableXml.matches(matchingRegex));
HtmlSubmitInput button = (HtmlSubmitInput) page.getElementById("button");
page = button.click();
table = (HtmlTable) page.getElementById("table");
tableXml = table.asXml();
assertTrue(tableXml.matches(matchingRegex));
}Example 2
| Project: Canoo-WebTest-master File: TableLocator.java View source code |
public String locateText(final Context context, Step step) throws TableNotFoundException, IndexOutOfBoundsException, SAXException {
try {
final HtmlElement htmlElement;
if (getHtmlId() == null) {
htmlElement = findFirstTable(context, step);
} else {
htmlElement = context.getCurrentHtmlResponse(step).getHtmlElementById(getHtmlId());
}
if (!(htmlElement instanceof HtmlTable)) {
throw new StepFailedException("Found '" + htmlElement.getTagName() + "' element when looking for 'table' element using htmlId " + getHtmlId(), step);
}
final HtmlTable table = (HtmlTable) htmlElement;
return table.getRow(getRow()).getCell(getColumn()).asText();
} catch (final ElementNotFoundException e) {
throw new TableNotFoundException(getHtmlId());
}
}Example 3
| Project: jsfunit-master File: RichDragAndDropTest.java View source code |
public void testDragAndDrop() throws IOException {
JSFSession jsfSession = JSFSessionFactory.makeSession("/richfaces/dragSupport.jsf");
HtmlPage page = (HtmlPage) jsfSession.getJSFClientSession().getContentPage();
HtmlTable table = (HtmlTable) page.getElementById("form:phptable");
assertEquals(0, table.getRowCount());
// element 0 is Flexible Ajax - drag to php
HtmlElement dragElement = (HtmlElement) page.getElementById("form:src:0:dragItem");
HtmlElement dropElement = (HtmlElement) page.getElementById("form:phppanel_body");
page = (HtmlPage) dragElement.mouseDown();
// need to trigger a mousemove outside of dragElement to initialize
((HtmlBody) page.getFirstByXPath("//body")).mouseMove();
page = (HtmlPage) dropElement.mouseOver();
page = (HtmlPage) dropElement.mouseMove();
page = (HtmlPage) dropElement.mouseUp();
table = (HtmlTable) page.getElementById("form:phptable");
assertEquals(1, table.getRowCount());
}Example 4
| Project: hibiscus.depotviewer-master File: WertpapierSuche.java View source code |
private static List<HashMap<String, String>> getYahooSearchResults(String search) throws IOException {
List<HashMap<String, String>> x = new ArrayList<HashMap<String, String>>();
WebClient webClient = new WebClient();
HtmlUtils.setProxyCfg(webClient, "https://de.finance.yahoo.com/");
webClient.getOptions().setTimeout(3000);
webClient.setCssErrorHandler(new SilentCssErrorHandler());
webClient.setRefreshHandler(new ThreadedRefreshHandler());
webClient.getOptions().setJavaScriptEnabled(false);
webClient.getOptions().setThrowExceptionOnScriptError(false);
java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(java.util.logging.Level.OFF);
HtmlPage page = webClient.getPage("https://de.finance.yahoo.com/lookup/all?s=" + search + "&t=A&m=ALL&r=");
HtmlTable tab = (HtmlTable) HtmlUnitTools.getElementByPartContent(page, "Ticker", "table");
if (tab == null) {
webClient.close();
return x;
}
x = HtmlUnitTools.analyse(tab);
List<HashMap<String, String>> out = new ArrayList<HashMap<String, String>>();
for (HashMap<String, String> e : x) {
e.put("Source", "Yahoo Finance");
e.remove("Letzter Kurs");
e.remove("Ticker");
e.remove("Börsenplatz");
System.out.println(e.entrySet());
if (!out.contains(e)) {
out.add(e);
}
}
webClient.close();
return out;
}Example 5
| Project: metadata-plugin-master File: MetadataSearchPageTest.java View source code |
/**
* Opens the search page and performs a search.
*
* @param web the client to connect with.
* @param searchString the search expression
* @param expectedCount the expected number of jobs to be displayed.
* @throws IOException if so.
* @throws SAXException if so.
*/
private void doTestSearch(WebClient web, String searchString, int expectedCount) throws IOException, SAXException {
HtmlPage htmlPage = web.goTo("/metadata-search/searchMetadata?metadata.search.queryString=" + searchString);
HtmlElement documentElement = htmlPage.getDocumentElement();
HtmlTable element = (HtmlTable) documentElement.getElementById("projectstatus");
//One extra for the table header.
assertEquals(expectedCount + 1, element.getRowCount());
}Example 6
| Project: openticket-master File: TaskboxUIWorkflowIT.java View source code |
@Test
public void testTicketPassingThroughWorkflow() throws Exception {
final HtmlPage startPage = webClient.getPage(startPageUrl);
final HtmlPage loginPage = startPage.getAnchorByText("Login").click();
HtmlForm form = loginPage.getForms().get(0);
HtmlSubmitInput loginButton = form.getInputByValue("Login");
form.getInputByName("username").setValueAttribute("admin");
form.getInputByName("password").setValueAttribute("password");
HtmlPage indexPage = loginButton.click();
HtmlPage createTicketPage = indexPage.getAnchorByText("Create Ticket").click();
HtmlForm createForm = createTicketPage.getForms().get(0);
createForm.getInputByName("ticketname").setValueAttribute("testname");
createForm.getInputByName("ticketcustomer").setValueAttribute("testcustomer");
createForm.getInputByName("ticketcontactEmailAddress").setValueAttribute("test@contact.com");
createForm.getTextAreaByName("ticketdescription").setText("something is not right.");
createForm.getSelectByName("tickettype").getOptions().get(2).setSelected(true);
createForm.getSelectByName("ticketpriority").getOptions().get(2).setSelected(true);
HtmlSubmitInput createButton = createForm.getInputByName("submitButton");
createButton.click();
Thread.sleep(WAIT_PAGE_REFRESH);
indexPage = webClient.getPage(startPageUrl);
HtmlPage overviewPage = indexPage.getAnchorByText("Ticket-Overview").click();
HtmlTable table = overviewPage.getFirstByXPath("//table");
HtmlTableRow ticketRow = table.getRow(2);
HtmlPage developerTicketPage = ticketRow.getCell(0).getHtmlElementsByTagName("a").get(0).click();
assertTrue(developerTicketPage.asText().contains("testname"));
assertTrue(developerTicketPage.asText().contains("something is not right."));
assertTrue(developerTicketPage.asText().contains("DeveloperTicket"));
HtmlForm develForm = developerTicketPage.getForms().get(1);
develForm.getInputByName("developerComment").setValueAttribute("done");
develForm.getInputByName("problemsOccurred").setValueAttribute("none");
develForm.getInputByName("workingHours").setValueAttribute("10");
develForm.getInputByValue("Finish Ticket").click();
Thread.sleep(WAIT_PAGE_REFRESH);
indexPage = webClient.getPage(startPageUrl);
overviewPage = indexPage.getAnchorByText("Ticket-Overview").click();
table = overviewPage.getFirstByXPath("//table");
ticketRow = table.getRow(2);
HtmlPage reviewerTicketPage = ticketRow.getCell(0).getHtmlElementsByTagName("a").get(0).click();
assertTrue(reviewerTicketPage.asText().contains("testname"));
assertTrue(reviewerTicketPage.asText().contains("something is not right."));
assertTrue(reviewerTicketPage.asText().contains("ReviewerTicket"));
HtmlForm reviewForm = reviewerTicketPage.getForms().get(1);
reviewForm.getTextAreaByName("feedback").setText("well done!");
HtmlCheckBoxInput box = reviewForm.getInputByName("ticketResolved");
box.setChecked(true);
reviewForm.getInputByValue("Finish Ticket").click();
Thread.sleep(WAIT_PAGE_REFRESH);
indexPage = webClient.getPage(startPageUrl);
overviewPage = indexPage.getAnchorByText("Ticket-Overview").click();
table = overviewPage.getFirstByXPath("//table");
ticketRow = table.getRow(2);
HtmlPage finalTaskViewPage = ticketRow.getCell(0).getHtmlElementsByTagName("a").get(0).click();
assertTrue(finalTaskViewPage.asText().contains("TaskFinalView"));
assertTrue(finalTaskViewPage.asText().contains("something is not right."));
assertTrue(finalTaskViewPage.asText().contains("done"));
HtmlForm closeForm = finalTaskViewPage.getForms().get(1);
closeForm.getInputByValue("Close").click();
Thread.sleep(WAIT_PAGE_REFRESH);
indexPage = webClient.getPage(startPageUrl);
overviewPage = indexPage.getAnchorByText("Ticket-Overview").click();
table = overviewPage.getFirstByXPath("//table");
assertEquals(3, table.getRows().size());
}Example 7
| Project: selenium-dsl-master File: HtmlUnitPage.java View source code |
public Table table(String id) {
final List<HtmlElement> elements = page.getElementsByIdAndOrName(id);
for (final HtmlElement htmlElement : elements) {
if (htmlElement instanceof HtmlTable) {
return new HtmlUnitTable((HtmlTable) htmlElement);
}
}
if (logger.isDebugEnabled()) {
final List<String> list = new ArrayList<String>();
for (final HtmlElement element : elements) {
if (element instanceof HtmlTable) {
list.add(element.toString());
}
}
logger.debug("Table with name or id " + id + " not found. Found tables: \n" + list);
}
return new InexistantTable(id);
}Example 8
| Project: gerrit-trigger-plugin-master File: ManualTriggerActionApprovalTest.java View source code |
/**
* Tests {@link ManualTriggerAction.Approval#getApprovals(net.sf.json.JSONObject, int)}.
* With an last patchset
*
* @throws Exception if so.
*/
@Test
public void testDoGerritSearchLastPatchSet() throws Exception {
JenkinsRule.WebClient client = j.createWebClient();
HtmlPage page = client.goTo("gerrit_manual_trigger");
HtmlForm theSearch = page.getFormByName("theSearch");
page = j.submit(theSearch);
HtmlTable table = page.getElementByName("searchResultTable");
HtmlTableCell verifiedCell = table.getCellAt(FIRST_RESULT_ROW, VERIFIED_COLUMN);
DomNode child = verifiedCell.getFirstChild();
assertThat(child, instanceOf(HtmlImage.class));
assertEquals("-1", ((HtmlImage) child).getAltAttribute());
HtmlTableCell codeReviewCell = table.getCellAt(FIRST_RESULT_ROW, CODE_REVIEW_COLUMN);
child = codeReviewCell.getFirstChild();
assertThat(child, instanceOf(HtmlImage.class));
assertEquals("2", ((HtmlImage) child).getAltAttribute());
}Example 9
| Project: openengsb-master File: TaskboxUiIT.java View source code |
@Test
public void testIfTaskOverviewInteractionWorks_shouldWork() throws Exception {
HtmlPage taskOverviewPage = webClient.getPage(pageEntryUrl);
assertTrue("Page does not contain: No Records Found", taskOverviewPage.asText().contains("No Records Found"));
assertEquals("The taskbox is not empty", 0, taskboxService.getOpenTasks().size());
workflowService.startFlow(WORKFLOW);
workflowService.startFlow(WORKFLOW);
assertEquals("The taskbox does not contain the new tasks", 2, taskboxService.getOpenTasks().size());
taskOverviewPage = taskOverviewPage.getAnchorByText("Task-Overview").click();
waitForTextOnPage(taskOverviewPage, new ElementCondition() {
@Override
public boolean isPresent(HtmlPage page) {
return page.getFirstByXPath("//table") != null;
}
});
HtmlTable table = taskOverviewPage.getFirstByXPath("//table");
assertNotNull("Table on Overviewpage not found", table);
assertEquals("Not all tasks found on page", 4, table.getRowCount());
HtmlTableRow headerRow = table.getRow(0);
assertTrue(headerRow.asText().contains("TaskId"));
HtmlTableRow actionsRow = table.getRow(1);
assertTrue(actionsRow.asText().contains("filter clear"));
HtmlTableRow taskOneRow = table.getRow(2);
assertTrue(taskOneRow.asText().contains("step1"));
assertEquals("even", taskOneRow.getAttribute("class"));
HtmlTableRow taskTwoRow = table.getRow(3);
assertTrue(taskTwoRow.asText().contains("step1"));
assertEquals("odd", taskTwoRow.getAttribute("class"));
String rowTwoText = taskTwoRow.asText();
taskOverviewPage = taskOneRow.getCell(0).getHtmlElementsByTagName("a").get(0).click();
// System.out.println(taskOverviewPage.asXml());
waitForTextOnPage(taskOverviewPage, new ElementCondition() {
@Override
public boolean isPresent(HtmlPage page) {
return page.getForms().size() == 2;
}
});
HtmlForm detailForm = taskOverviewPage.getForms().get(1);
HtmlSubmitInput finishButton = (HtmlSubmitInput) detailForm.getByXPath("input[@type=\"submit\"]").get(0);
detailForm.getInputByName("taskname").setValueAttribute("taskname");
detailForm.getTextAreaByName("taskdescription").setText("taskdescription");
taskOverviewPage = finishButton.click();
boolean isRight = false;
for (int i = 0; i < MAX_RETRY && !isRight; i++) {
try {
taskOverviewPage = webClient.getPage(pageEntryUrl);
table = taskOverviewPage.getFirstByXPath("//table");
taskOneRow = table.getRow(2);
taskTwoRow = table.getRow(3);
isRight = taskOneRow.asText().contains("step2") && taskOneRow.asText().contains("taskdescription") && taskTwoRow.asText().contains("step1") && table.getRowCount() == 4;
if (!isRight) {
Thread.sleep(3000);
}
} catch (Exception ex) {
}
}
if (!isRight) {
fail("Could not process click event in time!");
}
assertEquals("The taskbox should contain 2 tasks", 2, taskboxService.getOpenTasks().size());
taskOneRow.getCell(0).getHtmlElementsByTagName("a").get(0).click();
taskOneRow.getCell(0).getHtmlElementsByTagName("a").get(0).click();
waitForTextOnPage(taskOverviewPage, new ElementCondition() {
@Override
public boolean isPresent(HtmlPage page) {
return page.getForms().size() == 2;
}
});
detailForm = taskOverviewPage.getForms().get(1);
assertEquals("The taskname column is missing", "taskname", detailForm.getInputByName("taskname").getValueAttribute());
assertEquals("The taskdescription column is missing", "taskdescription", detailForm.getTextAreaByName("taskdescription").getText());
finishButton = (HtmlSubmitInput) detailForm.getByXPath("input[@type=\"submit\"]").get(0);
taskOverviewPage = finishButton.click();
isRight = false;
for (int i = 0; i < MAX_RETRY && !isRight; i++) {
try {
taskOverviewPage = webClient.getPage(pageEntryUrl);
table = taskOverviewPage.getFirstByXPath("//table");
taskOneRow = table.getRow(2);
isRight = taskOneRow.asText().contains("step1") && table.getRowCount() == 3;
if (!isRight) {
Thread.sleep(3000);
}
} catch (Exception ex) {
}
}
if (!isRight) {
fail("Could not process click event in time!");
}
assertEquals("The second row should not have changed", rowTwoText, taskOneRow.asText());
assertEquals("One task should be remaining", 1, taskboxService.getOpenTasks().size());
}Example 10
| Project: build-failure-analyzer-plugin-master File: CauseManagementHudsonTest.java View source code |
/**
* Verifies that the table on the {@link CauseManagement} page displays all causes with description and that
* one of them can be navigated to and a valid edit page for that cause is shown.
*
* @throws Exception if so.
*/
public void testTableViewNavigation() throws Exception {
KnowledgeBase kb = PluginImpl.getInstance().getKnowledgeBase();
//Overriding isStatisticsEnabled in order to display all fields on the management page:
KnowledgeBase mockKb = spy(kb);
when(mockKb.isStatisticsEnabled()).thenReturn(true);
Whitebox.setInternalState(PluginImpl.getInstance(), "knowledgeBase", mockKb);
List<String> myCategories = new LinkedList<String>();
myCategories.add("myCtegory");
//CS IGNORE MagicNumber FOR NEXT 5 LINES. REASON: TestData.
Date endOfWorld = new Date(1356106375000L);
Date birthday = new Date(678381175000L);
Date millenniumBug = new Date(946681200000L);
Date pluginReleased = new Date(1351724400000L);
FailureCause cause = new FailureCause(null, "SomeName", "A Description", "Some comment", endOfWorld, myCategories, null, Collections.singletonList(new FailureCauseModification("user", birthday)));
cause.addIndication(new BuildLogIndication("."));
kb.addCause(cause);
cause = new FailureCause(null, "SomeOtherName", "A Description", "Another comment", millenniumBug, myCategories, null, Collections.singletonList(new FailureCauseModification("user", pluginReleased)));
cause.addIndication(new BuildLogIndication("."));
kb.addCause(cause);
WebClient web = createWebClient();
HtmlPage page = web.goTo(CauseManagement.URL_NAME);
HtmlTable table = (HtmlTable) page.getElementById("failureCausesTable");
Collection<FailureCause> expectedCauses = kb.getShallowCauses();
int rowCount = table.getRowCount();
assertEquals(expectedCauses.size() + 1, rowCount);
Iterator<FailureCause> causeIterator = expectedCauses.iterator();
FailureCause firstCause = null;
for (int i = 1; i < rowCount; i++) {
assertTrue(causeIterator.hasNext());
FailureCause c = causeIterator.next();
HtmlTableRow row = table.getRow(i);
String name = row.getCell(NAME_CELL).getTextContent();
String categories = row.getCell(CATEGORY_CELL).getTextContent();
String description = row.getCell(DESCRIPTION_CELL).getTextContent();
String comment = row.getCell(COMMENT_CELL).getTextContent();
String modified = row.getCell(MODIFIED_CELL).getTextContent();
String lastSeen = row.getCell(LAST_SEEN_CELL).getTextContent();
assertEquals(c.getName(), name);
assertEquals(c.getCategoriesAsString(), categories);
assertEquals(c.getDescription(), description);
assertEquals(c.getComment(), comment);
assertEquals("Modified date should be visible", DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(c.getLatestModification().getTime()) + " by user", modified);
assertEquals("Last seen date should be visible", DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(c.getLastOccurred()), lastSeen);
if (i == 1) {
firstCause = c;
}
}
//The table looks ok, now lets see if we can navigate correctly.
assertNotNull(firstCause);
HtmlAnchor firstCauseLink = (HtmlAnchor) table.getCellAt(1, 0).getFirstChild();
HtmlPage editPage = firstCauseLink.click();
verifyCorrectCauseEditPage(firstCause, editPage);
}Example 11
| Project: hudson-test-harness-master File: TestResultPublishingTest.java View source code |
/**
* Make sure the open junit publisher shows junit history
* @throws IOException
* @throws SAXException
*/
@LocalData
public void testHistoryPageOpenJunit() throws IOException, SAXException {
List<Project> projects = this.hudson.getProjects();
// Make sure there's a project named breakable
Project proj = null;
for (Project p : projects) {
if (p.getName().equals(TEST_PROJECT_WITH_HISTORY)) {
proj = p;
break;
}
}
assertNotNull("We should have a project named " + TEST_PROJECT_WITH_HISTORY, proj);
// Validate that there are test results where I expect them to be:
HudsonTestCase.WebClient wc = new HudsonTestCase.WebClient();
HtmlPage historyPage = wc.getPage(proj.getBuildByNumber(7), "/testReport/history/");
assertGoodStatus(historyPage);
assertXPath(historyPage, "//img[@id='graph']");
assertXPath(historyPage, "//table[@id='testresult']");
HtmlElement wholeTable = historyPage.getElementById("testresult");
assertNotNull("table with id 'testresult' exists", wholeTable);
assertTrue("wholeTable is a table", wholeTable instanceof HtmlTable);
HtmlTable table = (HtmlTable) wholeTable;
// We really want to call table.getRowCount(), but
// it returns 1, not the real answer,
// because this table has *two* tbody elements,
// and getRowCount() only seems to count the *first* tbody.
// Maybe HtmlUnit can't handle the two tbody's. In any case,
// the tableText.contains tests do a (ahem) passable job
// of detecting whether the history results are present.
String tableText = table.getTextContent();
assertTrue("Table text is missing the project name", tableText.contains(TEST_PROJECT_WITH_HISTORY));
assertTrue("Table text is missing the build number", tableText.contains("7"));
assertTrue("Table text is missing the test duration", tableText.contains("4 ms"));
}Example 12
| Project: testcases-master File: OIDCTest.java View source code |
// Runs as BeforeClass: Login to the OIDC Clients page + create a new client
private static void loginToClientsPage(String rpPort, String oidcPort, String idpPort) throws Exception {
String url = "https://localhost:" + oidcPort + "/fediz-oidc/console/clients";
String user = "alice";
String password = "ecila";
// Login to the client page successfully
WebClient webClient = setupWebClient(user, password, idpPort);
HtmlPage loginPage = login(url, webClient);
final String bodyTextContent = loginPage.getBody().getTextContent();
Assert.assertTrue(bodyTextContent.contains("Registered Clients"));
String clientUrl = "https://localhost:" + rpPort + "/fedizdoubleit/auth/rp/complete";
// Now try to register a new client
HtmlPage registeredClientPage = registerNewClient(webClient, url, "consumer-id", clientUrl, clientUrl);
String registeredClientPageBody = registeredClientPage.getBody().getTextContent();
Assert.assertTrue(registeredClientPageBody.contains("Registered Clients"));
Assert.assertTrue(registeredClientPageBody.contains("consumer-id"));
HtmlTable table = registeredClientPage.getHtmlElementById("registered_clients");
storedClientId = table.getCellAt(1, 1).asText().trim();
Assert.assertNotNull(storedClientId);
// Now get the Client Secret
final HtmlPage clientPage = webClient.getPage(url + "/" + storedClientId);
HtmlTable clientPageTable = clientPage.getHtmlElementById("client");
storedClientSecret = clientPageTable.getCellAt(1, 2).asText().trim();
Assert.assertNotNull(storedClientSecret);
webClient.close();
}Example 13
| Project: cincinnati-library-auto-renew-master File: LibraryRenewer.java View source code |
private static List<AvailableItemStatus> statusesInTable(HtmlTable table) {
ArrayList<AvailableItemStatus> result = new ArrayList<AvailableItemStatus>();
int statusCol = -1;
int rowId = 0;
for (final HtmlTableRow row : table.getRows()) {
int colId = 0;
for (final HtmlTableCell cell : row.getCells()) {
if (rowId == 0) {
if (cell.asText().trim().equalsIgnoreCase("status")) {
statusCol = colId;
break;
}
} else {
if (colId == statusCol) {
result.add(AvailableItemStatus.findOrCreate(cell.asText().trim()));
}
}
++colId;
}
++rowId;
}
return result;
}Example 14
| Project: hudson_plugins-master File: CombinationOfParsersAndLabelsTest.java View source code |
private void assertGoodHistoryPage(HtmlPage page) {
String uri = page.getDocumentURI();
assertTrue("good http status for " + uri, isGoodHttpStatus(page.getWebResponse().getStatusCode()));
// The page should not say "More than 1 builds are needed for the chart."
final String NO_HISTORY_CHART_MSG = "More than 1 builds are needed for the chart.";
final String PROGRAMMING_ERROR_MSG = "programming error";
String pageText = page.asText();
assertFalse("should not say 'more than 1 builds are needed for the chart on page '" + uri, pageText.contains(NO_HISTORY_CHART_MSG));
assertFalse("should not say 'programming error' on page" + uri, pageText.contains(PROGRAMMING_ERROR_MSG));
HtmlElement wholeTable = page.getElementById("testresult");
assertNotNull("table with id 'testresult' exists on page " + uri, wholeTable);
assertTrue("wholeTable is a table on page " + uri, wholeTable instanceof HtmlTable);
HtmlTable table = (HtmlTable) wholeTable;
// We really want to call table.getRowCount(), but
// it returns 1, not the real answer,
// because this table has *two* tbody elements,
// and getRowCount() only seems to count the *first* tbody.
// Maybe HtmlUnit can't handle the two tbody's. In any case,
// the tableText.contains tests do a (ahem) passable job
// of detecting whether the history results are present.
String tableText = table.getTextContent();
assertTrue("table text should have header that says Fail on page " + uri, tableText.contains("Fail"));
assertTrue("table text should have header that says Skip on page " + uri, tableText.contains("Skip"));
// assert that there is a table with some interesting history in it
assertTrue("table text content should have the project name in it on page " + uri, tableText.contains(JUST_JAVA_GROUPS));
assertTrue("table text content should have some build numbers in it on page " + uri, tableText.contains("#1"));
}Example 15
| Project: alma-toolkit-master File: TaskUpdateResourcePartners.java View source code |
public ConcurrentMap<String, Partner> getLaddPartners() {
String prefix = "NLA";
String institutionCode = config.getProperty("ladd.institution.code");
ConcurrentMap<String, Partner> result = new ConcurrentHashMap<String, Partner>();
WebClient webClient = webClientProvider.get();
HtmlPage page = null;
try {
page = webClient.getPage(laddUrl);
} catch (IOException e) {
log.error("unable to acquire page: {}", laddUrl);
return result;
}
HtmlTable table = (HtmlTable) page.getElementById("suspension");
for (HtmlTableRow row : table.getRows()) {
String nuc = null;
try {
nuc = row.getCell(0).asText();
if ("NUC symbol".equals(nuc) || institutionCode.equals(nuc)) {
log.debug("skipping nuc: {}", nuc);
continue;
}
String org = row.getCell(1).asText();
org = org.replace("&", "and");
boolean suspended = "Suspended".equals(row.getCell(3).asText());
Partner partner = new Partner();
partner.setLink("https://api-ap.hosted.exlibrisgroup.com/almaws/v1/partners/" + nuc);
PartnerDetails partnerDetails = new PartnerDetails();
partner.setPartnerDetails(partnerDetails);
ProfileDetails profileDetails = new ProfileDetails();
partnerDetails.setProfileDetails(profileDetails);
profileDetails.setProfileType(ProfileType.ISO);
RequestExpiryType requestExpiryType = new RequestExpiryType();
requestExpiryType.setValue("INTEREST_DATE");
requestExpiryType.setDesc("Expire by interest date");
IsoDetails isoDetails = new IsoDetails();
profileDetails.setIsoDetails(isoDetails);
isoDetails.setAlternativeDocumentDelivery(false);
isoDetails.setIllServer(config.getProperty("alma.ill.server"));
isoDetails.setIllPort(Integer.parseInt(config.getProperty("alma.ill.port")));
isoDetails.setIsoSymbol(prefix + ":" + nuc);
isoDetails.setSendRequesterInformation(false);
isoDetails.setSharedBarcodes(true);
isoDetails.setRequestExpiryType(requestExpiryType);
SystemType systemType = new SystemType();
systemType.setValue("LADD");
systemType.setDesc("LADD");
LocateProfile locateProfile = new LocateProfile();
locateProfile.setValue("LADD");
locateProfile.setDesc("LADD Locate Profile");
partnerDetails.setStatus(suspended ? Status.INACTIVE : Status.ACTIVE);
partnerDetails.setCode(nuc);
partnerDetails.setName(org);
partnerDetails.setSystemType(systemType);
partnerDetails.setAvgSupplyTime(4);
partnerDetails.setDeliveryDelay(4);
partnerDetails.setCurrency("AUD");
partnerDetails.setBorrowingSupported(true);
partnerDetails.setBorrowingWorkflow("LADD_Borrowing");
partnerDetails.setLendingSupported(true);
partnerDetails.setLendingWorkflow("LADD_Lending");
partnerDetails.setLocateProfile(locateProfile);
partnerDetails.setHoldingCode(nuc);
ContactInfo contactInfo = new ContactInfo();
partner.setContactInfo(contactInfo);
Addresses addresses = new Addresses();
contactInfo.setAddresses(addresses);
Emails emails = new Emails();
contactInfo.setEmails(emails);
Phones phones = new Phones();
contactInfo.setPhones(phones);
Notes notes = new Notes();
partner.setNotes(notes);
result.put(partner.getPartnerDetails().getCode(), partner);
} catch (Exception e) {
log.error("failed to process partner: {}", nuc);
}
}
return result;
}Example 16
| Project: matrix-project-plugin-master File: MatrixProjectTest.java View source code |
void assertRectangleTable(MatrixProject p) throws Exception {
HtmlPage html = j.createWebClient().getPage(p);
HtmlTable table = html.getFirstByXPath("id('matrix')/table");
// remember cells that are extended from rows above.
Map<Integer, Integer> rowSpans = new HashMap<Integer, Integer>();
Integer masterWidth = null;
for (HtmlTableRow r : table.getRows()) {
int width = 0;
for (HtmlTableCell c : r.getCells()) {
width += c.getColumnSpan();
}
for (Integer val : rowSpans.values()) {
width += val;
}
if (masterWidth == null) {
masterWidth = width;
} else {
assertEquals(masterWidth.intValue(), width);
}
for (HtmlTableCell c : r.getCells()) {
int rowSpan = c.getRowSpan();
Integer val = rowSpans.get(rowSpan);
rowSpans.put(rowSpan, (val != null ? val : 0) + c.getColumnSpan());
}
// shift rowSpans by one
Map<Integer, Integer> nrs = new HashMap<Integer, Integer>();
for (Map.Entry<Integer, Integer> entry : rowSpans.entrySet()) {
if (entry.getKey() > 1) {
nrs.put(entry.getKey() - 1, entry.getValue());
}
}
rowSpans = nrs;
}
}Example 17
| Project: JSCover-master File: HtmlUnitServerTest.java View source code |
@Test
public void shouldDisplayCoverageInformationOnSourcePage() throws IOException {
HtmlPage page = webClient.getPage("http://localhost:9001/jscoverage.html?" + getTestUrl());
HtmlPage frame = (HtmlPage) page.getFrameByName("browserIframe").getEnclosedPage();
verifyTotal(webClient, page, 15);
page.getAnchorByText("/example/script.js").click();
webClient.waitForBackgroundJavaScript(2000);
HtmlTable sourceTable = (HtmlTable) page.getElementById("sourceTable");
verifySource(sourceTable, 11, 0, " else if (element.id === 'radio2') {");
verifySource(sourceTable, 12, 0, " message = getMessage(2);");
frame.getHtmlElementById("radio2").click();
webClient.waitForBackgroundJavaScript(500);
verifyTotal(webClient, page, 68, 0, 0);
page.getAnchorByText("/example/script.js").click();
webClient.waitForBackgroundJavaScript(2000);
sourceTable = (HtmlTable) page.getElementById("sourceTable");
verifySource(sourceTable, 11, 1, " else if (element.id === 'radio2') {");
verifySource(sourceTable, 12, 1, " message = getMessage(2);");
}Example 18
| Project: webtest-master File: TableLocator.java View source code |
public String locateText(final Context context, Step step) throws TableNotFoundException, IndexOutOfBoundsException, SAXException {
try {
final HtmlElement htmlElement;
if (getHtmlId() == null) {
htmlElement = findFirstTable(context, step);
} else {
htmlElement = context.getCurrentHtmlResponse(step).getHtmlElementById(getHtmlId());
}
if (!(htmlElement instanceof HtmlTable)) {
throw new StepFailedException("Found '" + htmlElement.getTagName() + "' element when looking for 'table' element using htmlId " + getHtmlId(), step);
}
final HtmlTable table = (HtmlTable) htmlElement;
return table.getRow(getRow()).getCell(getColumn()).asText();
} catch (final ElementNotFoundException e) {
throw new TableNotFoundException(getHtmlId());
}
}Example 19
| Project: cxf-fediz-master File: OIDCTest.java View source code |
// Runs as BeforeClass: Login to the OIDC Clients page + create two new clients
private static void loginToClientsPage(String rpPort, String idpPort) throws Exception {
String url = "https://localhost:" + rpPort + "/fediz-oidc/console/clients";
String user = "alice";
String password = "ecila";
// Login to the client page successfully
WebClient webClient = setupWebClient(user, password, idpPort);
HtmlPage loginPage = login(url, webClient);
final String bodyTextContent = loginPage.getBody().getTextContent();
Assert.assertTrue(bodyTextContent.contains("Registered Clients"));
// Now try to register a new client
HtmlPage registeredClientPage = registerNewClient(webClient, url, "new-client", "https://127.0.0.1", "https://cxf.apache.org", "https://localhost:12345");
String registeredClientPageBody = registeredClientPage.getBody().getTextContent();
Assert.assertTrue(registeredClientPageBody.contains("Registered Clients"));
Assert.assertTrue(registeredClientPageBody.contains("new-client"));
Assert.assertTrue(registeredClientPageBody.contains("https://127.0.0.1"));
HtmlTable table = registeredClientPage.getHtmlElementById("registered_clients");
storedClientId = table.getCellAt(1, 1).asText().trim();
Assert.assertNotNull(storedClientId);
// Try to register another new client
registeredClientPage = registerNewClient(webClient, url, "new-client2", "https://127.0.1.1", "https://ws.apache.org", "https://localhost:12345");
registeredClientPageBody = registeredClientPage.getBody().getTextContent();
Assert.assertTrue(registeredClientPageBody.contains("Registered Clients"));
Assert.assertTrue(registeredClientPageBody.contains("new-client"));
Assert.assertTrue(registeredClientPageBody.contains("https://127.0.0.1"));
Assert.assertTrue(registeredClientPageBody.contains("new-client2"));
Assert.assertTrue(registeredClientPageBody.contains("https://127.0.1.1"));
table = registeredClientPage.getHtmlElementById("registered_clients");
storedClient2Id = table.getCellAt(2, 1).asText().trim();
if (storedClient2Id.equals(storedClientId)) {
storedClient2Id = table.getCellAt(1, 1).asText().trim();
}
Assert.assertNotNull(storedClient2Id);
webClient.close();
}Example 20
| Project: tecnologia-e-applicazioni-internet-2010-master File: CourseListEndToEndTest.java View source code |
private int numberOfCoursesListed() {
HtmlTable table = (HtmlTable) page.getElementById("courses");
assertNotNull("courses table not found", table);
return table.getRowCount();
}Example 21
| Project: sling-master File: MetricWebConsolePluginTest.java View source code |
private void assertTable(String name, HtmlPage page) {
HtmlTable table = page.getHtmlElementById(name);
assertNotNull(table);
//1 for header and 1 for actual metric row
assertThat(table.getRowCount(), greaterThanOrEqualTo(2));
}Example 22
| Project: ci-game-plugin-master File: ScoreCardActionIntegrationTest.java View source code |
@LocalData
public void testThatUsernameWithDifferentCasingIsDisplayedAsOne() throws Exception {
hudson.getDescriptorByType(GameDescriptor.class).setNamesAreCaseSensitive(false);
HtmlTable table = (HtmlTable) new WebClient().goTo("job/multiple-culprits/4/cigame/").getHtmlElementById("game.culprits");
assertThat(table.getRowCount(), is(2));
}