public HtmlAnchor getTestReportAnchor(String testUrl) throws IOException, SAXException { return htmlPage.getAnchorByHref(getHrefFromTestUrl(testUrl)); } public void assertNoLink(String url) {
try (WebClient webClient = new WebClient(BrowserVersion.CHROME)) { new WebConnectionWrapper(webClient) { public WebResponse getResponse(WebRequest request) throws IOException { WebResponse response = super.getResponse(request); if (request.getUrl().toExternalForm().endsWith("identifier_select")) { String content = response.getContentAsString("UTF-8"); content = content.replace(">$J( function()", "$J( function()"); WebResponseData data = new WebResponseData(content.getBytes("UTF-8"), response.getStatusCode(), response.getStatusMessage(), response.getResponseHeaders()); response = new WebResponse(data, request, response.getLoadTime()); } return response; } }; HtmlPage page = webClient.getPage("http://www.tf2outpost.com"); HtmlAnchor a = page.getAnchorByHref("/login"); page = a.click(); page.<HtmlInput>getHtmlElementById("steamAccountName").setValueAttribute(username); page.<HtmlInput>getHtmlElementById("steamPassword").setValueAttribute(password); page = page.<HtmlInput>getHtmlElementById("imageLogin").click(); webClient.waitForBackgroundJavaScript(5000); System.out.println(page.asXml());
private HtmlAnchor findRenameAnchor(AbstractItem item) throws Exception { JenkinsRule.WebClient w = r.createWebClient(); HtmlPage page = w.goTo(item.getUrl()); String relativeUrl = r.contextPath + "/" + item.getUrl() + item.getAction(RenameAction.class).getUrlName(); return page.getAnchorByHref(relativeUrl); }
private void testSetDescription(String url, TestObject object) throws Exception { object.doSubmitDescription("description"); // test the roundtrip final WebClient wc = j.createWebClient(); HtmlPage page = wc.goTo(url); page.getAnchorByHref("editDescription").click(); wc.waitForBackgroundJavaScript(10000L); HtmlForm form = findForm(page, "submitDescription"); j.submit(form); assertEquals("description", object.getDescription()); }
/** * Tests if the html-link to {@link ManualTriggerAction#getUrlName()} is visible from the main-page. * It should be hidden from an Anonymous user as configured in the test-configuration. * * @throws Exception if so. */ @LocalData public void testGetGetUrlNameNotPermitted() throws Exception { //add a server so that the manual trigger action URL can be accessed by users with proper access rights. PluginImpl.getInstance().addServer(new GerritServer("testServer")); ManualTriggerAction action = getManualTriggerAction(); WebClient wc = createWebClient(); HtmlPage page = wc.goTo("/"); try { HtmlAnchor a = page.getAnchorByHref(action.getUrlName()); assertNull(a); } catch (ElementNotFoundException e) { return; } fail("Anonymous should not see the RootAction"); }
/** * Tests if the html-link to {@link ManualTriggerAction#getUrlName()} is visible from the main-page. * It should be visible to Administrators as configured in the test-configuration. * * @throws Exception if so. */ @LocalData public void testGetUrlName() throws Exception { //add a server so that the manual trigger action URL can be accessed by users with proper access rights. PluginImpl.getInstance().addServer(new GerritServer("testServer")); ManualTriggerAction action = getManualTriggerAction(); WebClient wc = new WebClient().login("admin", "admin"); HtmlPage page = wc.goTo("/"); try { HtmlAnchor a = page.getAnchorByHref(action.getUrlName()); assertNotNull(a); } catch (ElementNotFoundException e) { fail("Admin should see the RootAction"); } }
/** * Tests if the html-link to {@link ManualTriggerAction#getUrlName()} is visible from the main-page. * It should be visible to Privileged Users as configured in the test-configuration. * * @throws Exception if so. */ @LocalData public void testGetUrlNamePrivileged() throws Exception { //add a server so that the manual trigger action URL can be accessed by users with proper access rights. PluginImpl.getInstance().addServer(new GerritServer("testServer")); ManualTriggerAction action = getManualTriggerAction(); WebClient wc = new WebClient().login("bobby", "bobby"); HtmlPage page = wc.goTo("/"); try { HtmlAnchor a = page.getAnchorByHref(action.getUrlName()); assertNotNull(a); } catch (ElementNotFoundException e) { fail("Bobby should see the RootAction"); } }
story.j.createWebClient().login("admin").getPage(b).getAnchorByHref(toggleUrlAbs); try { story.j.createWebClient().getPage(b).getAnchorByHref(toggleUrlAbs); fail("link should not be present for anonymous user without CANCEL"); } catch (ElementNotFoundException x) {