How to use assert statement in Katalon Studio? - katalon-studio

Can someone tell me please how to use an assert statement in Katalon Studio?
The scenario is- I have to create one user (user=program), once I click the submit button I have to capture the result if the user is created successfully or not. If the user is created successfully, only then the execution should proceed further if not then the test case should fail and further execution should stop.
Please let me how to use assert statement in Test Case, Object repository or global variable or keywords?

In Katalon Studio, default assertions are available. Using which we can keep the validation check points. Please refer to below code where its checking for userPofileImge element. If user profile img present, assertion will be PASSED and execution will continue, or else failed and execution stops.
**Code Snippet**
assert WebUI.verifyElementVisible(findTestObject('HomePageLocators/userProfileImg')) == true : 'login failed as user profile is not present'

If you are using Groovy language with Katalon studio, this is the answer:
def x = 1
assert x == 2
// Output: // // Assertion failed: // assert x == 2 //
| | // 1 false
Groovy Language features: http://docs.groovy-lang.org/docs/latest/html/documentation/core-testing-guide.html#_introduction

Katalon Studio has significant customized assert methods. You can choose as per your requirement and control failure. In your case, when you click on Submit, user is created and probably you get alert message, notification message and or new user should be visible in user area.
So you have to identify checkpoint from above and get the property and WebUI.verify--select method with FailureHandling.STOP_ON_FAILURE.
Katalon Studio provides mutiple way to handle test failure
FailureHandling.CONTINUE_ON_FAILURE
FailureHandling.STOP_ON_FAILURE // Applicable in your case
FailureHandling.OPTIONAL
Code will be like this
WebUI.verifyElementPresent(findTestObject('User Locator'), maxWaitTime,
FailureHandling.STOP_ON_FAILURE) // use this if you want to fail further
execution

Related

Error handling in extensions to visual studio code

Can someone point me to best practices for error handling in a Visual Studio Code extension?
I'm writing an extension in TypeScript that contributes a debugger. I want to log unexpected behavior, sometimes as information to the user explaining that something didn't go right, sometimes to create a trail for debugging, but certainly not to fail silently. Using console.log or console.error shows up in the debug output when I am debugging the extension, but I can't find it when the extension is installed. Do I have to open an output channel specifically for my extension and write everything there? Should I be throwing up showInformationMessage and showErrorMessage windows? Should I just be throwing exceptions and hope that code will do the right thing?
In my extension I use two ways for feedback. One is an output channel for errors produced by an external process that I'm using for the work.
Create the channel in your activation method:
outputChannel = window.createOutputChannel("ANTLR4 Errors");
and push output to it whenever you have something:
} catch (reason) {
outputChannel.appendLine("Cannot parse sentence generation config file:");
outputChannel.appendLine((reason as SyntaxError).message);
outputChannel.show(true);
return;
}
The other one is what you already considered:
if (workspace.getConfiguration("antlr4.generation").mode === "none") {
void window.showErrorMessage("Interpreter data generation is disabled in the preferences (see " +
"'antlr4.generation'). Set this at least to 'internal' to enable debugging.");
return null;
}
which is for messages I create in the extension and that users need to see and take seriously.

How to handle test case fails in Katalon Studio

In my test case I decide whether I want to toggle my radio button. I check if my radio button does not have the checked attribute as follows:
TestObject srcCurrOpModeRadioBtn = guiUtils.createControl('config-src-op-mode-currentradio')
if(WebUI.verifyElementNotHasAttribute(srcCurrOpModeRadioBtn, 'checked', 5)){
TestObject srcCurrOpModeToggle = guiUtils.createControl('config-src-op-mode-current')
WebUI.click(srcCurrOpModeToggle)
WebUI.delay(1)
}
This works fine when my object does not have the checked attribute, but when my object is already checked (in the state that I want it to be), my test case fails. How do I make it so that instead of failing, it carries out the remaining test?
In simpler words, I have a toggle that toggles between 2 modes, lets call them mode1 and mode2. This specific test tests mode1's preferences, so before testing mode1's preferences, I have to toggle to mode1. My logic works when the toggle is at mode2 at the start of the test but it fails when I am already on mode1. I know that it fails because when mode1 is selected, its radio button already has a checked attribute and so the if statement fails but I don't want my test case to fail because of this, I want to test mode1's preferences.
There is another parameter to WebUI.verifyElementNotHasAttribute() - flow control.
You need to set FailureHandling.OPTIONAL so the test continues execution even if the function returns false. Then you can write the "else" part with corresponding logic.

Debugging test cases when they are combination of Robot framework and python selenium

Currently I'm using Eclipse with Nokia/Red plugin which allows me to write robot framework test suites. Support is Python 3.6 and Selenium for it.
My project is called "Automation" and Test suites are in .robot files.
Test suites have test cases which are called "Keywords".
Test Cases
Create New Vehicle
Create new vehicle with next ${registrationno} and ${description}
Navigate to data section
Those "Keywords" are imported from python library and look like:
#keyword("Create new vehicle with next ${registrationno} and ${description}")
def create_new_vehicle_Simple(self,registrationno, description):
headerPage = HeaderPage(TestCaseKeywords.driver)
sideBarPage = headerPage.selectDaten()
basicVehicleCreation = sideBarPage.createNewVehicle()
basicVehicleCreation.setKennzeichen(registrationno)
basicVehicleCreation.setBeschreibung(description)
TestCaseKeywords.carnumber = basicVehicleCreation.save()
The problem is that when I run test cases, in log I only get result of this whole python function, pass or failed. I can't see at which step it failed- is it at first or second step of this function.
Is there any plugin or other solution for this case to be able to see which exact python function pass or fail? (of course, workaround is to use in TC for every function a keyword but that is not what I prefer)
If you need to "step into" a python defined keyword you need to use python debugger together with RED.
This can be done with any python debugger,if you like to have everything in one application, PyDev can be used with RED.
Follow below help document, if you will face any problems leave a comment here.
RED Debug with PyDev
If you are wanting to know which statement in the python-based keyword failed, you simply need to have it throw an appropriate error. Robot won't do this for you, however. From a reporting standpoint, a python based keyword is a black box. You will have to explicitly add logging messages, and return useful errors.
For example, the call to sideBarPage.createNewVehicle() should throw an exception such as "unable to create new vehicle". Likewise, the call to basicVehicleCreation.setKennzeichen(registrationno) should raise an error like "failed to register the vehicle".
If you don't have control over those methods, you can do the error handling from within your keyword:
#keyword("Create new vehicle with next ${registrationno} and ${description}")
def create_new_vehicle_Simple(self,registrationno, description):
headerPage = HeaderPage(TestCaseKeywords.driver)
sideBarPage = headerPage.selectDaten()
try:
basicVehicleCreation = sideBarPage.createNewVehicle()
except:
raise Exception("unable to create new vehicle")
try:
basicVehicleCreation.setKennzeichen(registrationno)
except:
raise exception("unable to register new vehicle")
...

chai.assert() wont run methods in a test before the assertion (chai assert lib with protractor)

First time I post an issue on SO, I hope I'm doing it right.
it (' :: 2.0 service creation :: should fill out service info tab', function(){
createNewService.setServiceName(e2eConfig.newServiceDetails.basicServiceName);
createNewService.selectCategory();
createNewService.setIntroText(e2eConfig.newServiceDetails.introText);
createNewService.selectParent();
createNewService.uploadIcon();
createNewService.nextTab();
//right now assert will fire off without running the methods above because
//we are still on the infoTab
assert(($(createNewService.selectors.infoTab).isDisplayed()) == true, 'did not move to the next tab');
},20000);
What this test does is it fills the inputs, selects drop-downs where necessary and uploads a file.
The test then attempts to switch to the next tab in the widget.
To determine whether it managed to switch to the next tab I want to make a chai library assertion with a custom message.
with the current code the assert will return true because it sees the infoTab and the test will fail without running any of the methods before the assert
if I change the assert line to look for '!== true', then it's going to run the methods and move on
In any case, would it be better to do this in a different manner or perhaps use expect instead of assert?
Chai assert API
Chai expect API
All Protractor function calls return promises that resolve asynchronously, so if the functions you defined on createNewService are all calling Protractor functions you'll have to wait for them resolve before calling the assert. Try something like the following:
it (' :: 2.0 service creation :: should fill out service info tab', function(done) {
createNewService.setServiceName(e2eConfig.newServiceDetails.basicServiceName);
createNewService.selectCategory();
createNewService.setIntroText(e2eConfig.newServiceDetails.introText);
createNewService.selectParent();
createNewService.uploadIcon();
createNewService.nextTab().then(function() {
assert.eventually.strictEqual($(createNewService.selectors.infoTab).isDisplayed(), true, 'did not move to the next tab');
done();
});
},20000);
A few things to note:
This example assumes that createNewService.nextTab() returns a promise.
You'll need to use a library like chai-as-promised to handle assertions on the values returned from promises. In your code you're asserting that a promise object == true, which is truthy due to coercion.
Since your functions run asynchronously, you'll need to pass a callback to your anonymous function then call it when your test is finished. Information about testing asynchronous code can be found here.

reusable sub process in JBPM 6.1

I want to create a reusable sub processes in jbpm 6, but I cant't see any processes in Called Element pop up. It doesn't load any process information. Please can anyone give me the reason for this situation?
I'm not sure I completely understand your question/issue. However, I have successfully used reusable suprosses in JBPM 6.1.0.Final and eclipse.
These are steps:
Create a resuable subprocess with and ID. Make note the ID for steps 2-5.
Drag and Drop a "Call Activity" Activity to the bpmn
Edit the properties of the "Call Activity" - click on "Call Activity" and go to eclipse properties tab.
Click on "pencil" edit icon:
Enter the reusable subprocess id in edit window and type reusable subprosses id and hit o.k.
You should be able to run you bpmn and see the execution of subprocess.
I've just hitted this error today at work, using 6.1.0.Final. If process id has underscores it will not show in workbench called activity popup. Look at the sources:
Asset<String> processContent = ServletUtil.getProcessSourceContent(p, profile);
Pattern idPattern = Pattern.compile("<\\S*process[^\"]+id=\"([^_\"]+)\"", Pattern.MULTILINE);
Matcher idMatcher = idPattern.matcher(processContent.getAssetContent());
if(idMatcher.find()) {
String pid = idMatcher.group(1);
String pidcontent = ServletUtil.getProcessImageContent(processContent.getAssetLocation(), pid, profile);
if(pid != null && !(packageName.equals(processPackage) && pid.equals(processId))) {
processInfo.put(pid+"|"+processContent.getAssetLocation(), pidcontent != null ? pidcontent : "");
}
}
That regex used to get process id will not match "_". Check that your process id is valid.