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.
How do i verify each teststep and continue on failure
- RobinHood42
- Posts: 324
- Joined: Fri Jan 09, 2015 3:24 pm
Re: How do i verify each teststep and continue on failure
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.
Cheers,
Robin
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.
You would need to call sc._closeApplication(); outside/after the "try" block . Then it's always 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.
Cheers,
Robin
Re: How do i verify each teststep and continue on failure
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.
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.
- RobinHood42
- Posts: 324
- Joined: Fri Jan 09, 2015 3:24 pm
Re: How do i verify each teststep and continue on failure
Hi kumprave5,
Cheers,
Robin
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.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.
Cheers,
Robin
Re: How do i verify each teststep and continue on failure
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.
I believe collecting your thoughts of doing this task will help me greatly. Thank you so much.
- RobinHood42
- Posts: 324
- Joined: Fri Jan 09, 2015 3:24 pm
Re: How do i verify each teststep and continue on failure
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.:
Robin
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