Can't go through circuit in groovy

I am trying to run a basic example for the Geb library (http://www.gebish.org/manual/current/intro.html#introduction). Here is the code:

import geb.Browser Browser.drive { go "http://google.com/ncr" // make sure we actually got to the page assert title == "Google" // enter wikipedia into the search field $("input", name: "q").value("wikipedia") // wait for the change to results page to happen // (google updates the page dynamically without a new request) waitFor { title.endsWith("Google Search") } // is the first link to wikipedia? def firstLink = $("li.g", 0).find("al") assert firstLink.text() == "Wikipedia" // click the link firstLink.click() // wait for Google javascript to redirect to Wikipedia waitFor { title == "Wikipedia" } } 

When I try to run this (using Eclipse groovy support), I get the following exception:

 Caught: groovy.lang.MissingMethodException: No signature of method: static geb.Browser.drive() is applicable for argument types: (ExampleScript$_run_closure1) values: [ ExampleScript$_run_closure1@2a62610b ] Possible solutions: drive(groovy.lang.Closure), drive(geb.Browser, groovy.lang.Closure), drive(geb.Configuration, groovy.lang.Closure), drive(java.util.Map, groovy.lang.Closure), print(java.lang.Object), print(java.io.PrintWriter) groovy.lang.MissingMethodException: No signature of method: static geb.Browser.drive() is applicable for argument types: (ExampleScript$_run_closure1) values: [ ExampleScript$_run_closure1@2a62610b ] Possible solutions: drive(groovy.lang.Closure), drive(geb.Browser, groovy.lang.Closure), drive(geb.Configuration, groovy.lang.Closure), drive(java.util.Map, groovy.lang.Closure), print(java.lang.Object), print(java.io.PrintWriter) at ExampleScript.run(ExampleScript.groovy:21) 

I think this suggests that the closure I pass to the static groovy.lang.Closure method is not compatible with the groovy.lang.Closure type, but I don’t know why. Simple groovy hello world scripts work fine, but passing a closure to a method always returns a similar error.

+4
source share
1 answer

Plagiarism from: http://groovy.codehaus.org/Differences+from+Java

Java programmers are used for terminating statements with semicolons and have no closures. Class definitions also have instance initializers. So you can see something like:

 class Trial { private final Thing thing = new Thing ( ) ; { thing.doSomething ( ) ; } } 

Many Groovy programmers avoid using semicolons as distracting and redundant (although others use them all the time - it's a coding style issue). The situation that leads to the difficulties lies in writing above in Groovy as:

 class Trial { private final thing = new Thing ( ) { thing.doSomething ( ) } } 

This will throw a MissingMethodException!

+2
source

Source: https://habr.com/ru/post/1401465/


All Articles