Need some best practices

Hi,

I’ve just read the sample-docu (https://www.katalon.com/resources-center/tutorials/sample-web-automation-test-project/) and some of the other documentation.

I’m not shure if I got it right, but the sample test is just a simple record/replay test? How would you write a real world test? e.g. let’s say the test does enter the wrong passwort at the login screen. How do you define sucess for this operation? Lets assume that success would be: after the login click another page /profile is loaded (http 200), how can I check this? Is this the correct approach?

Cheers,
Manuel

@3816-ManuelWenk One approach would be to check the URL after the login click and assign the result to a boolean variable, then Assert the variable:

Boolean bLoginFailed = WebUI.getUrl().contains('failed')
Assert bLoginFailed == false

If the URL contains “failed”, the boolean will be true and Assert will cause the Test Case to fail. I suppose you could even skip the variable entirely. Another option would be to use VerifyMatch on the URL:

WebUI.VerifyMatch(WebUI.getURL(), <expected URL>)

VerifyMatch will throw a StepFailedException (which will cause the Test Case to fail, depending on the FailureHandling for the step) if the URLs do not match.

There is a command called ‘verifyElementPresent’. So let’s say you have an element on your home page (after successful login) called ‘id=Logout’. After the step that logs you in, insert Command = verifyElementPresent with the target id=Logout. If the script hasn’t logged you in this step will fail. One other thing to note.
To avoid Katalon looking for the element before the home page has loaded, insert the command ‘waitForPageToLoad’. The value you enter is the amount of time you want the app to wait. 1000 = 1 second. Don’t worry to much about putting in a fairly high value as Katalon will proceed once the page has loaded.

Hello,

My test case requires some transaction data to be captured from the application and dump into an excel file (which I have achieved using custom keyword). I have called the keyword at the end of my test step before closing of the browser assuming my test case has passed. However, if a test step fails in between this step is not executed and i lose my transaction data. Can someone suggest me how can i ensure to dump this data in excel even if my test case fails in between?

In selenium, I used to achieve this with the help of try… catch… blocks.

Appreciate the quick response.

Thanks.

@5520-AnupNair You can still use try… catch… blocks. When a step fails, it throws an exception. If you catch the exception, the Test Case continues. You should be able to do something like this:

try {
     WebUI.click(<some Test Object not on this page>)
}
catch (Exception e) {
     CustomKeywords.SaveExcelData()
     Throw e
}

The above example assumes you still want the Test Case to fail (if the expected object is missing) after saving your data.

3 Likes

Thank you very much Shadhi Morrow for your help.