Geb - IncompatibleClassChangeError - java

I'm just starting out with Geb and am encountering this error when inputting sample code from the Book of Geb:
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("a.l")
assert firstLink.text() == "Wikipedia"
// click the link
firstLink.click()
// wait for Google's javascript to redirect to Wikipedia
waitFor { title == "Wikipedia" }
}
I am encountering this exception:
Caught: java.lang.IncompatibleClassChangeError: the number of constructors during runtime and compile time for java.lang.Exception do not match. Expected 4 but got 5
at geb.error.GebException.<init>(GebException.groovy:20)
at geb.waiting.WaitTimeoutException.<init>(WaitTimeoutException.groovy:30)
at geb.waiting.Wait.waitFor(Wait.groovy:108)
.......
Any ideas? Thanks!

Are you using Java 7 by any chance? Groovy code that uses exceptions that was compiled with < Java 7 is not compatible with Java 7.

Geb is compatible with Java7 as of 0.7.1. If you are below that you should upgrade. SEe: http://jira.codehaus.org/browse/GEB-194

Related

Online Kotlin Compiler: Exception in thread "main" java.lang.NumberFormatException: null [duplicate]

The following code :
fun main(args: Array<String>) {
print("Write anything here: ")
val enteredString = readLine()
println("You have entered this: $enteredString")
}
gives the following error in KotlinPlayground :
Write anything here: You have entered this: null
Here, the user doesn't get an opportunity to enter input. After the initial print statement gets executed, the compiler is not waiting for the user to give input and skips to the next print statement. Why is it happening? I have tried the same in several other online Kotlin compilers but I am getting the same error.
There's no error. readLine just returns null (because Kotlin Playground doesn't have a console to read from), and it's printed as expected.
E.g. on https://ideone.com/ you can say what to use for input and it'll print that line (though its Kotlin version is pretty old).
Because Kotlin playground have no user input console and this is not an error. For user input you can either use https://ideone.com/ or
https://www.jdoodle.com/compile-kotlin-online/
I will recommend you to use the second on which is jdoodle. It is pretty much faster to run and read user input and almost use the latest version of Kotlin and JRE.
And if you like to play (run) with command line argument then it will good for you with jdoodle.
This can be done in Kotlin Playground by using JS as the destination platform - click on the JVM dropdown (top left, to the right of the kotlin version) and change to JS.
Now you can call JavaScript - only using constant strings, e.g.
fun main() {
val name = js("prompt('Please enter your name', 'Bob')")
println("Hello $name")
}
For another example, using a common function, see https://pl.kotl.in/MkhfYNS47
Note: if you try this:
fun promptName(default: String = "") {
return js("prompt('Please enter your name', '$default')")
}
You will get a compilation error - Argument must be string constant.
Note that JS IR as an option ran much slower and had an issue with default type needing to be stated for the linked code

Getting "cannot activate web view"

I received an error. When I did a google search, I got some results but they were all for Android programming. I am automating a test using Windows, Java 1.8 and Selenium.
The error
org.openqa.selenium.WebDriverException: unknown error: cannot activate web view
My original code (that I did not write but am debugging and has worked):
// Clicks a link which opens a new window
action.moveToElement(el).click(el).build().perform();
Set<String> windows = driver.getWindowHandles();
for (String a: windows) {
Reporter.log(a);
driver.switchTo().window(a);
}
The error I got was that there was "no such window". So I thought maybe I needed to wait until the number of windows stabilized, so I added the following after clicking and before doing the windows stuff:
int winds = driver.getWindowHandles().size();
int owinds = winds - 1;
while (owinds != winds) {
Thread.sleep(1000);
owinds = winds;
winds = driver.getWindowHandles().size();
}
It is at this point, where it does the switch, that I get the
org.openqa.selenium.WebDriverException: unknown error: cannot activate web view
and as I mentioned before, everything in Google only talks about Android, which this is not.
Any thoughts would be welcome.
I had this problem in JavaScript using Webdriver.io. I'm answering since it had the same characteristics described here, specifically that I was opening a new tab and I'd get this error.
I first added more memory/resources to my docker container and then got an issue that was resolved by this answer: https://stackoverflow.com/a/52340526/491553.
Once I applied the following Chrome arguments, I didn't see this again:
"--no-sandbox",
"--disable-infobars", // https://stackoverflow.com/a/43840128/1689770
"--disable-dev-shm-usage", // https://stackoverflow.com/a/50725918/1689770
"--disable-browser-side-navigation", // https://stackoverflow.com/a/49123152/1689770
"--disable-gpu", // https://stackoverflow.com/questions/51959986/how-to-solve-selenium-chromedriver-timed-out-receiving-message-from-renderer-exc
"--disable-features=VizDisplayCompositor" // https://stackoverflow.com/a/55371396/491553

Groovy Postbuild in Jenkins, parsing the log for strings and counting them

I am new to Groovy and am trying to set up a postbuild in Jenkins that allows me to count strings and determine if the build succeeded by how many the count returns at the end.
Here is my example code :
class Main {
def manager = binding.getVariable("manager")
def log = manager.build.logFile.text
def list = log
def JobCount = list.count {it.startsWith("====") && it.contains("COMPLETE")}
if (JobCount == 7) {
manager.listener.logger.println("All Jobs Completed Successfully")
} else {
manager.addWarningBadge("Not All Jobs Have Completed Successfully")
manager.buildUnstable()
}
}
I am looking for a specific string that gets printed to the console when the test has completed successfully. The string is "====JOB COMPLETE====" and I should have 7 instances of this string if all 7 tests passed correctly.
Currently when I run this code I get the following error :
Script1.groovy: 6: unexpected token: if # line 6, column 5.
if (JobCount == 7)
^
Any help would be greatly appreciated
manager.build.logFile.text returns the whole file text as String.
What you need is readLines():
def list = manager.build.logFile.readLines()
def JobCount = list.count {it.startsWith("====") && it.contains("COMPLETE")}
and of course as mentioned below, the Jenkins Groovy Postbuild plugin runs Groovy scripts, so you will have get rid of the enclosing class declaration (Main)
You have statements directly inside your class, without being in a method, which is not allowed in Java/Groovy. Since this is Groovy, you can run this as a script without the class at all, or put the offending code (the if statement) inside a method and call the method.
Perhaps you're missing a closing }
def JobCount = list.count {it.startsWith("====") && it.contains("COMPLETE")}

Incoparable Java Types boolean and object

I have this piece of code which worked in Java 6
if(false==sess.getAttribute("admin") || null==sess.getAttribute("admin"))
{
res.sendRedirect("/myapp/login.jsp?errmsg=You must log in as an administrator to manage resources");
return;
}
I want to familiarize myself with the new features of Java 7 and what it offers new in javaee hence I upgraded netbeans to 7.4 and jdk 7u45.
My project opened successfully however the file with this code is marked as a java class with an error by netbeans. Running the project I get the error
java.lang.RuntimeException: Uncompilable source code - incomparable types: boolean and java.lang.Object
What I want to ask is why this worked in java6 and doesn't work in java7
FYI HttpSession sess = req.getSession();
HttpSession.getAttribute returns an Object.
Change the line to (Boolean.FALSE==sess.getAtrribute)
Looks like autoboxing (boolean to Boolean) has changed in Java.
Unfortunately I cannot reproduce your error. I have seen a similar error message in the same Netbeans 7.4/jdk 7u45.
My code:
if (true == evt.getNewValue())
(where evt is a PropertyChangeEvent)
The message in Netbeans (when I hover over the red cross left to the statement) says "incomparable types: boolean and Object". Notice the difference with your message: the missing "java/lang" before Object.
And even stranger: my code compiles without any problem.
Compiler options in Netbeans are: "-version -Xlint:unchecked -Xlint:deprecation"
You should try with
if(false==(Boolean)sess.getAttribute("admin") || null==sess.getAttribute("admin"))
{
res.sendRedirect("/myapp/login.jsp?errmsg=You must log in as an administrator to manage resources");
return;
}
getAttribute probably returns either an Object or a boolean. If it returns a boolean, then null==getAttrubute will not work and if it returns an Object then false==getAttribute will fail.

Htmlunit ScriptException "console" is not defined

I am using htmlunit 2.9 and on java script parsing I am getting script exception due to console in following exception
function debug(o){
if (console && console.log){
console.log(o)
}
};
Stacktrace
EcmaError:
lineNumber=[168]
column=[0]
lineSource=[null]
name=[ReferenceError]
sourceName=[script in http://localhost:808/mypage/ll.html from (154, 36) to (301, 14)]
message=[ReferenceError: "console" is not defined. (script in http://localhost:8080.com/mypage/ll.html from (154, 36) to (301, 14)#168)]
com.gargoylesoftware.htmlunit.ScriptException: ReferenceError: "console" is not defined. (script in http://localhost:8080.com/mypage/ll.html from (154, 36) to (301, 14)#168)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:595)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:537)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:538)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:545)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:520)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:896)
at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventHandler(EventListenersContainer.java:195)
at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:214)
if I try specified page on firefox it works fine, I have tried v 3.6 as well as 9.0.1.
i have tried also to set setThrowExceptionOnScriptError(false) in order to avoid exception but engine stops or do not parse javascript after getting an error.
Is there any way that javascript engine can understand console in javascript?
Your if condition isn't properly structured:
if (console && console.log){
That first if will throw an error if its not set; accessing console in environments its not defined in is like accessing any undefined variable; it will throw a ReferenceError.
Try:
if( typeof console != "undefined" && console.log ) {
Or:
if(window.console && console.log) {
It doesn't throw in error in Firefox since Firefox implements the Firebug API, as do Chrome and Safari. But, by default, Internet Explorer does not, so, it's worth doing a proper feature check here, as it will throw a ReferenceError in browsers that don't implement this API.
https://sourceforge.net/tracker/index.php?func=detail&aid=3518475&group_id=47038&atid=448266 implies that support for console was just added to HtmlUnit.
Your code does use the java script console object, and it's not supported till the current version, and it is promised to be supported in the next release as it is said here

Categories