/** * Returns the first anchor with the specified text. * @param text the text to search for * @return the first anchor that was found * @throws ElementNotFoundException if no anchors are found with the specified text * @deprecated As of 2.6, please use {@link #getAnchorByText(String)} instead */ @Deprecated public HtmlAnchor getFirstAnchorByText(final String text) throws ElementNotFoundException { return getAnchorByText(text); }
/** * Returns the first anchor with the specified text. * @param text the text to search for * @return the first anchor that was found * @throws ElementNotFoundException if no anchors are found with the specified text * @deprecated As of 2.6, please use {@link #getAnchorByText(String)} instead */ @Deprecated public HtmlAnchor getFirstAnchorByText(final String text) throws ElementNotFoundException { return getAnchorByText(text); }
/** * Returns the first anchor with the specified text. * @param text the text to search for * @return the first anchor that was found * @throws ElementNotFoundException if no anchors are found with the specified text * @deprecated As of 2.6, please use {@link #getAnchorByText(String)} instead */ @Deprecated public HtmlAnchor getFirstAnchorByText(final String text) throws ElementNotFoundException { return getAnchorByText(text); }
public void hasLinkToTest(String testName) { htmlPage.getAnchorByText(testName); }
public void hasLinkToTestResultOfBuild(String projectName, int buildNumber) { htmlPage.getAnchorByText(projectName + " #" + buildNumber); } }
LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog"); java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF); java.util.logging.Logger.getLogger("org.apache.commons.httpclient").setLevel(Level.OFF); WebClient webClient = new WebClient(BrowserVersion.CHROME); webClient.getOptions().setJavaScriptEnabled(true); webClient.getOptions().setThrowExceptionOnScriptError(false); webClient.getOptions().setThrowExceptionOnFailingStatusCode(false); HtmlPage currentPage = webClient.getPage("http://www.google.com/"); HtmlAnchor advancedSearchAn = currentPage.getAnchorByText("About"); currentPage = advancedSearchAn.click();
WebClient webClient = new WebClient(); HtmlPage page = webClient.getPage("http://yourpage.com"); HtmlAnchor anchor = page.getAnchorByText("Enter a"); page = anchor.click();
WebClient webClient = new WebClient(BrowserVersion.CHROME); webClient.getOptions().setJavaScriptEnabled(true); webClient.getOptions().setThrowExceptionOnScriptError(false); webClient.getOptions().setThrowExceptionOnFailingStatusCode(false); HtmlPage page = webClient.getPage("https://scholar.google.com/"); HtmlInput searchBox = (HtmlInput) page.getElementById("gs_hp_tsi"); searchBox.setValueAttribute("internet of things for smart cities"); HtmlButton googleSearchSubmitButton = page.getElementByName("btnG"); page = googleSearchSubmitButton.click(); HtmlAnchor anchor = page.getAnchorByText("Cite"); anchor.click(); webClient.waitForBackgroundJavaScript(5000); HtmlAnchor linkBibTex = page.getAnchorByText("BibTeX"); TextPage neededPage = linkBibTex.click(); System.out.println(neededPage.getContent()); webClient.close();
public void testTomcat() throws Exception { HtmlPage page = null; try { page = client.getPage(url); } catch (HttpHostConnectException e) { // sometimes on jenkins there are connections exceptions. // ignoring the rest of the test in this case LOG.error("Failed connecting to tomcat", e); return; } assertEquals("Content Repository Setup", page.getTitleText()); page = submitNewRepositoryForm(page); assertEquals("Content Repository Ready", page.getTitleText()); page = page.getAnchorByText("home").click(); assertEquals("Apache Jackrabbit JCR Server", page.getTitleText()); }
@LocalData @Test public void testFailureLinks() throws Exception { FreeStyleBuild build = project.scheduleBuild2(0).get(10, TimeUnit.SECONDS); rule.assertBuildStatus(Result.UNSTABLE, build); TestResult theOverallTestResult = build.getAction(TestResultAction.class).getResult(); CaseResult theFailedTestCase = theOverallTestResult.getFailedTests().get(0); String relativePath = theFailedTestCase.getRelativePathFrom(theOverallTestResult); System.out.println("relative path seems to be: " + relativePath); WebClient wc = rule.createWebClient(); String testReportPageUrl = project.getLastBuild().getUrl() + "/testReport"; HtmlPage testReportPage = wc.goTo( testReportPageUrl ); Page packagePage = testReportPage.getAnchorByText("tacoshack.meals").click(); rule.assertGoodStatus(packagePage); // I expect this to work; just checking that my use of the APIs is correct. // Now we're on that page. We should be able to find a link to the failed test in there. HtmlAnchor anchor = testReportPage.getAnchorByText("tacoshack.meals.NachosTest.testBeanDip"); String href = anchor.getHrefAttribute(); System.out.println("link is : " + href); Page failureFromLink = anchor.click(); rule.assertGoodStatus(failureFromLink); // Now check the >>> link -- this is harder, because we can't do the javascript click handler properly // The summary page is just tack on /summary to the url for the test }
createWebClient().getPage(project).getAnchorByText("Rebuild Last") .click();
/** * Creates a new freestyle project and builds the project with a string * parameter. If the build is succesful, a rebuild of the last build is * done. The rebuild on the project level should point to the last build * * @throws Exception * Exception */ public void testWhenProjectWithParamsThenRebuildProjectExecutesRebuildOfLastBuild() throws Exception { FreeStyleProject project = createFreeStyleProject(); project.addProperty(new ParametersDefinitionProperty( new StringParameterDefinition("name", "defaultValue"))); // Build (#1) project.scheduleBuild2(0, new Cause.UserIdCause(), new ParametersAction(new StringParameterValue("name", "test"))) .get(); HtmlPage rebuildConfigPage = createWebClient().getPage(project, "1/rebuild"); // Rebuild (#2) submit(rebuildConfigPage.getFormByName("config")); HtmlPage projectPage = createWebClient().getPage(project); WebAssert.assertLinkPresentWithText(projectPage, "Rebuild Last"); HtmlAnchor rebuildHref = projectPage.getAnchorByText("Rebuild Last"); assertEquals("Rebuild Last should point to the second build", "/" + project.getUrl() + "lastCompletedBuild/rebuild", rebuildHref.getHrefAttribute()); }
HtmlAnchor failingTestLink = buildPage.getAnchorByText("org.jvnet.hudson.examples.small.MiscTest.testEleanor"); assertNotNull(failingTestLink); Page failingTestPage = failingTestLink.click();