Re: Executing dynamic DSL command

2018-01-17 Thread Mohan Radhakrishnan
I've been reading the older posts and this code which constructs a closure
works.

It evalutes this line of code.

bootStrap '//*[@id=\"pane\"]'

public Object runInContext(Object context, String script, GroovyShell
shell) {
Closure cl = (Closure) shell.evaluate("{->"  + script  + "}");
cl.setDelegate(context);
cl.setResolveStrategy(Closure.DELEGATE_FIRST);
return cl.call();
}

Thanks,

Mohan


On 16 January 2018 at 19:35, Mohan Radhakrishnan <
radhakrishnan.mo...@gmail.com> wrote:

> I mean that this works if the DSL command is hard-coded. I was trying to
> pass it into the shell.
>
> Am I allowed to pass it into the shell ? This evaluation is generic for
> many such fluent commands.
>
> def evaluatexpath( String dsl ){
> def binding = new Binding(
> dxp: new DynamicXPath(),
> DslCommand: dsl
> )
>
> def shell = new GroovyShell(this.class.classLoader, binding)
>
> shell.evaluate '''
> @BaseScript(com.automation.script.AxesBaseScript)
> import groovy.transform.BaseScript
>     bootStrap "//*[@id='pane']"
> '''
> }
>
> Mohan
>
>
> On 16 January 2018 at 19:06, Mohan Radhakrishnan <
> radhakrishnan.mo...@gmail.com> wrote:
>
>> Hi,
>>
>>   I am reading the book 'Groovy in Action' and this code is based on
>> that.
>>
>> My base script stores 'DynamicXPath' like this.
>>
>> abstract class AxesBaseScript extends Script {
>>
>> public DynamicXPath bootStrap(String initialPath ){
>> this.binding.dxp.bootStrap initialPath
>> }
>> }
>>
>> And here I want to execute a dynamic DSL command 'dsl '
>>
>> by storing it in the binding as 'DslCommand'.
>>
>> def evaluatexpath( String dsl ){
>> def binding = new Binding(
>> dsp: new DynamicXPath(),
>> DslCommand: dsl
>> )
>>
>> def shell = new GroovyShell(this.class.classLoader, binding)
>>
>> shell.evaluate '''
>> @BaseScript(com.automation.script.AxesBaseScript)
>> import groovy.transform.BaseScript
>> DslCommand
>> '''
>> }
>>
>> Looks like the DSL string I pass 'bootStrap somestring' is returned as
>> it is as a string by evaluate.
>>
>> Can I not execute 'bootStrap somestring' ?
>>
>> The relevant section in the book is '*Listing 19.12 Using a custom base
>> script class'*
>>
>> *My '*DslCommand' replaces 'move left' which you see at the end of the
>> listing.
>> I just want to pass my DSL commands to the evaluate method as parameters
>> through the binding.
>>
>>
>> Thanks,
>> Mohan
>>
>
>


Re: Executing dynamic DSL command

2018-01-16 Thread Mohan Radhakrishnan
I mean that this works if the DSL command is hard-coded. I was trying to
pass it into the shell.

Am I allowed to pass it into the shell ? This evaluation is generic for
many such fluent commands.

def evaluatexpath( String dsl ){
def binding = new Binding(
dxp: new DynamicXPath(),
DslCommand: dsl
)

def shell = new GroovyShell(this.class.classLoader, binding)

shell.evaluate '''
@BaseScript(com.automation.script.AxesBaseScript)
import groovy.transform.BaseScript
bootStrap "//*[@id='pane']"
'''
}

Mohan


On 16 January 2018 at 19:06, Mohan Radhakrishnan <
radhakrishnan.mo...@gmail.com> wrote:

> Hi,
>
>   I am reading the book 'Groovy in Action' and this code is based on
> that.
>
> My base script stores 'DynamicXPath' like this.
>
> abstract class AxesBaseScript extends Script {
>
> public DynamicXPath bootStrap(String initialPath ){
> this.binding.dxp.bootStrap initialPath
> }
> }
>
> And here I want to execute a dynamic DSL command 'dsl '
>
> by storing it in the binding as 'DslCommand'.
>
> def evaluatexpath( String dsl ){
> def binding = new Binding(
> dsp: new DynamicXPath(),
> DslCommand: dsl
> )
>
> def shell = new GroovyShell(this.class.classLoader, binding)
>
> shell.evaluate '''
> @BaseScript(com.automation.script.AxesBaseScript)
> import groovy.transform.BaseScript
> DslCommand
> '''
> }
>
> Looks like the DSL string I pass 'bootStrap somestring' is returned as it
> is as a string by evaluate.
>
> Can I not execute 'bootStrap somestring' ?
>
> The relevant section in the book is '*Listing 19.12 Using a custom base
> script class'*
>
> *My '*DslCommand' replaces 'move left' which you see at the end of the
> listing.
> I just want to pass my DSL commands to the evaluate method as parameters
> through the binding.
>
>
> Thanks,
> Mohan
>


Executing dynamic DSL command

2018-01-16 Thread Mohan Radhakrishnan
Hi,

  I am reading the book 'Groovy in Action' and this code is based on
that.

My base script stores 'DynamicXPath' like this.

abstract class AxesBaseScript extends Script {

public DynamicXPath bootStrap(String initialPath ){
this.binding.dxp.bootStrap initialPath
}
}

And here I want to execute a dynamic DSL command 'dsl '

by storing it in the binding as 'DslCommand'.

def evaluatexpath( String dsl ){
def binding = new Binding(
dsp: new DynamicXPath(),
DslCommand: dsl
)

def shell = new GroovyShell(this.class.classLoader, binding)

shell.evaluate '''
@BaseScript(com.automation.script.AxesBaseScript)
import groovy.transform.BaseScript
DslCommand
'''
}

Looks like the DSL string I pass 'bootStrap somestring' is returned as it
is as a string by evaluate.

Can I not execute 'bootStrap somestring' ?

The relevant section in the book is '*Listing 19.12 Using a custom base
script class'*

*My '*DslCommand' replaces 'move left' which you see at the end of the
listing.
I just want to pass my DSL commands to the evaluate method as parameters
through the binding.


Thanks,
Mohan


DSL Recommendation

2018-01-10 Thread Mohan Radhakrishnan
Hi,
 I didn't know Groovy DSL's could be almost like plain english as shown
in
http://docs.groovy-lang.org/docs/latest/html/documentation/core-domain-
specific-languages.html

Is that the latest recommendation ?  My use case is this.

I would like to create a small library to create XPath axes(
https://www.w3schools.com/xml/xpath_axes.asp) using a DSL.

Something like this.

id of ancestor of descendant of Node

This is just to create a more flexible way of using XPath expressions. I
don't plan to completely implement all expressions. Just a few.

Thanks,
Mohan


Re: Catch clause difference

2018-01-10 Thread Mohan Radhakrishnan
Yes Jochen. That worked.

import org.openqa.selenium.NoSuchElementException

I hadn;t imported anything.

Mohan

On 9 January 2018 at 22:58, Jochen Theodorou <blackd...@gmx.org> wrote:

>
>
> Am 09.01.2018 um 16:38 schrieb Dinko Srkoč:
>
>> On 9 January 2018 at 13:26, Mohan Radhakrishnan
>> <radhakrishnan.mo...@gmail.com> wrote:
>>
>>> I don't see java.util.NoSuchElementException anywhere.
>>>
>>
>>  From the line:
>>
>>  }catch( NoSuchElementException nse ){
>>
>> we don't know which `NoSuchElementException` you're trying to catch
>> (see what is imported), but we do know that the thrown exception is
>> `org.openqa.selenium.NoSuchElementException`.
>>
>> The conclusion is:
>>
>> a) the `NoSuchElementException` in the catch clause shown above is not
>> `org.openqa.selenium.NoSuchElementException`, or
>> b) as Felix noted, different class loaders are being used
>>
>
> if there is no "import org.openqa.selenium.NoSuchElementException" or
> "import org.openqa.selenium.*", then (a) has an extremely high probability
>
> bye Jochen
>


Re: Catch clause difference

2018-01-09 Thread Mohan Radhakrishnan
I don't see java.util.NoSuchElementException anywhere.


Mohan

On 9 January 2018 at 15:05, Felix Dorner <felix.dor...@gmail.com> wrote:

> Or the same exception class but  different classloader? Either of these
> two.
>
> On Jan 9, 2018 10:01, "Dinko Srkoč" <dinko.sr...@gmail.com> wrote:
>
>> Is your `NoSuchElementException` in the catch clause by any chance
>> `java.util.NoSuchElementException`?
>>
>> cheers,
>> Dinko
>>
>> On 8 January 2018 at 16:18, Mohan Radhakrishnan
>> <radhakrishnan.mo...@gmail.com> wrote:
>> > In the second case it is this.
>> >
>> > org.openqa.selenium.NoSuchElementException
>> >
>> > In the first case this seems to escape out.
>> >
>> > So I changed my first clause to this.
>> >
>> > }catch( NoSuchElementException nse ){
>> > print "Catch clause " + nse
>> > }catch( Exception e ){
>> > print "Catch clause " + e
>> > }
>> >
>> > It prints org.openqa.selenium.NoSuchElementException if I catch
>> 'Exception'.
>> >
>> > Does this have anything to do with the 'closure' shown in this trace ?
>> >
>> >   at
>> > com.automation.pages.PageObjectLayer$_waitUntil_closure2.
>> doCall(PageObjectLayer.groovy:39)
>> >   at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.
>> java:208)
>> >   at
>> > com.automation.pages.PageObjectLayer.waitUntil(PageObjectLay
>> er.groovy:39)
>> >   at
>> > com.automation.page.test.WidgetTest.waitUntilNoSuchWidgetExc
>> eptionWithMessage(WidgetTest.groovy:54)
>> >
>> > Thanks.
>> >
>> > On 8 January 2018 at 19:28, Paul King <pa...@asert.com.au> wrote:
>> >>
>> >> What does printing out `nse` in both cases show?
>> >>
>> >> On Mon, Jan 8, 2018 at 11:02 PM, Mohan Radhakrishnan
>> >> <radhakrishnan.mo...@gmail.com> wrote:
>> >>>
>> >>> Hello,
>> >>>
>> >>> These catch clauses are somehow different from each other. Why  ?
>> >>>
>> >>> In the first case 'NoSuchElementException' is somehow escaping the
>> >>> 'catch' block. My test fails.
>> >>>
>> >>> But the second clause succeeds as expected.
>> >>>
>> >>> Clause 1 :
>> >>>
>> >>> catch( NoSuchElementException nse ){
>> >>>
>> >>> throw new NoSuchWidgetException( " Element " + by.toString() + "
>> not
>> >>> found" +
>> >>>  " after polling for [" +
>> >>> pollingInterval.longValue() +
>> >>>  "] with timeout set to [" +
>> >>> timeOut.longValue() );
>> >>> }
>> >>>
>> >>>
>> >>> Clause 2 :
>> >>>
>> >>> try{
>> >>> WaitForWidget wait =
>> >>> new WaitForWidget(wd).
>> >>>
>> >>> pollingEvery(pollingInterval.longValue(),unit).
>> >>> withTimeout(timeOut.longValue(),unit).
>> >>> withMessage(supplierClosure)
>> >>>
>> >>> wait.until( {  wd.findElement( by )} as Function )
>> >>> }catch(  nse ){
>> >>> throw new NoSuchWidgetException( " Element " + by.toString() + "
>> not
>> >>> found" +
>> >>>  " after polling for [" +
>> >>> pollingInterval.longValue() +
>> >>>  "] with timeout set to [" +
>> >>> timeOut.longValue() );
>> >>> }
>> >>>
>> >>> Thanks,
>> >>> Mohan
>> >>
>> >>
>> >
>>
>


Re: Catch clause difference

2018-01-08 Thread Mohan Radhakrishnan
In the second case it is this.

org.openqa.selenium.NoSuchElementException

In the first case this seems to escape out.

So I changed my first clause to this.

}catch( NoSuchElementException nse ){
print "Catch clause " + nse
}catch( Exception e ){
print "Catch clause " + e
}

It prints org.openqa.selenium.NoSuchElementException if I catch 'Exception'.

Does this have anything to do with the 'closure' shown in this trace ?

at
com.automation.pages.PageObjectLayer$_waitUntil_closure2.doCall(PageObjectLayer.groovy:39)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:208) at
com.automation.pages.PageObjectLayer.waitUntil(PageObjectLayer.groovy:39)
at
com.automation.page.test.WidgetTest.waitUntilNoSuchWidgetExceptionWithMessage(WidgetTest.groovy:54)

Thanks.

On 8 January 2018 at 19:28, Paul King <pa...@asert.com.au> wrote:

> What does printing out `nse` in both cases show?
>
> On Mon, Jan 8, 2018 at 11:02 PM, Mohan Radhakrishnan <
> radhakrishnan.mo...@gmail.com> wrote:
>
>> Hello,
>>
>> These catch clauses are somehow different from each other. Why  ?
>>
>> In the first case 'NoSuchElementException' is somehow escaping the
>> 'catch' block. My test fails.
>>
>> But the second clause succeeds as expected.
>>
>> Clause 1 :
>>
>> catch( NoSuchElementException nse ){
>>
>> throw new NoSuchWidgetException( " Element " + by.toString() + " not 
>> found" +
>>  " after polling for [" + 
>> pollingInterval.longValue() +
>>  "] with timeout set to [" + 
>> timeOut.longValue() );
>> }
>>
>>
>> Clause 2 :
>>
>> try{
>> WaitForWidget wait =
>> new WaitForWidget(wd).
>> pollingEvery(pollingInterval.longValue(),unit).
>> withTimeout(timeOut.longValue(),unit).
>> withMessage(supplierClosure)
>>
>> wait.until( {  wd.findElement( by )} as Function )
>> }catch(  nse ){
>> throw new NoSuchWidgetException( " Element " + by.toString() + " not 
>> found" +
>>  " after polling for [" + 
>> pollingInterval.longValue() +
>>  "] with timeout set to [" + 
>> timeOut.longValue() );
>> }
>>
>> Thanks,
>> Mohan
>>
>
>


Catch clause difference

2018-01-08 Thread Mohan Radhakrishnan
Hello,

These catch clauses are somehow different from each other. Why  ?

In the first case 'NoSuchElementException' is somehow escaping the 'catch'
block. My test fails.

But the second clause succeeds as expected.

Clause 1 :

catch( NoSuchElementException nse ){

throw new NoSuchWidgetException( " Element " + by.toString() + "
not found" +
 " after polling for [" +
pollingInterval.longValue() +
 "] with timeout set to [" +
timeOut.longValue() );
}


Clause 2 :

try{
WaitForWidget wait =
new WaitForWidget(wd).
pollingEvery(pollingInterval.longValue(),unit).
withTimeout(timeOut.longValue(),unit).
withMessage(supplierClosure)

wait.until( {  wd.findElement( by )} as Function )
}catch(  nse ){
throw new NoSuchWidgetException( " Element " + by.toString() + "
not found" +
 " after polling for [" +
pollingInterval.longValue() +
 "] with timeout set to [" +
timeOut.longValue() );
}

Thanks,
Mohan


Re: Unknown type: METHOD_DEF

2018-01-08 Thread Mohan Radhakrishnan
I couldn't understand the reason as I my Groovy exp. is less.

But this Maven configuration fixed it.


org.codehaus.gmavenplus
gmavenplus-plugin
1.6



addSources
addTestSources
compile
compileTests






Thanks,

Mohan


On 8 January 2018 at 09:14, Mohan Radhakrishnan <
radhakrishnan.mo...@gmail.com> wrote:

> Hi Keith,
>
> The error when I run Maven test is this.
>
> [ERROR] Failed to execute goal org.codehaus.gmaven:gmaven-
> plugin:1.2:generateStu
> bs (default) on project Automation: startup failed:
> [ERROR] /D:/Development_Avecto/Automation/src/main/groovy/
> com/automation/pages/t
> ime/ThreadSleeper.groovy: 11: Unknown type: METHOD_DEF at line: 11 column:
> 5. Fi
> le: /D:/Development_Avecto/Automation/src/main/groovy/
> com/automation/pages/time/
> ThreadSleeper.groovy @ line 11, column 5.
> [ERROR] def  sleeperWithAction() {
> [ERROR] ^
> [ERROR]
> [ERROR] 1 error
>
> But when I execute a test like this from Intellij it passes.
>
> @Test( expected = SleepInterruptedException.class )
> def void interruptedTest() {
>
> Thread.currentThread().interrupt()
> def sleeper = new AutomationSleeper( ms : 10)
> sleeper.sleeper()
> }
>
> I am handling InterruptedException because some Selenium code calls sleep 
> everywhere.
>
> And the calling code isn't prepared to be interrupted. Moreover there is no 
> descriptive
>
> message about what the thread is sleeping on. I plan to add some messages so 
> that code that
>
> calls my 'sleeper' will atleast have messages. The closure could help too.
>
> Even selenium source code has this section probably because that framework 
> isn't required to deal with
>
> 'InterruptedException'. It is a web scraping tool.
>
>
> try {
> Thread.sleep(50);
>   } catch (InterruptedException e) {
> throw new RuntimeException( e);
>   }
>
>
>
> Thanks,
> Mohan
>
> On 6 January 2018 at 03:47, Keith Suderman <suder...@anc.org> wrote:
>
>> What error are you seeing?  Do you see the error at runtime or in your
>> IDE?  Your code works for me (Groovy 2.4.9) so maybe check for unbalanced
>> braces elsewhere in your code.
>>
>> However, you shouldn't catch/rethrow the InterruptedException as you do.
>> The InterruptedException is not thrown for "some reason", it is thrown when
>> another thread calls Thread.interrupt() on your thread (e.g. to wake your
>> thread up so it can check its state).  For example:
>>
>> Thread t = Thread.start {
>> boolean running = true
>> while (running) {
>> doSomeWork()
>> try {
>> Thread.sleep(1000)
>> }
>> catch (InterruptedException e) {
>> running = shouldIKeepRunning()
>> return true
>> }
>> }
>> }
>> // At program shutdown/cleanup
>> t.interrupt()
>> t.join()
>> println "Our thread has termintated."
>>
>>
>> The Closure passed to the Thread.sleep method can be used in place of the
>> try/catch block.  That is the closure will be called when
>> Thread.interrupt() is called on your thread i.e.:
>>
>> Thread t = Thread.start {
>> boolean running = false
>> while(running) {
>> doSomeWork()
>> Thread.sleep(1000) {
>> // Called then Thread.sleep() is interrupted.
>> running = false
>> return true
>> }
>> }
>> }
>> // ...
>> t.interrupt()
>> t.join()
>>
>>
>> Finally, if you are doing complicated threading work you should really be
>> using GPars or Java's Executors, ThreadPools, et al.
>>
>> Cheers,
>> Keith
>>
>> On Jan 5, 2018, at 11:01 AM, Mohan Radhakrishnan <
>> radhakrishnan.mo...@gmail.com> wrote:
>>
>>
>>
>>
>> Hi,
>>
>>  I am new to groovy. Here I tried to create
>>
>> a simple wrapper around 'sleep'.
>>
>> I see the error in the subject at 'def'. What's wrong ?
>>
>> Thanks,
>>
>> Mohan
>>
>> /**
>>  * Our custom sleep logic.
>>  */
>> trait ThreadSleeper {
>>  long ms
>>  Closure cl = {}
>>
>> /*Sleep with an action taken*/
>> def  sleeperWithAction() {
>> try{
>>
>> Thread.sleep ms, cl
>>
>> }catch( InterruptedException ie ){
>> throw new SleepInterruptedException( ie, "Thread.sleep is 
>> interrupted for "+
>>   "some reason [" + 
>> ie.getMessage() +"]");
>> }
>> }
>>
>>
>> /*If there is no action to be taken then we call this*/
>> def  sleeper() {
>> try{
>>
>> Thread.sleep ms
>>
>> }catch( InterruptedException ie ){
>> throw new SleepInterruptedException( ie, "Thread.sleep is 
>> interrupted for "+
>>  "some reason [" + 
>> ie.getMessage() +"]");
>> }
>> }
>> }
>>
>>
>> --
>> Keith Suderman
>> Research Associate
>> Department of Computer Science
>> Vassar College, Poughkeepsie NY
>> suder...@cs.vassar.edu
>>
>>
>>
>>
>>
>


Re: Unknown type: METHOD_DEF

2018-01-07 Thread Mohan Radhakrishnan
Hi Keith,

The error when I run Maven test is this.

[ERROR] Failed to execute goal
org.codehaus.gmaven:gmaven-plugin:1.2:generateStu
bs (default) on project Automation: startup failed:
[ERROR]
/D:/Development_Avecto/Automation/src/main/groovy/com/automation/pages/t
ime/ThreadSleeper.groovy: 11: Unknown type: METHOD_DEF at line: 11 column:
5. Fi
le:
/D:/Development_Avecto/Automation/src/main/groovy/com/automation/pages/time/
ThreadSleeper.groovy @ line 11, column 5.
[ERROR] def  sleeperWithAction() {
[ERROR] ^
[ERROR]
[ERROR] 1 error

But when I execute a test like this from Intellij it passes.

@Test( expected = SleepInterruptedException.class )
def void interruptedTest() {

Thread.currentThread().interrupt()
def sleeper = new AutomationSleeper( ms : 10)
sleeper.sleeper()
}

I am handling InterruptedException because some Selenium code calls
sleep everywhere.

And the calling code isn't prepared to be interrupted. Moreover there
is no descriptive

message about what the thread is sleeping on. I plan to add some
messages so that code that

calls my 'sleeper' will atleast have messages. The closure could help too.

Even selenium source code has this section probably because that
framework isn't required to deal with

'InterruptedException'. It is a web scraping tool.


try {
Thread.sleep(50);
  } catch (InterruptedException e) {
throw new RuntimeException( e);
  }



Thanks,
Mohan

On 6 January 2018 at 03:47, Keith Suderman <suder...@anc.org> wrote:

> What error are you seeing?  Do you see the error at runtime or in your
> IDE?  Your code works for me (Groovy 2.4.9) so maybe check for unbalanced
> braces elsewhere in your code.
>
> However, you shouldn't catch/rethrow the InterruptedException as you do.
> The InterruptedException is not thrown for "some reason", it is thrown when
> another thread calls Thread.interrupt() on your thread (e.g. to wake your
> thread up so it can check its state).  For example:
>
> Thread t = Thread.start {
> boolean running = true
> while (running) {
> doSomeWork()
> try {
> Thread.sleep(1000)
> }
> catch (InterruptedException e) {
> running = shouldIKeepRunning()
> return true
> }
> }
> }
> // At program shutdown/cleanup
> t.interrupt()
> t.join()
> println "Our thread has termintated."
>
>
> The Closure passed to the Thread.sleep method can be used in place of the
> try/catch block.  That is the closure will be called when
> Thread.interrupt() is called on your thread i.e.:
>
> Thread t = Thread.start {
> boolean running = false
> while(running) {
> doSomeWork()
> Thread.sleep(1000) {
> // Called then Thread.sleep() is interrupted.
> running = false
> return true
> }
> }
> }
> // ...
> t.interrupt()
> t.join()
>
>
> Finally, if you are doing complicated threading work you should really be
> using GPars or Java's Executors, ThreadPools, et al.
>
> Cheers,
> Keith
>
> On Jan 5, 2018, at 11:01 AM, Mohan Radhakrishnan <
> radhakrishnan.mo...@gmail.com> wrote:
>
>
>
>
> Hi,
>
>  I am new to groovy. Here I tried to create
>
> a simple wrapper around 'sleep'.
>
> I see the error in the subject at 'def'. What's wrong ?
>
> Thanks,
>
> Mohan
>
> /**
>  * Our custom sleep logic.
>  */
> trait ThreadSleeper {
>  long ms
>  Closure cl = {}
>
> /*Sleep with an action taken*/
> def  sleeperWithAction() {
> try{
>
> Thread.sleep ms, cl
>
> }catch( InterruptedException ie ){
> throw new SleepInterruptedException( ie, "Thread.sleep is 
> interrupted for "+
>   "some reason [" + 
> ie.getMessage() +"]");
> }
> }
>
>
> /*If there is no action to be taken then we call this*/
> def  sleeper() {
> try{
>
> Thread.sleep ms
>
> }catch( InterruptedException ie ){
> throw new SleepInterruptedException( ie, "Thread.sleep is 
> interrupted for "+
>  "some reason [" + 
> ie.getMessage() +"]");
> }
> }
> }
>
>
> --
> Keith Suderman
> Research Associate
> Department of Computer Science
> Vassar College, Poughkeepsie NY
> suder...@cs.vassar.edu
>
>
>
>
>


Unknown type: METHOD_DEF

2018-01-05 Thread Mohan Radhakrishnan
Hi,

 I am new to groovy. Here I tried to create

a simple wrapper around 'sleep'.

I see the error in the subject at 'def'. What's wrong ?

Thanks,

Mohan

/**
 * Our custom sleep logic.
 */
trait ThreadSleeper {
 long ms
 Closure cl = {}

/*Sleep with an action taken*/
def  sleeperWithAction() {
try{

Thread.sleep ms, cl

}catch( InterruptedException ie ){
throw new SleepInterruptedException( ie, "Thread.sleep is
interrupted for "+
  "some reason ["
+ ie.getMessage() +"]");
}
}


/*If there is no action to be taken then we call this*/
def  sleeper() {
try{

Thread.sleep ms

}catch( InterruptedException ie ){
throw new SleepInterruptedException( ie, "Thread.sleep is
interrupted for "+
 "some reason [" +
ie.getMessage() +"]");
}
}
}


Re: Groovy code with Function or Predicate

2017-12-11 Thread Mohan Radhakrishnan
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.mo...@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
>


Groovy code with Function or Predicate

2017-12-11 Thread Mohan Radhakrishnan
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