I am writing the script for web testing. And I have code around 100 lines where with set text, click the buttons and etc.
Now the question is, I wanted to handle the screen shot when the script is failed. I wanted to handle this without auto screen shot. Screenshot name should contain with the date & time also.
where do we write the code to take the screen shot when I have 100 lines of code as we cannot one after the every line of the code. I am coding with the CONTINUE_ON_FAILURE option. In this case, how to identify particular test case is failed. Can someone please share the code for taking the screenshot !!
The only solution I know is to write tests the way I write them - but it’s not for everyone.
The idea is to wrap all test case steps in try/catch(). All failures must come from throw. In the catch() you can add any failure handling, including screenshots.
public class Test extends basePage {
Test() {
WebUI.whatever()
// More steps
}
}
try {
new Test()
passThisTest()
} catch(Exception e) {
failThisTest(e.message)
// Do Screenshot
}
Otherwise, I guess we’re talking about metaprogramming, and for that @kazurayam is your man.
The downside with listeners is, they are not in the same scope (or execution context) as the groovy script class that hosts your Test Case - the script class run() method[1].
But what do I know… this may be exactly what OP needs.
[1] The more I stumble across this, the more I think the devs got this part of the design wrong. I’d appreciate a new set of hooks, something like this pseudocode:
object run( ... ) {
ifExists(runStart) runStart(context)
// call Test Case Steps
ifExists(runEnd) runEnd(context)
}
Why? What is the reason why the auto screen shot is not enough for you? In other words, what problem do you want to solve by taking screen shots in your own way?
Actually, I have the code for example 100 lines between try…catch statement. When I execute the testsuite, I can check the ProjectSettings -> Report -> TakeScreenshot check box. But that screenshot will not have test case number, data & time. So, I wanted to handle it separately with the script.
So, when I have 100 lines of code between the try…catch statements, after what line I need to write the screenshot code and how to write that ?
Coming to the CONTINUE_ON_FAILURE, all my coding statements will have WebUI.XX(findTestobject(xx, CONTINUE_ON_FAILURE) because we don’t want the browser to get close until the suite is completed. So, how to identify particular line is failed and if it is failed, how to store it into variable and update the status sheet with the failed status.
The above two are my queries. Can you please look into this and guide me to proceed further ?
Please let me know if you have any questions in this.
@vdavuluri2 as i mentioned in the private message you sent me … we are here for fun, not employees. and we have jobs too.
so please be patient until we find time to analyse your issue and mock-up some code. thank you!