How to continue the test case when the statement failed in CasperJS?

Is there a way to continue the test suite on failure? Example:

casper.test.begin("",3,function suite(){ casper.start(url).then(function(){ test.assert(...); test.assert(...); //If this assert fail, the script stop and the third assert isn't tested test.assert(...); }).run(function(){ test.done(); }); }); 

I want all claims to be tested, even if some fail. Is it possible?

+5
source share
2 answers

See the goperjs google group post . We can surround the statement using casper.then(..

This code works the way I want (but this method is not the best?)

 casper.test.begin("",3,function suite(){ casper.start(url).then(function(){ casper.then(function(){ test.assert(...); //if fail, this suite test continue }); casper.then(function(){ test.assert(...); //so if assert(1) fail, this assert is executed }); casper.then(function(){ test.assert(...); }); }).run(function(){ test.done(); }); }); 
+6
source

This is usually what you want when testing a device: if it fails anyway, do it quickly. That is, a crash on the first problem in each test function. In addition, later tests usually involve earlier tests, for example, if the page title is incorrect and says 404, there is no exact test that the page will display the correct number of images.

I assume that you want this to get more information in the test results, and one way to do this would be to use a single statement and a custom error message:

 var title = this.getTitle(); var linkText = this.getHTML('a#testLink'); this.assert( title == "MyPage" && linkText == "continue", "title=" + title + ";a#testLink = " + linkText); 

But it can get messy. If you want to use the full power of the assert family of functions, rather than throw them away, and instead continue to study the source code , this may work:

 test.assert(false, null, {doThrow:false} ); test.assertEquals(1 == 2, null, {doThrow:false} ); test.assertEquals(2 == 2); 

And if you want this to be the default in all your statements, well, cracking the code might be the best choice! (Change the default value of true for doThrow to false .)

+4
source

Source: https://habr.com/ru/post/1210333/


All Articles