Question

I have a couple simple tests that looks like this.

public class My1Test extends AutoBaseFunctions{

@Test
public void test1(){

    startDriver(STARTPAGE,DRIVER2USE);
    schoolLogin("XXX", "XXX");

    toolbarNav("toolsSingle","Manage Users");

    getElmObject("input[type='checkbox'][name='includeUsersHiddenFromDirectory']",loctype.CSS).click();
    getElmObject("Searchxx",loctype.LINKTEXT).click();

    driver.quit();
    //driver.close();
}

}

The problem I have is this: I am purposely causing a NoSuchElement Exception to happen when doing a findElement on the search button. When I run the mvn surefire-report:report command the output stops here

surefire report output

until I MANUALLY close the window that was opened - only then does it finish generating the report.

I understand that when the script errors out it dies and never gets to the driver.quit line. But, if I put it in a try/catch block, the report shows the test as passed and doesn't report the error details. I also tried putting this as part of a @Suite test and using @After/@AfterClass but that doesn't close the driver window either.

What am I doing wrong? How do I get the report to generate after an error is encountered without having to "be present" to manually close the open windows?

Était-ce utile?

La solution

You need to put it in try/catch and in catch block do

    try{

    }catch(Exception e){
     Assert.fail(e.getMessage());
    }finally{
              // CLOSE ANY OPEN RESOURCES HERE !!!!
    }

If you have any open resources, don't forget to close them in finally block.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top