spriteCloud / lapis-lazuli

Cucumber helper functions and scaffolding for easier test automation suite development.
Other
7 stars 7 forks source link

Feature: Add the ability to customize the error message when using .find/.wait #11

Closed sjieg closed 9 years ago

sjieg commented 9 years ago

The default message given by .find/.wait are fine for the TA developers, but when these messages are eventually shown to the customer you want a more user friendly message.

Because of this we will have to do a lot of try/catch in the step definitions. Adding the possibility to override the default error message will prevent this.

browser.find(
    :a => 
        {
            :title => /login/
        },
    :error => 'Login button was not present after logging out'
).click

Because this would be a user friendly message, while debugging this would not be useful. So when enabling debug mode I'd expect to see both the custom message and the default produced error by LL.

jfinkhaeuser commented 9 years ago

Try adding :message to the hash. I'm not 100% sure it will work as expected, but there's a mechanism in there already for passing messages through.

jfinkhaeuser commented 9 years ago

Either way, I completely agree with the feature request.

jfinkhaeuser commented 9 years ago

You probably found out yourself by now that :message doesn't work quite like that, and that's because find overwrites it.

I'll figure out how to best add this feature and will let you know.

jfinkhaeuser commented 9 years ago

Made :message work like that. It was the cleanest solution.

The error function is quite complex; adding yet another parameter to it makes things worse. The change is in find, which no longer sets :message everywhere, but only does so if no :message was passed yet.

In the log, it'll look like this:

browser.find(:a => {:title => 'notfound'}, :message => "foo")
E, [2015-02-13T17:26:04.580192 #13702] ERROR -- #<IO:0x00000001e54290>: foo - Cannot find elements with selectors: {:pick=>:first, :mode=>:match_one, :message=>"foo", :selectors=>[{:a=>{:title=>"notfound"}}]} (http://www.spritecloud.com/)

That'll give you all the power for making error messages more consumer-friendly, whilst leaving everything in that you might need for debugging.