How to handle system.exit in the cucumber test case

851 views Asked by At

newbie to cucumber and selenuim in java

I am calling a method in cucumber test case and there if it goes into the else part it would send a mail and exit from the system.when i am running this method with cucumber then it will send the mail and exit with test case. How to resolve that

and after that by using selenium i want to open the browser and check the mailbox to check the mail has sent by the code or not.

2

There are 2 answers

0
Codebender On

You can use Runtime.getRuntime().addShutdownHook(hook);

When you invoke this method, the thread hook will be called whenever the VM wants to shutdown (including when a System.exit() is called). You can add all your validation in the hook thread.

Check the Java Doc for more information about shutdown hook.

0
KDP On

call the method (selenium) before the exit

else{
    //code to send the mail
     seleniumMethod();
    System.exit();
 }
seleniumMethod(){

//check mail }