How to handle test case fails in Katalon Studio - 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.

Related

How to use assert statement in 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

Test in mocha not completing if shareReplay operator of RxJS is used

I have a simple Javascript function that returns an observable to which I have applied the shareReplay operator with parameter 1.
[![export function doStuffWithShareReplay() {
return interval(100).pipe(
shareReplay(1),
tap(d => console.log('do stuff 1', d)),
take(5)
);
}
If I put such function within a mocha test and run it from within VSCode, it seems that the execution of the test never completes and I have to stop the test execution manually. More precisely, the test passes as expected, but the small control pad at the top-center of VScode is not closed and I have to click on the red button to close it, as you can see in the following picture. If I remove shareReplay the execution ends as expected. I am wondering which is the reason of the behavior.
Use publishReplay(1) and refCount() instead of shareReplay(1):
return interval(100).pipe(
publishReplay(1),
refCount(),
...
There's a bug in shareReplay(1) since RxJS 5.5 (that still exists in RxJS 6.1) that prevents it from unsubscribing from its source.
For more details see this issue: https://github.com/ReactiveX/rxjs/issues/3336

Perl Selenium::ActionChains move_to_element not working

I am trying to click on a menu dropdown. The dropdown appears when the mouse pointer is on a menu element. The workaround can be by clicking on the menu element aslo but that sometimes is giving error due to wait time being large or small depending on the speed of site.Thus, I want to use ActionChains move_to_element for this. But it is not working no errors nothing but not working.
my $driver = Selenium::Chrome->new(binary=>"D:\\chromedriver_win32\\chromedriver.exe");
my $action_chains = Selenium::ActionChains->new(driver => $driver);
$elem = $driver->find_element(".//*[\#id='navl']/li[3]/a");
$action_chains->move_to_element($elem);
$driver->pause(5000);
$driver->find_element_by_xpath(".//*[\#id='navl']/li[3]/ul/li[1]/a")->click;
$driver->pause(50000);
$driver->shutdown_binary;
I am not sure if it is of any help - there are many questions about Selenium actions and action chains and many suggestions - I struggled with a similar problem, using Python Selenium bindings though.
First of all in the code above, it could be that there is no final perform() method called after move_to_element
Secondly - and that thing was my own problem and the source of lots of bafflement on my side - i discovered that in my case, after a single perform(), i couldn't reuse the same ActionChains object - there was no error or complaint, but something was not happening right. After I created a new ActionChains object, the subsequent new chain of actions and the final perform() worked as expected.

Unable to set breakpoints in chrome developer tools

When I use chrome developer tools to set a breakpoint it wont set it exactly in the line that I wanted to be set. It changes it to another line. Why this happens? and what should I do if i want to set a breakpoint in the line i want?
here is the video : https://drive.google.com/file/d/0B7NuLgKMVzkgUHhaclM0YW1BSEU/view?usp=sharing
The debugger allows you to add breakpoints on statements. This is achieved by clicking on the line number where the statement begins. You can't add a breakpoint on an expression within.
Example
The following code is a mockup of the Angular code in your video:
$stateProvider.state("key1", {
url: "url1",
controller: "controller1",
templateUrl: "templateUrl1"
}).state("key2", {
url: "url2",
controller: "controller2",
templateUrl: "templateUrl2"
});
There is only one statement, beginning on line 1 and ending on line 9. You may be calling two functions that chain together, but they are one statement.
Injecting debugger/trace statements
You can work around this restriction by adding a debugger statement into the state function, so that it breaks for every chained function call. You can run something like into the Console/Snippet:
var oldState = $stateProvider.state;
$stateProvider.state = function() {
debugger;
return oldState.apply(this, arguments);
}
This saves a reference to the old function definition, and then overwrites the current with the debugger statement. If you didn't care about the real functionality, you could end it there. However, to continue normal execution, we can call the origin function using apply, which specifies the context and the arguments to be passed in. You can read a detailed explanation here.
Now this will break for every state execution. What if you just wanted to break for a particular case? Well you could add a Conditional Breakpoint on the debugger statement as per below:
Now the code will only break when the key is 'key2'.
A debugger statement can be intrusive on your execution flow, so you could replace it with a console.log statement, or anything else. The conditional logic could be omitted in this case.

Eclipse breakpoint condition for objects

I have a problem with the eclipse breakpoint condition pattern.
Regarding this code snippet
public void updateGateway(Gateway pGatewy) {
mGateway = pGateway;
I want to stop the process only if
pGateway.getNumber()==123.
But the condition is without effect and I tested it already successful with this number(but without condition).
What I have to insert in the editor of the Breakpoint properties dialog? The checkbox Conditional is selected.
Thx in advance.
Update your condition
pGateway.getNumber()==123.
to
pGateway.getNumber()==123
Choose Suspend when true option.
Conditional debugging can be run on my machine. You can reference here.