groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dinko Srko─Ź <dinko.sr...@gmail.com>
Subject Re: Call Method Without Params
Date Tue, 18 Aug 2015 07:15:22 GMT
On 18 August 2015 at 07:10, Anto Aravinth <anto.aravinth.cse@gmail.com> wrote:
> [...]
> loadGroovyPage.groovy:
>
> TestBehavior('test google home page' , {
>
>     loAd "http://www.google.com"
>
>     driver.findElement(By.id("lst-ib")).sendKeys("Selenium!")
>
> })
>
> the TestBehavior method is defined in SeleniumCallHandler. Like:
>
>     def TestBehavior(def name,Closure cls)
>
>     {
>
>         cls.delegate = this;
>
>         cls();
>
>     }
>
> The above code in loadGroovypage works fine. But to make my DSL good, I
> tried this:
>
> TestBehavior 'test google home page' , {
>
>     loAd "http://www.google.com"
>
>     driver.findElement(By.id("lst-ib")).sendKeys("Selenium!")
>
> }
>
> (same code without param's) And this code fails with message:
>
> Error:(1, 13) Groovyc: unexpected token: test google home page on
> loadGroovyPage.groovy.
>
> Where I'm making the mistake? Does the method call without params should
> work without any issues right?

The problem is with method's name, i.e. it starts with a capital
letter. If the method's name had been `testBehavior`, it would have
worked fine.

I may not be the most suitable person to explain this, but here it is
... Generally, a name starting with a capital letter is considered a
class. Having `Foo(arg1, arg2)` is not ambiguous, so you got away with
it. On the other hand, `Foo arg1, arg2` is, hence the error.

Cheers,
Dinko

>
> Thanks,
> Anto.

Mime
View raw message