Java Code Examples for org.jvnet.hudson.test.JenkinsRule.WebClient#getPage()

The following examples show how to use org.jvnet.hudson.test.JenkinsRule.WebClient#getPage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JUnitResultArchiverTest.java    From junit-plugin with MIT License 6 votes vote down vote up
@LocalData("All")
@Test public void basic() throws Exception {
    FreeStyleBuild build = project.scheduleBuild2(0).get(10, TimeUnit.SECONDS);

    assertTestResults(build);

    WebClient wc = j.new WebClient();
    wc.getPage(project); // project page
    wc.getPage(build); // build page
    wc.getPage(build, "testReport");  // test report
    wc.getPage(build, "testReport/hudson.security"); // package
    wc.getPage(build, "testReport/hudson.security/HudsonPrivateSecurityRealmTest/"); // class
    wc.getPage(build, "testReport/hudson.security/HudsonPrivateSecurityRealmTest/testDataCompatibilityWith1_282/"); // method


}
 
Example 2
Source File: JUnitResultArchiverTest.java    From junit-plugin with MIT License 6 votes vote down vote up
@Test public void specialCharsInRelativePath() throws Exception {
    Assume.assumeFalse(Functions.isWindows());
    final String ID_PREFIX = "test-../a=%3C%7C%23)/testReport/org.twia.vendor/VendorManagerTest/testCreateAdjustingFirm/";
    final String EXPECTED = "org.twia.dao.DAOException: [S2001] Hibernate encountered an error updating Claim [null]";

    MatrixProject p = j.jenkins.createProject(MatrixProject.class, "test-" + j.jenkins.getItems().size());
    p.setAxes(new AxisList(new TextAxis("a", "<|#)")));
    p.setScm(new SingleFileSCM("report.xml", getClass().getResource("junit-report-20090516.xml")));
    p.getPublishersList().add(new JUnitResultArchiver("report.xml"));

    MatrixBuild b = p.scheduleBuild2(0).get();
    j.assertBuildStatus(Result.UNSTABLE, b);

    WebClient wc = j.createWebClient();
    HtmlPage page = wc.getPage(b, "testReport");

    assertThat(page.asText(), not(containsString(EXPECTED)));

    ((HtmlAnchor) page.getElementById(ID_PREFIX + "-showlink")).click();
    wc.waitForBackgroundJavaScript(10000L);
    assertThat(page.asText(), containsString(EXPECTED));

    ((HtmlAnchor) page.getElementById(ID_PREFIX + "-hidelink")).click();
    wc.waitForBackgroundJavaScript(10000L);
    assertThat(page.asText(), not(containsString(EXPECTED)));
}
 
Example 3
Source File: TestResultPublishingTest.java    From junit-plugin with MIT License 5 votes vote down vote up
@LocalData
@Test
public void testBasic() throws Exception {
    FreeStyleBuild build = project.scheduleBuild2(0).get(30, TimeUnit.SECONDS);

    assertTestResults(build);

    WebClient wc = rule.createWebClient();
    wc.getPage(project); // project page
    wc.getPage(build); // build page
    wc.getPage(build, "testReport");  // test report
    wc.getPage(build, "testReport/hudson.security"); // package
    wc.getPage(build, "testReport/hudson.security/HudsonPrivateSecurityRealmTest/"); // class
    wc.getPage(build, "testReport/hudson.security/HudsonPrivateSecurityRealmTest/testDataCompatibilityWith1_282/"); // method
}
 
Example 4
Source File: TestResultPublishingTest.java    From junit-plugin with MIT License 5 votes vote down vote up
/**
 * Make sure the open junit publisher shows junit history
 * @throws IOException
 * @throws SAXException
 */
@LocalData
@Test
public void testHistoryPageOpenJunit() throws IOException, SAXException {
    Project proj = (Project)rule.jenkins.getItem(TEST_PROJECT_WITH_HISTORY);
    assertNotNull("We should have a project named " + TEST_PROJECT_WITH_HISTORY, proj);

    // Validate that there are test results where I expect them to be:
    WebClient wc = rule.createWebClient();

    HtmlPage historyPage = wc.getPage(proj.getBuildByNumber(7),"/testReport/history/");
    rule.assertGoodStatus(historyPage);
    rule.assertXPath(historyPage, "//img[@id='graph']");
    rule.assertXPath(historyPage, "//table[@id='testresult']");
    DomElement 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 5
Source File: TestResultPublishingTest.java    From junit-plugin with MIT License 5 votes vote down vote up
void assertTestResultsAsExpected(WebClient wc, Run run, String restOfUrl,
                                 String packageName,
                                 String expectedResult, String expectedDurationStr,
                                 int expectedTotalTests, int expectedTotalDiff,
                                 int expectedFailCount, int expectedFailDiff,
                                 int expectedSkipCount, int expectedSkipDiff) throws IOException, SAXException {

    // TODO: verify expectedResult
    // TODO: verify expectedDuration

    XmlPage xmlPage = wc.goToXml(run.getUrl() + restOfUrl + "/" + packageName + "/api/xml");
    int expectedPassCount = expectedTotalTests - expectedFailCount - expectedSkipCount;
    // Verify xml results
    rule.assertXPathValue(xmlPage, "/packageResult/failCount", Integer.toString(expectedFailCount));
    rule.assertXPathValue(xmlPage, "/packageResult/skipCount", Integer.toString(expectedSkipCount));
    rule.assertXPathValue(xmlPage, "/packageResult/passCount", Integer.toString(expectedPassCount));
    rule.assertXPathValue(xmlPage, "/packageResult/name", packageName);

    // TODO: verify html results
    HtmlPage testResultPage =   wc.getPage(run, restOfUrl);

    // Verify inter-build diffs in html table
    String xpathToFailDiff =  "//table[@id='testresult']//tr[td//span[text()=\"" + packageName + "\"]]/td[4]";
    String xpathToSkipDiff =  "//table[@id='testresult']//tr[td//span[text()=\"" + packageName + "\"]]/td[6]";
    String xpathToTotalDiff = "//table[@id='testresult']//tr[td//span[text()=\"" + packageName + "\"]]/td[last()]";

    Object totalDiffObj = testResultPage.getFirstByXPath(xpathToTotalDiff);
    assertPaneDiffText("total diff", expectedTotalDiff, totalDiffObj);

    Object failDiffObj = testResultPage.getFirstByXPath(xpathToFailDiff);
    assertPaneDiffText("failure diff", expectedFailDiff, failDiffObj);

    Object skipDiffObj = testResultPage.getFirstByXPath(xpathToSkipDiff);
    assertPaneDiffText("skip diff", expectedSkipDiff, skipDiffObj);

    // TODO: The link in the table for each of the three packages in the testReport table should link to a by-package page,
    // TODO: for example, http://localhost:8080/job/breakable/lastBuild/testReport/com.yahoo.breakable.misc/

}