Verify Error for every line in Script Mode

Hi,
I am writing the code as below for one of my test case for web testing. During the coding, how do I check the error for every line of the code and also please provide one example !!!

WebUI.navigateToUrl(‘https://cs15.com:8201/servlet/GGate’)

WebUI.click(findTestObject(‘Object Repository/ORTC01/Page_/a_Return to legacy Global Logon’))

WebUI.setText(findTestObject(‘Object Repository/ORTC01/Page_Security Server Login/input_ID_userid’), “uu2313”)

WebUI.setText(findTestObject(‘Object Repository/ORTC01/Page_Security Server Login/input_Password_password’), “tg1jg”)

Im not sure i understand? what are checking the lines for. If they are failing and you want to provide a message for that you can use a try catch block for your lines of code, is that the kind of thing you are looking for ?

1 Like

Thanks for your reply. Let say for example, I have opened url with the above link and need to verify the particular content. If it is valid, it should proceed else it should fail and stop the continuity of the execution.
And the same way, user id box should be enabled and password also should be enabled to enter else it should fail.

Yeah… may be try… catch or any other possibility… please suggest.

Ok so you can use IF Else statements for that. Im not sure sure of your coding experience. Have a read of this doc, if your still unsure maybe i can try provide some examples for you

1 Like

Hi Venkat,

Try to browse for the overloaded method where the failure handling is in the parameter of the method.

For example:

//you will see this as a suggestion when you are typing WebUI.
//this is applicable in most/all WebUI keywords
WebUI.click(TestObject yourTestObject, FailureHandling flowControl)

//to fill the parameter, do this. . . 
WebUI.click(findTestObject("Object/yourTestObject"), FailureHandling.STOP_ON_FAILURE)

//some of the most commonly used failure handling methods
FailureHandling.CONTINUE_ON_FAILURE
FailureHandling.STOP_ON_FAILURE
FailureHandling.OPTIONAL

I think this is what you are looking for as you mention here:

Give it a try. . . Hope that helps. . . :slight_smile:

@hpulsford & @Arnel Thanks for your clarifications.
For each line of the code, if there is any invalid result, my test should not stop and it should exit from the test case and continue with the next one. In this case, if I cannot use FailureHandling.STOP_ON_FAILURE, as it stop the exectuion and may close the browser also.
Here my condition is browser also should not be closed until the suite is completed.

Please Suggest to proceed further.

In these test cases do you have nested test cases? If a test fails, it will move onto the next test case in the suite so youve lost me on what you expect to happen.

1 Like

If any test case is failed, the browser should not be closed. And it should be moved to next test case and in the browser it starts from the home. There are no nested tested cases.

So i understand what you want to do but thats not how the test suite will work, each test case will start a new instance of the browser driver. If you want to have all the test cases be completed in the same browser, you will have to create a test case with all of those test cases nested inside. You can then run a try catch for each test case which will prevent the browser from closing if the test case fails.

1 Like

Yes. That is correct. I will have to create a test case with all of those test cases. Where and how I can give the try…catch statements ? or show me one example with my code.
Probably, if I don’t use STOP_ON_FAILURE, do I need to use try… catch ? I want the suggestion not preventing closing the browser… only to handle the errors !!

Please suggest.

Now the way you want to handle the errors is up to you, as you said if you dont use STOP_ON_FAILURE you can just use FailureHandling.CONTINUE_ON_FAILURE. This will continue on when the test case fails and shouldnt close the browser.

The try catch will just work with you trying the test case, if it fails then whatever you put in the catch block will be exectued, this could be a message “test case a has failed” and Coninue on failure. Try catch will just allow you to customise how you handle each. (You can find examples in the doc i linked above)

But to be honest, for you it looks like just using Continue_On_Failure will be fine :slight_smile:

1 Like

Appreciate your help @hpulsford

I will use STOP_ON_CONTINUE. Referring the below code, if line 1 code is failed, will try…catch end of the code will get call ? i mean, one try…catch is enough for all the four lines or for every line of code is required try…catch ??

with the below sample code, if you can provide one example, it would be fine. As I am new to this tool. Thanks. Great help.

1. WebUI.navigateToUrl(‘https://cs15.com:8201/servlet/GGate’)
2. WebUI.click(findTestObject(‘Object Repository/ORTC01/Page_/a_Return to legacy Global
Logon’))
3. WebUI.setText(findTestObject(‘Object Repository/ORTC01/Page_Security Server
Login/input_ID_userid’), “uu2313”)
4. WebUI.setText(findTestObject(‘Object Repository/ORTC01/Page_Security Server
Login/input_Password_password’), “tg1jg”)

try {
} catch

So instead of using all 4 lines you will just call each test case in the main test case. It will look something like this -

WebUI.callTestCase(findTestCase('THIS WILL BE THE NAME OF YOUR TEST CASE'), [:], FailureHandling.CONTINUE_ON_FAILURE)

By using the continue it will continue if it fails, no need for you to use a try catch.

1 Like

Thanks for your suggestion, @hpulsford

Actually the four lines I mentioned as a sample. It will be huge script around 300 lines of script that I need to develop. But, my question was, if I have four or three hundred lines of code, where I need to keep my try…catch block ? And also with example of my lines of code.

try
{
WebUI.navigateToUrl(‘https://cs15.com:8201/servlet/GGate’)

WebUI.click(findTestObject(‘Object Repository/ORTC01/Page_/a_Return to legacy Global Logon’))

WebUI.setText(findTestObject(‘Object Repository/ORTC01/Page_Security Server Login/input_ID_userid’), “uu2313”)

WebUI.setText(findTestObject(‘Object Repository/ORTC01/Page_Security Server Login/input_Password_password’), “tg1jg”)
}
catch (Exception e)
{
//your code when steps fail
}

1 Like

Thanks for your suggestion, @hpulsford