Stop Group Test if Assertion Failed in NightwatchJS - testing

Is there a way to stop test execution if assertion failed so other test group will not be executed ?

From the documentation:
Nightwatch.js instance has two objects containing the same methods to perform
assertions on elements:
.assert - when an assertion fails, the test ends, skipping all other assertions.
.verify - when an assertion fails, the test logs the failure and continues with
other assertions.
So I guess use assert? Unless you are and that's not working for you?

Using assert will stop the current test, but to stop the whole suite, you need to set the setting 'skip_testcases_on_fail' to true in your nightwatch.json config file.

Related

Does testcafe support soft assertions

I have a scenario that is an end to end testing where I have multiple assertion points. Observed that when an assertion fails test stops. But I need to just report a failed step in test results and proceed further with the test execution. Does Test cafe support soft assertions?
Not yet. You might want to split your tests so that they test more specific things and not multiple assertions in a single test case.

Is there a way to abort a test suite in TestCafe if a test in the middle fails?

I have a series of tests that are dependent on a step in the middle (such as creating an account). The API that I'm using for this is a kind of brittle (which is a separate problem), and sometimes fails. I'd like to be able to just quit the tests in the middle there when that fails, instead of wait for TestCafe to fail the initial assertions for the next few tests that follow. Is there a way to get the test controller to stop, or signify to the fixture that the tests should stop? I immediately thought of Spock's #Stepwise annotation, but I can't find anything like that in the TestCafe docs.
The Stop on First Fail option stops the entire run once a failed test occurred. If I understand your scenario correctly, you could add an assertion for a successful account creation and if it fails, exit the entire run with this option.
CLI Documentation
API Documentation (under Parameters)

How to Continues execution with hard assertion on testNG?

After hard assertion give exception on testNG it moves to onTestFailure listener for screenshot, but execution is not continuing. How to continue the execution?
Not possible, once Assertions fails then it will throw exception.
see for example https://jitpack.io/com/github/cbeust/testng/master/javadoc/org/testng/Assert.html#assertEquals-java.lang.String-java.lang.String-
if need to continue after Assertion fails then need to handle that thrown exception, so need to use try/catch
But make a note that, when Assertions are handled by try/catch then test will be passed as exceptions are handled.
You can achieve it by using QAF TestNG extension. It provides Verify and assert methods. You can use validator as Below:
Validator.verifyThat(actual,Matchers.equalTo(expected));
Validator.verifyTrue(condition, failMessage, successMsg);
Validator.verifyFalse(condition, failMessage, successMsg);
Further more for web and mobile test it has inbuilt wait, verify and assert methods available with element object.

Preventing asserts from failing tests in Codeception

I've just started exploring automated testing, specifically Codeception, as part of my QA work at a web design studio. The biggest issue I'm experiencing is having Codeception fail a test as soon as an assert fails, no matter where it's placed in the code. If my internet connection hiccups or is too slow, things can become difficult. I was wondering if there were methods to provide more control over when Codeception will fail and terminate a test session, or even better, a way to retry or execute a different block or loop of commands when an assert does fail. For example, I would like to do something similar to the following:
if ( $I->see('Foo') )
{
echo 'Pass';
}
else
{
echo 'Fail';
}
Does anyone have any suggestions that could help accomplish this?
You can use a conditional assertion:
$I->canSeeInCurrentUrl('/user/miles');
$I->canSeeCheckboxIsChecked('#agree');
$I->cantSeeInField('user[name]', 'Miles');
The codeception documentation says:
Sometimes you don't want the test to be stopped when an assertion fails. Maybe you have a long-running test and you want it to run to the end. In this case you can use conditional assertions. Each see method has a corresponding canSee method, and dontSee has a cantSee method.
I'm not sure, if I understand it correctly, but I think, you should try to use Cest.
$ php codecept.phar generate:cest suitename CestName
So you could write one test in one test function. If a test fails, it will abort. You can also configure codeception, that it will not abort and show only the one test which fails in a summary at the end of all tests.
See here in the documentation: https://github.com/Codeception/Codeception/blob/2.0/docs/07-AdvancedUsage.md
Maybe it's better to use:
$I::dontSee('Foo');
Regards

Create screenshot after failed selenium command

The PHPUnit Selenium base class has an option to make a screenshot on failure, which is a huge help in finding out why the test failed. The selenium server, however, returns an error instead of a failure on any error condition other than explicit assert* calls (such us trying to do something with a non-existent element). If I try to make a screenshot after the server reports the error, I get another error saying that the server already discarded the session. Is there any way to change that behavior?
Update: this is because PHPUnit breaks the connection when it receives an error. I was able to change it by some (rather ugly) manipulation of the PHPUnit code.
Make those interactions as test cases.
For example in perl,
If it is written as below and fails due to a non-existent element. the script will error out
$sel->type("email-id","trial\#trial.com");
While if the above step is made as a test case by writing it as follows
$sel->type_ok("email-id","trial\#trial.com");
If there is a non-existent element, the test case will only fail, and the script will continue.
So using TAP (test any protocol) by using the module use Test::More; , if _ok is added after a function, the function return will be used to determine the fate of the test case.
ie. - A return of 'O' means the test Failed
and A return of '1' means the test Passed
It is not the Selenium server but the SeleniumTestCase class for PHPUnit 3.4 which automatically sends a stop command when it detects an error (Driver.php line 921). PHPUnit 3.6 seems handle errors better.
I think you can overwrite method 'travelbox' and make something like this:
public function onNotSuccessfulTest(Exception $e){
file_put_content('/xxx/xxx.jpg', $this->currentScreenshot());
}