Missing method handling. #239

Closed
geb-bot opened this Issue Dec 3, 2012 · 4 comments

Projects

None yet

2 participants

@geb-bot
geb-bot commented Dec 3, 2012

Originally created by marko.m.

Please consider changing the behavior of empty-param missing method handling.

The expected behavior would be a missing method exception, but instead it surprisingly returns an empty element set.

Mailing list discussion:
http://goo.gl/j59Pq

Sample code:

class HomePage extends Page {
    static url = "http://google.com/"
}


Browser.drive(driver:new ChromeDriver()) {
    to HomePage

    // expecting to execute HomePage.foobar(), 
    // but instead is silently ignored?!?
    foobar()  
}.quit()
@geb-bot
geb-bot commented Jan 6, 2013

Originally posted by marko.m.

After more list discussion with Marcin i understand that missingMethod delegates to a mixed-in Navigator of the current Page/Module context.

Polymorphic Navigator calls against Page/Module sound reasonable, so i don't want this request to sound like i'm pushing to break that.

My request specifically concerns the syntax of field shortcuts, which are handling Page/Module missingMethod/Property calls.

If an intended Page/Module method/property call has a syntax error, then it will be interpreted as an field lookup.

For that case, a syntax error can be very surprising and difficult to diagnose, particularly if the field does not exist (most likely case), since the result will be an empty Navigator.

** So in most cases, a Page/Module method/prop call syntax error results in no observable behavior.

What is the alternative?

One possible alternative is to disable the shortcut behavior of the internal Page/Module Navigator. Against an explicit Navigator all could behave as is, but method/prop calls against Pages/Modules would never result in field lookups.

ie.

// any field lookup directly against a Navigator could work as is.
$("form").name()

// even shorter would be a lookup relative to the dom root/base of the current Page/Module.
$().name()

// or a new syntax could be added that makes it explicit what the intent is.
input.name() // ???

// but if a Page/Module method call failed, then an error would be reported immediately, rather than attempt to lookup an field.
name()

Thank you.

@geb-bot
geb-bot commented Jan 2, 2014

Originally posted by Marcin Erdmann.

We could improve it the following way:

In my view the only thing we could do here is throw some kind of exception when there is no element with the given name on the page. The exception thrown should extend MissingMethodException and carry a message that we were looking for an element with the given name but didn't find it. This would remove the surprise factor but also slightly limit the functionality of the shortcut - it could be only used if the element with the given name is on the page. On the other hand it would keep the main functionality intact which I'm happy about. It will be also consistent with property shortcuts (like iDontExist = 'foo') failing fast with a MissingPropertyException.

@geb-bot
geb-bot commented May 10, 2014

Originally posted by Marcin Erdmann.

Thanks for being so persistent on this. In hindsight it's the only right thing to do in such situation. Fixing this also led to finding multiple places in the codebase where non existing methods were being called but they were not caught because of this.

@geb-bot
geb-bot commented Jun 12, 2014

Resolved

@geb-bot geb-bot added the New feature label Apr 12, 2015
@erdi erdi was assigned by geb-bot Apr 12, 2015
@geb-bot geb-bot added this to the 0.9.3 milestone Apr 12, 2015
@geb-bot geb-bot closed this Apr 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment