How do i verify each teststep and continue on failure

Ask general questions here.
kumprave5
Posts: 33
Joined: Wed Jul 18, 2018 9:55 pm

How do i verify each teststep and continue on failure

Post by kumprave5 » Thu Aug 02, 2018 10:02 pm

Hello,

1. For example, I have 4 teststeps (open browser, navigate to url, click on button, close application). Now, I want to print the info log only if step test step is successfully executed otherwise print the failure log. I don't think the below mentioned approach i am using is correct, please provide a suggestion on this

try
{
sc._startBrowser("chrome.exe", "abc.com");
LogUtility._info("Chrome browser started and launched abc homapage ");
sc._dom("/dom[@caption='abc']");
LogUtility._info("abc dom located successfully");
sc._link(".//ul[@id='menu-about-us']/li//a[@href='https://abc.xyz/']");
LogUtility._info("Clicked on the button successfully");
sc._closeApplication();
LogUtility._info("Application closed");
}
catch
{
LogUtility._failure("I am failed");
}


2. Suppose my test step 3 (click on button is falied) but still i want to execute teststep4 (Close Application) I would i do that? Please modify above code.
Thank you so much.

User avatar
RobinHood42
Posts: 238
Joined: Fri Jan 09, 2015 3:24 pm

Re: How do i verify each teststep and continue on failure

Post by RobinHood42 » Fri Aug 03, 2018 11:39 am

Hello kumprave5,

The "catch" block will just be entered in case of an exception within the "try" block. So, if there's any exception thrown, e.g. step fails, within your "try" block then "LogUtility._failure("I am failed");" will be executed.
2. Suppose my test step 3 (click on button is falied) but still i want to execute teststep4 (Close Application) I would i do that? Please modify above code.
You would need to call sc._closeApplication(); outside/after the "try" block . Then it's always executed.

Cheers,
Robin

kumprave5
Posts: 33
Joined: Wed Jul 18, 2018 9:55 pm

Re: How do i verify each teststep and continue on failure

Post by kumprave5 » Fri Aug 03, 2018 1:07 pm

Suppose i am not using try catch block and my code will look like this

sc._startBrowser("chrome.exe", "abc.com");
LogUtility._info("Chrome browser started and launched abc homapage ");
sc._dom("/dom[@caption='abc']");
LogUtility._info("abc dom located successfully");
sc._link(".//ul[@id='menu-about-us']/li//a[@href='https://abc.xyz/']");
LogUtility._info("Clicked on the button successfully");
sc._closeApplication();
LogUtility._info("Application closed");

LogUtility._failure("I am failed");

1. Without having try catch, how will I determine each step executed successfully or not and print meaningful log on successful execution or failure of test step.
2. Now, I don't have try catch block, nHow will i continue on failure of test step.

User avatar
RobinHood42
Posts: 238
Joined: Fri Jan 09, 2015 3:24 pm

Re: How do i verify each teststep and continue on failure

Post by RobinHood42 » Thu Aug 09, 2018 7:27 am

Hi kumprave5,
1. Without having try catch, how will I determine each step executed successfully or not and print meaningful log on successful execution or failure of test step. 2. Now, I don't have try catch block, nHow will i continue on failure of test step.
I'm not exactly sure what your methods do in case of a failure, e.g. "sc._startBrowser()". I guess they throw an exception in case of failures. If the exception isn't caught (try/catch block) your test will just end and no code after the failure is executed, so you can't even log an error message. Therefore, I would recommend to keep the try/catch block.

Cheers,
Robin

kumprave5
Posts: 33
Joined: Wed Jul 18, 2018 9:55 pm

Re: How do i verify each teststep and continue on failure

Post by kumprave5 » Thu Aug 09, 2018 1:19 pm

I would like to know your way of doing the same thing. For instance, you have a test case with 4 steps (open browser, navigate to url, click on button, close application). Then how would you log messages for each step being executed successfully or not?

I believe collecting your thoughts of doing this task will help me greatly. Thank you so much.

User avatar
RobinHood42
Posts: 238
Joined: Fri Jan 09, 2015 3:24 pm

Re: How do i verify each teststep and continue on failure

Post by RobinHood42 » Mon Aug 13, 2018 8:56 am

Hi,

If you want your test to continue in case of failure, you would need to create seperate try/catch blocks for every single step, e.g.:
//Start browser
			try
			{
				sc._startBrowser("chrome.exe", "abc.com");
				LogUtility._info("Chrome browser started and launched abc homapage ");
				
			}
			catch (Exception)
			{
				LogUtility._info("Failed to launch Chrome browser");
				
			}
			
			//Locate DOM
			try
			{
				sc._dom("/dom[@caption='abc']");
				LogUtility._info("abc dom located successfully");
			}
			catch (Exception)
			{
				LogUtility._info("Failed to find abc dom");
			}
Cheers,
Robin