@Test public void privateView() throws Exception { j.createFreeStyleProject("project1"); User user = User.get("me", true); // create user WebClient wc = j.createWebClient(); HtmlPage userPage = wc.goTo("user/me"); HtmlAnchor privateViewsLink = userPage.getFirstAnchorByText("My Views"); assertNotNull("My Views link not available", privateViewsLink); HtmlPage privateViewsPage = (HtmlPage) privateViewsLink.click(); Text viewLabel = (Text) privateViewsPage.getFirstByXPath("//div[@class='tabBar']//div[@class='tab active']/a/text()"); assertTrue("'All' view should be selected", viewLabel.getTextContent().contains(Hudson_ViewName())); View listView = listView("listView"); HtmlPage newViewPage = wc.goTo("user/me/my-views/newView"); HtmlForm form = newViewPage.getFormByName("createItem"); form.getInputByName("name").setValueAttribute("proxy-view"); ((HtmlRadioButtonInput) form.getInputByValue("hudson.model.ProxyView")).setChecked(true); HtmlPage proxyViewConfigurePage = j.submit(form); View proxyView = user.getProperty(MyViewsProperty.class).getView("proxy-view"); assertNotNull(proxyView); form = proxyViewConfigurePage.getFormByName("viewConfig"); form.getSelectByName("proxiedViewName").setSelectedAttribute("listView", true); j.submit(form); assertTrue(proxyView instanceof ProxyView); assertEquals(((ProxyView) proxyView).getProxiedViewName(), "listView"); assertEquals(((ProxyView) proxyView).getProxiedView(), listView); }
public void testPreview() throws Exception { String name = uniqueWikiPageName("PreviewPageTest"); HtmlPage editPage = clickEditLink(getWikiPage(name)); HtmlForm form = editPage.getFormByName(ID_EDIT_FORM); HtmlInput minorEdit = form.getInputByName("minorEdit"); assertFalse(minorEdit.isChecked()); minorEdit.setChecked(true); HtmlInput description = form.getInputByName("description"); String expectedDescription = "My test change"; description.setValueAttribute(expectedDescription); HtmlTextArea content = form.getTextAreaByName("content"); String expectedContent = "http://www.example.com"; content.setText(expectedContent); // Now if we preview we should get the previewed text rendered, and in // the edit area. The other options should be preserved too. editPage = (HtmlPage) form.getInputByValue("Preview").click(); form = editPage.getFormByName(ID_EDIT_FORM); minorEdit = form.getInputByName("minorEdit"); description = form.getInputByName("description"); content = form.getTextAreaByName("content"); assertEquals(expectedDescription, description.getValueAttribute()); assertTrue(minorEdit.isChecked()); assertEquals(expectedContent + NEWLINE_TEXTAREA, content.getText()); // This checks for the rendering... assertNotNull(editPage.getAnchorByHref(expectedContent)); }
@Override protected String getCallbackUrl(final HtmlPage authorizationPage) throws Exception { HtmlForm form = authorizationPage.getFormByName("loginform"); final HtmlTextInput login = form.getInputByName("log"); login.setValueAttribute("testscribeup"); final HtmlPasswordInput passwd = form.getInputByName("pwd"); passwd.setValueAttribute("testpwdscribeup"); HtmlElement button = (HtmlElement) authorizationPage.createElement("button"); button.setAttribute("type", "submit"); form.appendChild(button); // HtmlButton button = form.getButtonByName("wp-submit"); final HtmlPage confirmPage = button.click(); form = confirmPage.getFormByName("loginform"); button = (HtmlElement) confirmPage.createElement("button"); button.setAttribute("type", "submit"); form.appendChild(button); // button = form.getButtonByName("wp-submit"); final HtmlPage callbackPage = button.click(); final String callbackUrl = callbackPage.getUrl().toString(); logger.debug("callbackUrl : {}", callbackUrl); return callbackUrl; }
public void testPreviewDiffBug() throws Exception { // https://bugs.corefiling.com/show_bug.cgi?id=13510 // Old versions of the diff_match_patch package have a bug in the diff_cleanupSemantic method // The two comparison strings need to be well crafted to trigger the bug. String name = uniqueWikiPageName("PreviewPageTest"); String content = "=" + NEWLINE_TEXTAREA + "This is a lis of things that someone be doing if" + NEWLINE_TEXTAREA + "===Wiki" + NEWLINE_TEXTAREA; String newContent = "||" + NEWLINE_TEXTAREA + "=="; HtmlPage edited = editWikiPage(name, content, "", "", true); HtmlPage editPage = clickEditLink(edited); HtmlForm form = editPage.getFormByName(ID_EDIT_FORM); HtmlTextArea contentArea = form.getTextAreaByName("content"); contentArea.setText(newContent); editPage = (HtmlPage) form.getInputByValue("Preview").click(); form = editPage.getFormByName(ID_EDIT_FORM); contentArea = form.getTextAreaByName("content"); assertEquals(newContent + NEWLINE_TEXTAREA, contentArea.getText()); }
@Test public void testConfigurationAuthentication() throws Exception { prepareSecurity(); FreeStyleProject p = j.createFreeStyleProject(); WebClient wc = j.createWebClient(); wc.login("test1"); // Reauthentication is not required if No need for re-authentication is checked p.addProperty( new AuthorizeProjectProperty(new SpecificUsersAuthorizationStrategy("admin", true))); j.submit(wc.getPage(p, "configure").getFormByName("config")); // Reauthentication is required if No need for re-authentication is checked p.removeProperty(AuthorizeProjectProperty.class); p.addProperty( new AuthorizeProjectProperty(new SpecificUsersAuthorizationStrategy("admin", false))); try { j.submit(wc.getPage(p, "configure").getFormByName("config")); fail(); } catch (FailingHttpStatusCodeException e) { assertEquals(400, e.getStatusCode()); } // No authentication is required if oneself. { HtmlPage page = wc.getPage(p, "configure"); HtmlTextInput userid = page.<HtmlTextInput>getFirstByXPath( "//*[contains(@class, 'specific-user-authorization')]//input[contains(@name, 'userid') and @type='text']"); userid.setValueAttribute("test1"); j.submit(page.getFormByName("config")); assertEquals( "test1", ((SpecificUsersAuthorizationStrategy) p.getProperty(AuthorizeProjectProperty.class).getStrategy()) .getUserid()); } // Reauthentication is required to change userid even if No need for re-authentication is // checked p.addProperty( new AuthorizeProjectProperty(new SpecificUsersAuthorizationStrategy("admin", true))); { HtmlPage page = wc.getPage(p, "configure"); HtmlTextInput userid = page.<HtmlTextInput>getFirstByXPath( "//*[contains(@class, 'specific-user-authorization')]//input[contains(@name, 'userid') and @type='text']"); userid.setValueAttribute("test2"); try { j.submit(page.getFormByName("config")); fail(); } catch (FailingHttpStatusCodeException e) { assertEquals(400, e.getStatusCode()); } } }
private void editThenCancel(final String name) throws Exception { final String flagText = "Should not be saved."; HtmlPage editPage = clickEditLink(getWikiPage(name)); HtmlForm form = editPage.getFormByName(ID_EDIT_FORM); form.getTextAreaByName("content").setText(flagText); HtmlPage viewPage = (HtmlPage) form.getInputByValue("Cancel").click(); assertFalse(viewPage.asText().contains(flagText)); try { viewPage.getFormByName(ID_EDIT_FORM); fail("Should be back to view page, not edit form."); } catch (ElementNotFoundException ignore) { } assertEquals("Should not be present.", 0, viewPage.getByXPath("id('lockedInfo')").size()); }
public boolean athenticated() { web = new WebClient(); try { page1 = web.getPage(url); } catch (FailingHttpStatusCodeException | IOException e) { e.printStackTrace(); } HtmlForm form = page1.getFormByName("form2"); form.getInputByName("txtUserName").setAttribute("value", username); form.getInputByName("txtPassword").setAttribute("value", password); try { page2 = form.getInputByName("LoginButton").click(); } catch (ElementNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } if (page2.getUrl().toString().equals("http://78.39.200.210/Default.aspx")) { return true; } else { web.closeAllWindows(); return false; } }
public void testDoDelete() throws Exception { UpdateSite target = new UpdateSite("test1", "http://example.com/test/update-center.json"); Jenkins.getInstance().getUpdateCenter().getSites().clear(); Jenkins.getInstance().getUpdateCenter().getSites().add(target); int initialSize = Jenkins.getInstance().getUpdateCenter().getSites().size(); WebClient wc = new WebClient(); HtmlPage deleteSitePage = wc.goTo(String.format("%s/%s/delete", UpdateSitesManager.URL, target.getId())); assertEquals( "UpdateSite must not be deleted yet.", initialSize, Jenkins.getInstance().getUpdateCenter().getSites().size()); HtmlForm deleteSiteForm = deleteSitePage.getFormByName("deleteSiteForm"); assertNotNull("There must be deleteSiteForm", deleteSiteForm); submit(deleteSiteForm); assertEquals( "UpdateSite must be deleted.", initialSize - 1, Jenkins.getInstance().getUpdateCenter().getSites().size()); }
public void testDoConfigure() throws Exception { UpdateSite target = new UpdateSite("test1", "http://example.com/test/update-center.json"); // Multiple update site. Jenkins.getInstance().getUpdateCenter().getSites().clear(); Jenkins.getInstance().getUpdateCenter().getSites().add(target); String originalId = target.getId(); WebClient wc = new WebClient(); HtmlPage editSitePage = wc.goTo(String.format("%s/%s", UpdateSitesManager.URL, target.getId())); HtmlForm editSiteForm = editSitePage.getFormByName("editSiteForm"); assertNotNull("There must be editSiteForm", editSiteForm); String newId = "newId"; String newUrl = "http://localhost/update-center.json"; editSiteForm.getInputByName("_.id").setValueAttribute(newId); editSiteForm.getInputByName("_.url").setValueAttribute(newUrl); submit(editSiteForm); UpdateSite site = null; for (UpdateSite s : Jenkins.getInstance().getUpdateCenter().getSites()) { if (newId.equals(s.getId())) { site = s; } assertFalse("id must be updated(old one must not remain)", originalId.equals(s.getId())); } assertNotNull("id must be updated", site); assertEquals("url must be updated", newUrl, site.getUrl()); }
public void testFileItemPersistence() throws Exception { // TODO: write a synchronous connector? byte[] testData = new byte[1024]; for (int i = 0; i < testData.length; i++) testData[i] = (byte) i; Server server = new Server(); SocketConnector connector = new SocketConnector(); server.addConnector(connector); ServletHandler handler = new ServletHandler(); handler.addServletWithMapping(new ServletHolder(new FileItemPersistenceTestServlet()), "/"); server.addHandler(handler); server.start(); localPort = connector.getLocalPort(); try { WebClient wc = new WebClient(); HtmlPage p = (HtmlPage) wc.getPage("http://localhost:" + localPort + '/'); HtmlForm f = p.getFormByName("main"); HtmlFileInput input = (HtmlFileInput) f.getInputByName("test"); input.setData(testData); f.submit(); } finally { server.stop(); } }
private void testInvalidSessionIdHelper( final String button, final String name, final String failMsg, final boolean fakeAppendedSessionId) throws IOException, JaxenException { HtmlPage editPage = clickEditLink(getWikiPage(name)); final HtmlForm form = editPage.getFormByName(ID_EDIT_FORM); final HtmlInput sessionId = form.getInputByName("sessionId"); sessionId.setValueAttribute(FAKE_SESSION_ID); if (fakeAppendedSessionId) { form.setActionAttribute(name + ";jsessionid=" + FAKE_SESSION_ID); } final HtmlTextArea content = form.getTextAreaByName("content"); final String expectedContent = "http://www.example.com"; content.setText(expectedContent); editPage = (HtmlPage) form.getInputByValue(button).click(); try { getAnchorByHrefContains(editPage, expectedContent); fail(failMsg); } catch (NoSuchElementException e) { } }
@Test public void deleteView() throws Exception { WebClient wc = j.createWebClient(); ListView v = listView("list"); HtmlPage delete = wc.getPage(v, "delete"); j.submit(delete.getFormByName("delete")); assertNull(j.jenkins.getView("list")); User user = User.get("user", true); MyViewsProperty p = user.getProperty(MyViewsProperty.class); v = new ListView("list", p); p.addView(v); delete = wc.getPage(v, "delete"); j.submit(delete.getFormByName("delete")); assertNull(p.getView("list")); }
@Test public void testRebuild() throws Exception { // job with promotion process FreeStyleProject p1 = j.createFreeStyleProject("promojob"); // setup promotion process JobPropertyImpl promotion = new JobPropertyImpl(p1); p1.addProperty(promotion); PromotionProcess proc = promotion.addProcess("promo"); proc.conditions.add(new SelfPromotionCondition(false)); // build it FreeStyleBuild b1 = j.assertBuildStatusSuccess(p1.scheduleBuild2(0)); j.waitUntilNoActivity(); // verify that promotion happened Assert.assertSame(proc.getBuilds().getLastBuild().getTarget(), b1); // job with parameter FreeStyleProject p2 = j.createFreeStyleProject("paramjob"); // add promoted build param p2.addProperty( new ParametersDefinitionProperty( new PromotedBuildParameterDefinition( "var", "promojob", "promo", "promoted build param to test rebuild"))); // build with parameter FreeStyleBuild b2 = j.assertBuildStatusSuccess(p2.scheduleBuild2(0)); // validate presence of parameter ParametersAction a1 = b2.getAction(ParametersAction.class); Assert.assertNotNull(a1); Assert.assertFalse(a1.getParameters().isEmpty()); ParameterValue v1 = a1.getParameter("var"); Assert.assertTrue(v1 instanceof PromotedBuildParameterValue); PromotedBuildParameterValue pbpv1 = (PromotedBuildParameterValue) v1; Assert.assertEquals(b1.getNumber(), pbpv1.getRun().getNumber()); // rebuild it JenkinsRule.WebClient wc = j.createWebClient(); HtmlPage page = wc.getPage(b2, "rebuild"); HtmlForm form = page.getFormByName("config"); j.submit(form); j.waitUntilNoActivity(); // validate presence of parameter FreeStyleBuild rebuild = p2.getLastBuild(); j.assertBuildStatusSuccess(rebuild); Assert.assertNotEquals(b2.getNumber(), rebuild.getNumber()); ParametersAction a2 = rebuild.getAction(ParametersAction.class); Assert.assertNotNull(a2); Assert.assertFalse(a2.getParameters().isEmpty()); ParameterValue v2 = a2.getParameter("var"); Assert.assertTrue(v2 instanceof PromotedBuildParameterValue); PromotedBuildParameterValue pbpv2 = (PromotedBuildParameterValue) v2; Assert.assertEquals(b1.getNumber(), pbpv2.getRun().getNumber()); }
/** * Manual submission form. */ public void testUploadJpi() throws Exception { HtmlPage page = new WebClient().goTo("pluginManager/advanced"); HtmlForm f = page.getFormByName("uploadPlugin"); File dir = env.temporaryDirectoryAllocator.allocate(); File plugin = new File(dir, "tasks.jpi"); FileUtils.copyURLToFile(getClass().getClassLoader().getResource("plugins/tasks.jpi"),plugin); f.getInputByName("name").setValueAttribute(plugin.getAbsolutePath()); submit(f); assertTrue( new File(jenkins.getRootDir(),"plugins/tasks.jpi").exists() ); }
@Test public void enterCredential() throws Exception { HtmlPage p = j.createWebClient().goTo("descriptorByName/hudson.tools.JDKInstaller/enterCredential"); HtmlForm form = p.getFormByName("postCredential"); form.getInputByName("username").setValueAttribute("foo"); form.getInputByName("password").setValueAttribute("bar"); HtmlFormUtil.submit(form, null); DescriptorImpl d = j.jenkins.getDescriptorByType(DescriptorImpl.class); assertEquals("foo", d.getUsername()); assertEquals("bar", d.getPassword().getPlainText()); }
public void testPreviewWithChangedAttributes() throws Exception { String name = uniqueWikiPageName("PreviewPageTest"); HtmlPage editPage = clickEditLink(getWikiPage(name)); HtmlForm form = editPage.getFormByName(ID_EDIT_FORM); HtmlTextArea attributes = form.getTextAreaByName("attributes"); String expectedContent = "SomeContent"; String expectedAttributes = "\"text\" = \"" + expectedContent + "\""; attributes.setText(expectedAttributes); HtmlTextArea content = form.getTextAreaByName("content"); String expectedContentSource = "<<attr:text>>"; content.setText(expectedContentSource); // Now if we preview we should get the previewed text rendered, and in // the edit area. editPage = (HtmlPage) form.getInputByValue("Preview").click(); editPage.asText().contains(expectedContent); form = editPage.getFormByName(ID_EDIT_FORM); attributes = form.getTextAreaByName("attributes"); assertEquals(expectedAttributes + NEWLINE_TEXTAREA, attributes.getText()); content = form.getTextAreaByName("content"); assertEquals(expectedContentSource + NEWLINE_TEXTAREA, content.getText()); }
public void testCopy() throws Exception { String fromPageName = uniqueWikiPageName("CopyTestFrom"); String toPageName = uniqueWikiPageName("CopyTestTo"); editWikiPage(fromPageName, "Catchy tunes", "", "Whatever", true); HtmlPage page = getWikiPage(fromPageName); page = (HtmlPage) page.getAnchorByName("copy").click(); HtmlForm form = page.getFormByName("copyForm"); form.getInputByName("toPage").setValueAttribute(toPageName); page = (HtmlPage) form.getButtonByName("copy").click(); assertTrue( page.getWebResponse().getWebRequest().getUrl().toURI().getPath().contains(toPageName)); assertTrue(page.asText().contains("Catchy tunes")); page = getWikiPage(fromPageName); assertTrue(page.asText().contains("Catchy tunes")); }
@Test public void errorDropdownIsPresentAndIsNotEmpty() throws Exception { JenkinsRule.WebClient wc = j.createWebClient(); wc.login("user1", "user1"); HtmlPage page = wc.goTo("job/x/" + build.getNumber()); page.getElementById("claim").click(); HtmlForm form = page.getFormByName("claim"); HtmlSelect select = form.getSelectByName("_.errors"); HashSet<String> set = new HashSet<String>(); for (HtmlOption option : select.getOptions()) { set.add(option.getValueAttribute()); } assertTrue(set.contains("Default")); assertTrue(set.contains(CAUSE_NAME_2)); assertTrue(set.contains(CAUSE_NAME_1)); }
private ClaimBuildAction applyClaimWithFailureCauseSelected( String element, String error, String reason, String description) throws Exception { HtmlPage page = whenNavigatingtoClaimPage(); page.getElementById(element).click(); HtmlForm form = page.getFormByName("claim"); form.getTextAreaByName("reason").setText(reason); HtmlSelect select = form.getSelectByName("_.errors"); HtmlOption option = select.getOptionByValue(error); select.setSelectedAttribute(option, true); assertEquals(description, form.getTextAreaByName("errordesc").getTextContent()); form.submit((HtmlButton) j.last(form.getHtmlElementsByTagName("button"))); ClaimBuildAction action = build.getAction(ClaimBuildAction.class); return action; }
public AppAnnieCrawlerJava(String application, String store, String rankType, AuthObject auth) throws ParsingException { url = "http://www.appannie.com/app/" + (store.equals("appstore") ? "ios" : store) + "/" + application.replaceAll(" ", "-").toLowerCase() + "/ranking/#view=" + rankType + "&date="; WebClient webClient = buildWebClient(); HtmlPage page = null; try { page = webClient.getPage("https://www.appannie.com/account/login/"); } catch (IOException e) { e.printStackTrace(); // todo: throw exception } HtmlForm form = page.getFormByName(""); // authentication try { form.getInputByName("username").setValueAttribute(auth.username()); } catch (Throwable t) { throw new ParsingException( "Login form incorrect! Please check " + getClass().getName() + " for errors."); } try { form.getInputByName("password").setValueAttribute(auth.password()); } catch (Throwable t) { throw new ParsingException( "Login form incorrect! Please check " + getClass().getName() + " for errors."); } try { form.getButtonByName("").click(); } catch (IOException e) { throw new ParsingException( "Login form incorrect! Please check " + getClass().getName() + " for errors."); } cookieManager = webClient.getCookieManager(); }
/** * Test method. * * @throws IOException exception */ public void testLoginValid() throws IOException { final WebClient webClient = new WebClient(); // XXX: issues with jquery webClient.setJavaScriptEnabled(false); final HtmlPage page = webClient.getPage(HTTP_PROCC_LOGIN_USER); final HtmlForm form = page.getFormByName(LOGIN_USER_FORM_NAME); final HtmlTextInput textEmail = form.getInputByName(EMAIL_INPUT_NAME); final HtmlPasswordInput textPassword = form.getInputByName(PASSWD_INPUT_NAME); final HtmlSubmitInput btnLogin = form.getInputByName(LOGIN_SUBMIT_NAME); textEmail.setValueAttribute("*****@*****.**"); textPassword.setValueAttribute("malczyk123"); final HtmlPage nextPage = btnLogin.click(); assertTrue(nextPage.getTitleText().equals("Taskflow-Main")); webClient.closeAllWindows(); }
@Test public void choiceWithLTGT() throws Exception { FreeStyleProject project = j.createFreeStyleProject(); ParametersDefinitionProperty pdp = new ParametersDefinitionProperty( new ChoiceParameterDefinition("choice", "Choice 1\nChoice <2>", "choice description")); project.addProperty(pdp); CaptureEnvironmentBuilder builder = new CaptureEnvironmentBuilder(); project.getBuildersList().add(builder); WebClient wc = j.createWebClient(); wc.setThrowExceptionOnFailingStatusCode(false); HtmlPage page = wc.goTo("job/" + project.getName() + "/build?delay=0sec"); HtmlForm form = page.getFormByName("parameters"); HtmlElement element = (HtmlElement) form.selectSingleNode(".//tr[td/div/input/@value='choice']"); assertNotNull(element); assertEquals( "choice description", ((HtmlElement) element .getNextSibling() .getNextSibling() .selectSingleNode("td[@class='setting-description']")) .getTextContent()); assertEquals( "choice", ((HtmlElement) element.selectSingleNode("td[@class='setting-name']")).getTextContent()); HtmlOption opt = (HtmlOption) element.selectSingleNode("td/div/select/option[@value='Choice <2>']"); assertNotNull(opt); assertEquals("Choice <2>", opt.asText()); opt.setSelected(true); j.submit(form); Queue.Item q = j.jenkins.getQueue().getItem(project); if (q != null) q.getFuture().get(); else Thread.sleep(1000); assertNotNull(builder.getEnvVars()); assertEquals("Choice <2>", builder.getEnvVars().get("CHOICE")); }
public void testFormRoundTrip() throws Exception { MavenInstallation.DescriptorImpl mavenDescriptor = jenkins.getDescriptorByType(MavenInstallation.DescriptorImpl.class); mavenDescriptor.setInstallations(new MavenInstallation("maven", "XXX", NO_PROPERTIES)); AntInstallation.DescriptorImpl antDescriptor = jenkins.getDescriptorByType(AntInstallation.DescriptorImpl.class); antDescriptor.setInstallations(new AntInstallation("ant", "XXX", NO_PROPERTIES)); JDK.DescriptorImpl jdkDescriptor = jenkins.getDescriptorByType(JDK.DescriptorImpl.class); jdkDescriptor.setInstallations(new JDK("jdk", "XXX")); ToolLocationNodeProperty property = new ToolLocationNodeProperty( new ToolLocationNodeProperty.ToolLocation(jdkDescriptor, "jdk", "foobar"), new ToolLocationNodeProperty.ToolLocation(mavenDescriptor, "maven", "barzot"), new ToolLocationNodeProperty.ToolLocation(antDescriptor, "ant", "zotfoo")); slave.getNodeProperties().add(property); WebClient webClient = new WebClient(); HtmlPage page = webClient.getPage(slave, "configure"); HtmlForm form = page.getFormByName("config"); submit(form); Assert.assertEquals(1, slave.getNodeProperties().toList().size()); ToolLocationNodeProperty prop = slave.getNodeProperties().get(ToolLocationNodeProperty.class); Assert.assertEquals(3, prop.getLocations().size()); ToolLocationNodeProperty.ToolLocation location = prop.getLocations().get(0); Assert.assertEquals(jdkDescriptor, location.getType()); Assert.assertEquals("jdk", location.getName()); Assert.assertEquals("foobar", location.getHome()); location = prop.getLocations().get(1); Assert.assertEquals(mavenDescriptor, location.getType()); Assert.assertEquals("maven", location.getName()); Assert.assertEquals("barzot", location.getHome()); location = prop.getLocations().get(2); Assert.assertEquals(antDescriptor, location.getType()); Assert.assertEquals("ant", location.getName()); Assert.assertEquals("zotfoo", location.getHome()); }
@Test @Issue("JENKINS-11543") public void unicodeParametersArePresetCorrectly() throws Exception { final FreeStyleProject p = j.createFreeStyleProject(); ParametersDefinitionProperty pdb = new ParametersDefinitionProperty( new StringParameterDefinition("sname:a¶‱ﻷ", "svalue:a¶‱ﻷ", "sdesc:a¶‱ﻷ"), new FileParameterDefinition("fname:a¶‱ﻷ", "fdesc:a¶‱ﻷ")); p.addProperty(pdb); WebClient wc = j.createWebClient(); wc.setThrowExceptionOnFailingStatusCode(false); // Ignore 405 HtmlPage page = wc.getPage(p, "build"); // java.lang.IllegalArgumentException: No such parameter definition: <gibberish>. wc.setThrowExceptionOnFailingStatusCode(true); final HtmlForm form = page.getFormByName("parameters"); form.submit(form.getButtonByCaption("Build")); }
/** * Test method. * * @throws IOException exception */ public void testLoginInvalid() throws IOException { final WebClient webClient = new WebClient(); // XXX: issues with jquery webClient.setJavaScriptEnabled(false); final HtmlPage page = webClient.getPage(HTTP_PROCC_LOGIN_USER); final HtmlForm form = page.getFormByName(LOGIN_USER_FORM_NAME); final HtmlTextInput textEmail = form.getInputByName(EMAIL_INPUT_NAME); final HtmlPasswordInput textPassword = form.getInputByName(PASSWD_INPUT_NAME); final HtmlSubmitInput btnLogin = form.getInputByName(LOGIN_SUBMIT_NAME); textEmail.setValueAttribute("invalidLogin"); textPassword.setValueAttribute("invalidPasswd"); final HtmlPage nextPage = btnLogin.click(); assertTrue(nextPage.asText().contains("Błędny login bądź hasło")); webClient.closeAllWindows(); }
@LocalData public void testReadOnlyConfigAccessWithPermissionEnabled() throws Exception { setPermissionEnabled(true); AuthorizationStrategy as = jenkins.getAuthorizationStrategy(); assertTrue( "Expecting GlobalMatrixAuthorizationStrategy", (as instanceof GlobalMatrixAuthorizationStrategy)); GlobalMatrixAuthorizationStrategy gas = (GlobalMatrixAuthorizationStrategy) as; assertTrue( "Charlie should have extended read for this test", gas.hasExplicitPermission("charlie", Item.EXTENDED_READ)); WebClient wc = new WebClient().login("charlie", "charlie"); HtmlPage page = wc.goTo("job/a/configure"); HtmlForm form = page.getFormByName("config"); HtmlButton saveButton = getButtonByCaption(form, "Save"); assertNull(saveButton); }
@Test @Issue("JENKINS-3539") public void fileParameterNotSet() throws Exception { FreeStyleProject project = j.createFreeStyleProject(); ParametersDefinitionProperty pdp = new ParametersDefinitionProperty(new FileParameterDefinition("filename", "description")); project.addProperty(pdp); WebClient wc = j.createWebClient(); wc.setThrowExceptionOnFailingStatusCode(false); HtmlPage page = wc.goTo("job/" + project.getName() + "/build?delay=0sec"); HtmlForm form = page.getFormByName("parameters"); j.submit(form); Queue.Item q = j.jenkins.getQueue().getItem(project); if (q != null) q.getFuture().get(); else Thread.sleep(1000); assertFalse("file must not exist", project.getSomeWorkspace().child("filename").exists()); }
/** * Creates a new freestyle project and rebuild. Check that the RebuildCause has been set to the * new build. Check also that a UserIdCause is added. * * @throws Exception Exception */ public void testWhenProjectWithCauseThenCauseIsCopiedAndUserCauseAdded() throws Exception { FreeStyleProject project = createFreeStyleProject(); // Build (#1) project .scheduleBuild2( 0, new Cause.RemoteCause("host", "note"), new ParametersAction(new StringParameterValue("name", "test"))) .get(); HtmlPage rebuildConfigPage = createWebClient().getPage(project, "1/rebuild"); // Rebuild (#2) submit(rebuildConfigPage.getFormByName("config")); createWebClient().getPage(project).getAnchorByText("Rebuild Last").click(); while (project.isBuilding()) { Thread.sleep(100); } List<Action> actions = project.getLastCompletedBuild().getActions(); boolean hasRebuildCause = false; boolean hasRemoteCause = false; boolean hasUserIdCause = false; for (Action action : actions) { if (action instanceof CauseAction) { CauseAction causeAction = (CauseAction) action; if (causeAction.getCauses().get(0).getClass().equals(RebuildCause.class)) { hasRebuildCause = true; } if (causeAction.getCauses().get(0).getClass().equals(Cause.RemoteCause.class)) { hasRemoteCause = true; } if (causeAction.getCauses().get(0).getClass().equals(Cause.UserIdCause.class)) { hasUserIdCause = true; } } } assertTrue( "Build should have user, remote and rebuild causes", hasRebuildCause && hasRemoteCause && hasUserIdCause); }
public static HtmlPage login(HtmlPage page, String username, String password) { int attempts = 0; boolean loggedIn = false; while (!loggedIn) { try { if (attempts > 3) System.exit(1); attempts++; System.out.println("Logging in... (Attempt " + attempts + ")"); page = wc.getPage("http://torn.com/login"); final HtmlForm form = page.getFormByName("login"); HtmlSubmitInput button = form.getInputByName("btnLogin"); HtmlTextInput textField = form.getInputByName("player"); // Change the value of the text field textField.setValueAttribute(username); final HtmlPasswordInput passwordField = form.getInputByName("password"); // Change the value of the text field passwordField.setValueAttribute(password); // Now submit the form by clicking the button and get back the second page. page = button.click(); page = wc.getPage("http://torn.com/index.php"); loggedIn = true; } catch (Exception e) { System.out.println(e.toString()); loggedIn = false; } } return page; }
/** * 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(); // 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", rebuildHref.getHrefAttribute(), "/" + project.getUrl() + "2/rebuild"); }