@LocalData
  public void testDontCopyExcessFilesWhenOtherFilesEmpty() throws Exception {
    Hudson hudson = Hudson.getInstance();
    List<Project> projects = hudson.getProjects();
    Project testProject = null;
    for (Project project : projects) {
      if (project.getName().equals("dont-copy")) testProject = project;
    }
    if (testProject == null) fail("Couldn't find example project");
    Future<Run> run = testProject.scheduleBuild2(0);

    while (!run.isDone()) {
      Thread.sleep(5);
    }

    Run lastBuild = testProject.getLastBuild();
    assertTrue("Build wasn't a success", lastBuild.getResult() == Result.SUCCESS);

    File storedOutput =
        new File(lastBuild.getRootDir(), RobotPublisher.FILE_ARCHIVE_DIR + "/output.xml");
    File storedSplitOutput =
        new File(lastBuild.getRootDir(), RobotPublisher.FILE_ARCHIVE_DIR + "/output-001.xml");
    File storedDummy =
        new File(lastBuild.getRootDir(), RobotPublisher.FILE_ARCHIVE_DIR + "/dummy.file");

    assertTrue("output.xml was not stored", storedOutput.exists());
    assertTrue("output-001.xml was not stored", storedSplitOutput.exists());
    assertFalse("dummy.file was copied", storedDummy.exists());
  }
  @LocalData
  public void testPublish() throws Exception {
    Hudson hudson = Hudson.getInstance();
    List<Project> projects = hudson.getProjects();
    Project testProject = null;
    for (Project project : projects) {
      if (project.getName().equals("robot")) testProject = project;
    }
    if (testProject == null) fail("Couldn't find example project");
    Future<Run> run = testProject.scheduleBuild2(0);

    while (!run.isDone()) {
      Thread.sleep(5);
    }

    Run lastBuild = testProject.getLastBuild();
    assertTrue("Build wasn't a success", lastBuild.getResult() == Result.SUCCESS);

    File storedOutput =
        new File(lastBuild.getRootDir(), RobotPublisher.FILE_ARCHIVE_DIR + "/output.xml");
    File storedSplitOutput =
        new File(lastBuild.getRootDir(), RobotPublisher.FILE_ARCHIVE_DIR + "/output-001.xml");
    File storedReport =
        new File(lastBuild.getRootDir(), RobotPublisher.FILE_ARCHIVE_DIR + "/report.html");
    File storedSplitReport =
        new File(lastBuild.getRootDir(), RobotPublisher.FILE_ARCHIVE_DIR + "/report.html");
    File storedLog =
        new File(lastBuild.getRootDir(), RobotPublisher.FILE_ARCHIVE_DIR + "/log.html");
    File storedSplitLog =
        new File(lastBuild.getRootDir(), RobotPublisher.FILE_ARCHIVE_DIR + "/log-001.html");
    File storedJs = new File(lastBuild.getRootDir(), RobotPublisher.FILE_ARCHIVE_DIR + "/log.js");
    File storedSplitJs1 =
        new File(lastBuild.getRootDir(), RobotPublisher.FILE_ARCHIVE_DIR + "/log-001.js");
    File storedImage1 =
        new File(lastBuild.getRootDir(), RobotPublisher.FILE_ARCHIVE_DIR + "/screenshot.png");
    File storedImage2 =
        new File(
            lastBuild.getRootDir(), RobotPublisher.FILE_ARCHIVE_DIR + "/subfolder/screenshot2.png");
    File storedDummy =
        new File(lastBuild.getRootDir(), RobotPublisher.FILE_ARCHIVE_DIR + "dummy.file");

    assertTrue("output.xml was not stored", storedOutput.exists());
    assertTrue("output-001.xml was not stored", storedSplitOutput.exists());
    assertTrue("report.html was not stored", storedReport.exists());
    assertTrue("report-001.html was not stored", storedSplitReport.exists());
    assertTrue("log.html was not stored", storedLog.exists());
    assertTrue("log-001.html was not stored", storedSplitLog.exists());
    assertTrue("log.js was not stored", storedJs.exists());
    assertTrue("log-001.js was not stored", storedSplitJs1.exists());
    assertTrue("screenshot.png was not stored", storedImage1.exists());
    assertTrue("screenshot2.png was not stored", storedImage2.exists());
    assertFalse("dummy.file was copied", storedDummy.exists());
  }
  @LocalData
  public void testMissingReportFileWithOld() throws Exception {
    Hudson hudson = Hudson.getInstance();
    List<Project> projects = hudson.getProjects();
    Project testProject = null;
    for (Project project : projects) {
      if (project.getName().equals("oldrobotbuild")) testProject = project;
    }
    if (testProject == null) fail("Couldn't find example project");

    WebClient wc = getWebClient();

    File buildRoot = testProject.getLastBuild().getRootDir();
    File robotHtmlReport = new File(buildRoot, RobotPublisher.FILE_ARCHIVE_DIR + "/report.html");
    if (!robotHtmlReport.delete()) fail("Unable to delete report directory");

    HtmlPage page = wc.goTo("job/oldrobotbuild/robot/");
    WebAssert.assertTextPresent(page, "No Robot html report found!");

    page = wc.goTo("job/oldrobotbuild/1/robot/");
    WebAssert.assertTextPresent(page, "No Robot html report found!");
  }
  @LocalData
  public void testReportPage() throws Exception {
    Hudson hudson = Hudson.getInstance();
    List<Project> projects = hudson.getProjects();
    Project testProject = null;
    for (Project project : projects) {
      if (project.getName().equals("robot")) testProject = project;
    }
    if (testProject == null) fail("Couldn't find example project");
    Future<Run> run = testProject.scheduleBuild2(0);

    while (!run.isDone()) {
      Thread.sleep(5);
    }
    Run lastBuild = testProject.getLastBuild();
    assertTrue("Build wasn't a success", lastBuild.getResult() == Result.SUCCESS);

    WebClient wc = getWebClient();
    HtmlPage page = wc.goTo("job/robot/robot/");
    WebAssert.assertTextPresent(page, "Robot Framework test results");
    WebAssert.assertTextPresent(page, "4 failed tests, 4 critical");
    WebAssert.assertTextPresent(page, "Tests took 0:00:00.009 (+0:00:00.009)");
    WebAssert.assertElementPresentByXPath(
        page,
        "//td[@id='main-panel']//a[@href='Testcases%20&%20Othercases/Testcases/Not%20equal' and contains(.,'Testcases & Othercases.Testcases.Not equal')]");
    WebAssert.assertElementPresentByXPath(
        page,
        "//td[@id='main-panel']//a[@href='Testcases%20&%20Othercases/Othercases' and contains(.,'Testcases & Othercases.Othercases')]");

    page = wc.goTo("job/robot/1/robot/report/");
    WebAssert.assertElementPresentByXPath(
        page, "//td[@id='main-panel']//a[@href='output.xml' and contains(.,'output.xml')]");

    page = wc.goTo("job/robot/1/robot/Testcases%20&%20Othercases");
    WebAssert.assertTextPresent(page, "4 failed tests, 4 critical");
    WebAssert.assertTextPresent(page, "Tests took 0:00:00.009 (+0:00:00.009)");
    WebAssert.assertTextNotPresent(page, "All Testcases");
    WebAssert.assertElementPresentByXPath(
        page,
        "//td[@id='main-panel']//a[@href='Testcases/Not%20equal' and contains(.,'Testcases.Not equal')]");
    WebAssert.assertElementPresentByXPath(
        page, "//td[@id='main-panel']//a[@href='Othercases' and contains(.,'Othercases')]");

    page = wc.goTo("job/robot/1/robot/Testcases%20&%20Othercases/Othercases");
    WebAssert.assertTextPresent(page, "2 failed tests, 2 critical");
    WebAssert.assertTextPresent(page, "Tests took 0:00:00.005 (+0:00:00.005)");
    WebAssert.assertTextPresent(page, "All Testcases");
    WebAssert.assertElementPresentByXPath(
        page, "//td[@id='main-panel']//a[@href='Not%20equal' and contains(.,'Not equal')]");
    WebAssert.assertElementPresentByXPath(
        page,
        "//td[@id='main-panel']//a[@href='Contains%20string' and contains(.,'Contains string')]");

    page = wc.goTo("job/robot/1/robot/Testcases%20&%20Othercases/Othercases/Not%20equal");
    WebAssert.assertTextPresent(page, "Critical test case: \"Not equal\"");
    WebAssert.assertTextPresent(page, "Failed!");
    WebAssert.assertTextPresent(page, "Error message:");
    WebAssert.assertTextPresent(page, "Hello, world! != Good bye, world!");
    WebAssert.assertTextPresent(page, "Test took 0:00:00.001 (+0:00:00.001)");
    WebAssert.assertElementPresentByXPath(
        page, "//td[@id='main-panel']//img[@src='durationGraph']");

    page = wc.goTo("job/robot/1/robot/Testcases%20&%20Othercases/Othercases/Contains%20string");
    WebAssert.assertTextPresent(page, "Passed!");
    WebAssert.assertTextNotPresent(page, "Error message:");
  }
  @LocalData
  public void testSummariesWithData() throws Exception {
    Hudson hudson = Hudson.getInstance();
    List<Project> projects = hudson.getProjects();
    Project testProject = null;
    for (Project project : projects) {
      if (project.getName().equals("robot")) testProject = project;
    }
    if (testProject == null) fail("Couldn't find example project");
    Future<Run> run = testProject.scheduleBuild2(0);

    while (!run.isDone()) {
      Thread.sleep(5);
    }

    Run lastBuild = testProject.getLastBuild();
    assertTrue("Build wasn't a success", lastBuild.getResult() == Result.SUCCESS);

    WebClient wc = getWebClient();

    HtmlPage page = wc.goTo("job/robot/");
    WebAssert.assertElementPresentByXPath(
        page, "//div[@id='navigation']//a[@href='/job/robot/robot']");
    WebAssert.assertElementPresentByXPath(
        page, "//td[@id='main-panel']//h4[contains(.,'Latest Robot Results:')]");
    WebAssert.assertElementPresentByXPath(page, "//td[@id='main-panel']//img[@src='robot/graph']");
    WebAssert.assertElementPresentByXPath(
        page,
        "//td[@id='main-panel']//a[@href='/job/robot/1/robot' and contains(text(),'Browse results')]");
    WebAssert.assertElementPresentByXPath(
        page,
        "//td[@id='main-panel']//a[@href='/job/robot/1/robot/report/report.html' and contains(text(), 'Open report.html')]");
    WebAssert.assertElementPresentByXPath(
        page,
        "//td[@id='main-panel']//a[@href='/job/robot/1/robot/report/log.html' and contains(text(), 'Open log.html')]");

    HtmlTable table = page.getHtmlElementById("robot-summary-table");
    Assert.assertTrue(
        table
            .asXml()
            .replaceAll("\\s", "")
            .contains(
                "<tableclass=\"table\"id=\"robot-summary-table\"><tbodyalign=\"left\"><tr><th/><th>Total</th><th>Failed</th><th>Passed</th><th>Pass%</th></tr><tr><th>Criticaltests</th><tdclass=\"table-upper-row\"style=\"border-left:0px;\">8</td><tdclass=\"table-upper-row\"><spanclass=\"fail\">4</span></td><tdclass=\"table-upper-row\">4</td><tdclass=\"table-upper-row\">50.0</td></tr><tr><th>Alltests</th><tdstyle=\"border-left:0px;\">8</td><td><spanclass=\"fail\">4</span></td><td>4</td><td>50.0</td></tr></tbody></table>"));

    page = wc.goTo("job/robot/1/");
    WebAssert.assertElementPresentByXPath(
        page, "//div[@id='navigation']//a[@href='/job/robot/1/robot']");
    WebAssert.assertElementPresentByXPath(
        page, "//td[@id='main-panel']//h4[contains(.,'Robot Test Summary:')]");
    WebAssert.assertElementPresentByXPath(
        page,
        "//td[@id='main-panel']//a[@href='/job/robot/1/robot' and contains(text(),'Browse results')]");
    WebAssert.assertElementPresentByXPath(
        page,
        "//td[@id='main-panel']//a[@href='/job/robot/1/robot/report/report.html' and contains(text(), 'Open report.html')]");
    WebAssert.assertElementPresentByXPath(
        page,
        "//td[@id='main-panel']//a[@href='/job/robot/1/robot/report/log.html' and contains(text(), 'Open log.html')]");
    table = page.getHtmlElementById("robot-summary-table");
    Assert.assertTrue(
        table
            .asXml()
            .replaceAll("\\s", "")
            .contains(
                "<tableclass=\"table\"id=\"robot-summary-table\"><tbodyalign=\"left\"><tr><th/><th>Total</th><th>Failed</th><th>Passed</th><th>Pass%</th></tr><tr><th>Criticaltests</th><tdclass=\"table-upper-row\"style=\"border-left:0px;\">8</td><tdclass=\"table-upper-row\"><spanclass=\"fail\">4</span></td><tdclass=\"table-upper-row\">4</td><tdclass=\"table-upper-row\">50.0</td></tr><tr><th>Alltests</th><tdstyle=\"border-left:0px;\">8</td><td><spanclass=\"fail\">4</span></td><td>4</td><td>50.0</td></tr></tbody></table>"));
  }