You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by Mohan Radhakrishnan <ra...@gmail.com> on 2017/12/11 09:36:04 UTC
Groovy code with Function or Predicate
Hi,
When I try to pass a lambda to a Selenium API call I see this error.
Believe this version of Selenium uses Guava lambdas.
I understand that I need to be explicit and specify whether it is a
Function or a Predicate. But don't know how to do this with groovy.
So here I may have to explicitly declare a Function with an 'apply' method.
Cannot resolve which method to invoke for [class Fluent$_closure1] due to
overlapping prototypes between:
[interface com.google.common.base.Function]
[interface com.google.common.base.Predicate]
ieDriver = new ChromeDriver();
class Fluent{
ChromeDriver ieDriver;
def application = { wd -> wd.findElement(By.name("q"))}
Fluent( ChromeDriver ieDriver){
this.ieDriver = ieDriver;
}
public WebElement waitFluently(){
Wait wait = new FluentWait( ieDriver)
.withTimeout(10, SECONDS )
.pollingEvery(5, SECONDS)
.ignoring(NoSuchElementException.class);
WebElement foo = wait.until(application);
}
}
try{
ieDriver.get("http://www.google.com");
WebElement element = new
Fluent(ieDriver).waitFluently(); //driver.findElement(By.name("q"));
}catch(Exception e) {
log.info(" Exception " + e.getMessage());
}finally{
ieDriver.quit();
}
Thanks,
Mohan
Re: Groovy code with Function or Predicate
Posted by Paul King <pa...@asert.com.au>.
that or:
wait.until(application as Function)
Cheers, Paul.
On Mon, Dec 11, 2017 at 8:46 PM, Mohan Radhakrishnan <
radhakrishnan.mohan@gmail.com> wrote:
> I posted this too soon.
>
> This line
>
> Function<WebDriver, Boolean> application = { wd ->
> wd.findElement(By.name("q"))}
>
> removes that error. Hope this is the right way.
>
> Thanks,
> Mohan
>
> On 11 December 2017 at 15:06, Mohan Radhakrishnan <
> radhakrishnan.mohan@gmail.com> wrote:
>
>> Hi,
>>
>> When I try to pass a lambda to a Selenium API call I see this error.
>> Believe this version of Selenium uses Guava lambdas.
>>
>> I understand that I need to be explicit and specify whether it is a
>> Function or a Predicate. But don't know how to do this with groovy.
>>
>> So here I may have to explicitly declare a Function with an 'apply'
>> method.
>>
>> Cannot resolve which method to invoke for [class Fluent$_closure1] due to
>> overlapping prototypes between:
>> [interface com.google.common.base.Function]
>> [interface com.google.common.base.Predicate]
>>
>>
>> ieDriver = new ChromeDriver();
>>
>> class Fluent{
>>
>> ChromeDriver ieDriver;
>> def application = { wd -> wd.findElement(By.name("q"))}
>>
>> Fluent( ChromeDriver ieDriver){
>> this.ieDriver = ieDriver;
>>
>> }
>>
>> public WebElement waitFluently(){
>>
>> Wait wait = new FluentWait( ieDriver)
>> .withTimeout(10, SECONDS )
>> .pollingEvery(5, SECONDS)
>> .ignoring(NoSuchElementException.class);
>> WebElement foo = wait.until(application);
>>
>> }
>> }
>> try{
>> ieDriver.get("http://www.google.com");
>> WebElement element = new
>> Fluent(ieDriver).waitFluently(); //driver.findElement(By.name("q"));
>> }catch(Exception e) {
>> log.info(" Exception " +
>> e.getMessage());
>> }finally{
>> ieDriver.quit();
>> }
>>
>>
>> Thanks,
>> Mohan
>>
>
>
Re: Groovy code with Function or Predicate
Posted by Mohan Radhakrishnan <ra...@gmail.com>.
I posted this too soon.
This line
Function<WebDriver, Boolean> application = { wd ->
wd.findElement(By.name("q"))}
removes that error. Hope this is the right way.
Thanks,
Mohan
On 11 December 2017 at 15:06, Mohan Radhakrishnan <
radhakrishnan.mohan@gmail.com> wrote:
> Hi,
>
> When I try to pass a lambda to a Selenium API call I see this error.
> Believe this version of Selenium uses Guava lambdas.
>
> I understand that I need to be explicit and specify whether it is a
> Function or a Predicate. But don't know how to do this with groovy.
>
> So here I may have to explicitly declare a Function with an 'apply' method.
>
> Cannot resolve which method to invoke for [class Fluent$_closure1] due to
> overlapping prototypes between:
> [interface com.google.common.base.Function]
> [interface com.google.common.base.Predicate]
>
>
> ieDriver = new ChromeDriver();
>
> class Fluent{
>
> ChromeDriver ieDriver;
> def application = { wd -> wd.findElement(By.name("q"))}
>
> Fluent( ChromeDriver ieDriver){
> this.ieDriver = ieDriver;
>
> }
>
> public WebElement waitFluently(){
>
> Wait wait = new FluentWait( ieDriver)
> .withTimeout(10, SECONDS )
> .pollingEvery(5, SECONDS)
> .ignoring(NoSuchElementException.class);
> WebElement foo = wait.until(application);
>
> }
> }
> try{
> ieDriver.get("http://www.google.com");
> WebElement element = new
> Fluent(ieDriver).waitFluently(); //driver.findElement(By.name("q"));
> }catch(Exception e) {
> log.info(" Exception " +
> e.getMessage());
> }finally{
> ieDriver.quit();
> }
>
>
> Thanks,
> Mohan
>