0

Hi my JUnit test passes in eclipse. JUnit has all green bars in eclipse however when I envoke the xml file from Jenkins it says failed. I have seared for hours on stakeoverflow and i cant find the issue. Please help my code that works is below:

   @FixMethodOrder(MethodSorters.NAME_ASCENDING) // this allows you to execute test in order 
public class AdpPortal_1_Homepage {

  private WebDriver driver;
  private String homeUrl;
  private String homeTitle = "ADP Associate Portal";
  private StringBuffer verificationErrors = new StringBuffer();

  @Before
  public void setUp() throws Exception {
    System.setProperty("webdriver.chrome.driver", "C:\\eclipse\\chromedriver\\chromedriver.exe");
    driver = new ChromeDriver();
    homeUrl = "https://myadp.adpcorp.com/wps/myportal/main/myADP_new";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  }

  //Full test
  @Test
  public void fullTest() throws Exception {

    step01_VerifyHomePage();

  }


  // Go to Home page and verify title 
  public void step01_VerifyHomePage() throws Exception {
    driver.get(homeUrl);
    // homeTitle = "ADP Associate Portal" 
    driver.getTitle().contains(homeTitle);
    Thread.sleep(3000);
  }


  @After
  public void tearDown() throws Exception {
    driver.quit();
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {
      fail(verificationErrorString);
    }
  }
}

Also here is my console output from Jenkins:

enter image description here

Please help.

ant file snippet:

 <target name="AdpPortal_1_Homepage">
        <mkdir dir="${junit.output.dir}"/>
        <junit fork="yes" printsummary="withOutAndErr">
            <formatter type="xml"/>
            <test name="AdpPortal_1_Homepage" todir="${junit.output.dir}"/>
            <classpath refid="ADP_Automation_(JUnit)_(Jenkins).classpath"/>
        </junit>
    </target>
    <target name="junitreport">
        <junitreport todir="${junit.output.dir}">
            <fileset dir="${junit.output.dir}">
                <include name="TEST-*.xml"/>
            </fileset>
            <report format="frames" todir="${junit.output.dir}"/>
        </junitreport>

enter image description here

-------------- NEW ISSUE-------------------------- enter image description here

@Before
    public void setUp() throws Exception {
    System.setProperty("webdriver.chrome.driver", "C:\\eclipse\\chromedriver\\chromedriver.exe");  
    driver = new ChromeDriver();
    homeUrl = "https://myadp.adpcorp.com/wps/myportal/main/myADP_new";
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    driver.get(homeUrl);
    }

        //Full test
         @Test 
         public void fullTest() throws Exception {

             step02_HoverMyWorkSpace(); 

         }


          public void step02_HoverMyWorkSpace() throws Exception {
              WebDriverWait wait = new WebDriverWait(driver,20000);
              wait.until(ExpectedConditions.visibilityOfElementLocated((By.id("DivMyWorkList"))));
              if ( driver.findElement(By.id("DivMyWorkList")).isDisplayed()){
                  System.out.println("DivMyWorkList Visiable");
              }else{
                  System.out.println("DivMyWorkList NOT Visiable");
              }

    //        Assert.assertEquals(true, workspace.isDisplayed());
    //        Thread.sleep(3000);
          }
Jonathan
  • 395
  • 2
  • 8
  • 25
  • Looks like a config issue for Jenkins job to me not an issue with tests themselves. Check these links: https://stackoverflow.com/questions/14933375/jenkins-junit-test-result-report-plugin-states-that-the-junit-xml-file-is-not-fo https://wiki.jenkins.io/display/JENKINS/JUnit+Plugin – Ivan Feb 15 '18 at 20:05
  • is **/build/test-results/**/TEST-*.xml the folder and file path? because I only have junit where my test are stored and jenkins has problems finding it. – Jonathan Feb 15 '18 at 21:43
  • Added some information as an answer. @Jonathan – Ivan Feb 15 '18 at 21:59

1 Answers1

1

jUnit step in your Ant build creates XML file with test results for each executed test class.

If your step looks like this

<target name="unit-test" depends="test-build" >
    <junit printsummary="yes" haltonfailure="no" haltonerror="no" failureproperty="test.failed">
        <classpath refid="test.classpath"/>
        <formatter type="xml" />
        <batchtest fork="no" todir="build/test-results">
            <fileset dir="${test-src}">
                <include name="**/*Test*.java" />
            </fileset>
        </batchtest>
    </junit>
  <fail message="Test failure detected, check test results." if="test.failed" />
</target>

Then those files will be generated in build/test-results directory under your project directory. The only issue is that directory build/test-results should be created manually before executing build or should be created during the build in prior steps.

Ivan
  • 8,508
  • 2
  • 19
  • 30
  • My ant file snippet is posted above its some what different. – Jonathan Feb 16 '18 at 12:10
  • Note I did what you said i created a folder called build/test-results and my tests are showing in the folder I havent run jenkins yet should i run a new build and see if it corrects itself? because it is still saying noes not exist. Also not in my ant file where it says ${junit.output.dir} I hover my mouse over it and it says path build/test-results – Jonathan Feb 16 '18 at 12:27
  • Try to rerun Jenkins job with new Ant build.xml – Ivan Feb 16 '18 at 13:00
  • I found my issue I had to put the workspace path in Jenkins. now everything runs well – Jonathan Feb 16 '18 at 13:47
  • I am using jenkins and one of my test fail. The jenkins log says it can't find the element however it passes when I run Junit with eclipse is there a reason why the test fails and the 1st one doesn't? I have the proper waits I. Here as well let me know if you need to see my code – Jonathan Feb 24 '18 at 07:50
  • It might mean that your tests are somehow depend on each other (which is not good). And Jenkins execute tests not in the same order as your local eclipse – Ivan Feb 24 '18 at 13:26
  • They are in separate classes on the same project – Jonathan Feb 24 '18 at 14:19
  • I have added content above – Jonathan Feb 24 '18 at 14:21
  • One of the issues I found out with this is that when I did a sample test on google.com it showed up in Jenkins however when i did a test on an internal site for my job it would not and would fail so the issue i found was that as well – Jonathan Mar 30 '18 at 14:41