Why is junit not catching my exception in try catch block?

Junit is not catching my exception in try/catch block. I am using Serenity bdd with junit and appium for android testing. Here is my code and exception. The exception shows fine in the failure trace but is not getting caught. I am purposely causing an exception by closing my android app when the test reaches the required method:

@RunWith(SerenityRunner.class)
@WithTags
(
        {
            @WithTag(type="TP", name="TP-000397prachi")
        }
        )


public class TP397_P1_S06 implements Subject{

    //List<String> exceptions = new ArrayList<String>();
    @Managed
    WebDriver appiumDriver;

    @Steps
    TP397_P1_Section05 Section05;

    private static final Logger log = LogManager.getLogger(com.tp.tp397.Procedure1_ORSession.TP397_P1_S05.class);
    String testCaseID = TP397_TestCaseIDs.TP397_002;
    String observedToast, expectedToast;

    static ResultWriterCSV resultWriter = new ResultWriterCSV(TP397_Constants.TestProtocolId);
    
    TestCase testCase = new TestCase(TP397_Constants.TestProtocolId, testCaseID);
    
    String testId = "";
    
    
    @Title("Amplitude increases according to step size")
    @Test
    public void amplitudeUpdatesForOR()
    {       
            log.info("User logins into CP application and creates OR session for the searched patient");
            Section05.setUp();
            
            try {
                log.info("User will increase and decrease Amplitude according to selected step size");
                Section05.TP397_ID32();
            }catch(NoSuchElementException e){
                System.out.println("******************");
            }
}

Failure trace is as follows:

org.openqa.selenium.NoSuchElementException: Timed out after 2 seconds. Element not found
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'PF2JP03M', ip: '192.168.1.28', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_261'
Driver info: driver.version: unknown
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'PF2JP03M', ip: '192.168.1.28', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_261'
Driver info: driver.version: unknown
    at com.mobapp.pages.ORSession_RangeValuesPage.setValueInTheInputbox(ORSession_RangeValuesPage.java:345)
    at com.mobapp.pages.ORSession_RangeValuesPage.setAmplitudeValue(ORSession_RangeValuesPage.java:1438)
    at com.mobapp.steps.ORSession_CheckRangeValuesOfTonicStimulationMode.userShouldBeAbleToEnterTheValue(ORSession_CheckRangeValuesOfTonicStimulationMode.java:370)
    at com.mobapp.steps.ORSession_CheckRangeValuesOfTonicStimulationMode.userShouldBeAbleToEnterTheRequiredParameterValues(ORSession_CheckRangeValuesOfTonicStimulationMode.java:351)
    at com.tp.tp397.Procedure1_ORSession.TP397_P1_S06.amplitudeUpdatesForOR(TP397_P1_S06.java:97)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:542)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:770)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:464)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)


from Recent Questions - Stack Overflow https://ift.tt/3hY60ZH
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation