Take Screenshot using AShot and Watir - ruby

I am trying to use AShot with Selenium to take a screenshot.
require 'selenium/webdriver'
require 'javalib/ashot-1.5.4.jar'
driver_path = 'C:\ProgramData\chocolatey\lib\chromedriver\tools\chromedriver.exe'
Selenium::WebDriver::Chrome::Service.driver_path = driver_path
base_url = 'https://www.google.com/'
driver = Selenium::WebDriver.for :chrome
driver.navigate.to base_url
ashot = Java::RuYandexQatoolsAshot::AShot.new
png = ashot.takeScreenshot(driver)
test_pod_name = 'c:\data\google_screenshot.png'
File.write(test_pod_name, png)
puts "Writing to: #{test_pod_name}"
driver.close
But I am getting this error message:
Unhandled Java exception: java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
getDeclaredMethods0 at java/lang/Class.java:-2
privateGetDeclaredMethods at java/lang/Class.java:2729
getDeclaredMethods at java/lang/Class.java:2003
computeValue at org/jruby/javasupport/binding/Initializer.java:467
computeValue at org/jruby/javasupport/binding/Initializer.java:464
getFromHashMap at java/lang/ClassValue.java:227
getFromBackup at java/lang/ClassValue.java:209
get at java/lang/ClassValue.java:115
getMethods at org/jruby/javasupport/binding/Initializer.java:498
setupClassMethods at org/jruby/javasupport/binding/ClassInitializer.java:116
initialize at org/jruby/javasupport/binding/ClassInitializer.java:31
setupProxyClass at org/jruby/javasupport/binding/Initializer.java:100
createProxyClass at org/jruby/javasupport/Java.java:528
generateClassProxy at org/jruby/javasupport/Java.java:486
createProxyClassForClass at org/jruby/javasupport/Java.java:442
computeValue at org/jruby/javasupport/JavaSupportImpl.java:126
computeValue at org/jruby/javasupport/JavaSupportImpl.java:118
get at org/jruby/util/collections/MapBasedClassValue.java:25
getProxyClassFromCache at org/jruby/javasupport/JavaSupportImpl.java:199
getProxyClass at org/jruby/javasupport/Java.java:409
getProxyClass at org/jruby/javasupport/Java.java:402
getProxyClassOrNull at org/jruby/javasupport/Java.java:976
getProxyClassOrNull at org/jruby/javasupport/Java.java:927
getProxyOrPackageUnderPackage at org/jruby/javasupport/Java.java:885
relativeJavaClassOrPackage at org/jruby/javasupport/JavaPackage.java:188
const_missing at org/jruby/javasupport/JavaPackage.java:127
call at org/jruby/javasupport/JavaPackage$INVOKER$i$1$0$const_missing.gen:-1
finvoke at org/jruby/RubyClass.java:909
invoke at org/jruby/runtime/Helpers.java:442
callMethod at org/jruby/RubyBasicObject.java:363
searchModuleForConst at org/jruby/ir/targets/ConstantLookupSite.java:133
<main> at C:/src/energyflow/exdb/data/netlogix/scripts/google-screenshot-selenium.rb:12
invokeWithArguments at java/lang/invoke/MethodHandle.java:627
load at org/jruby/ir/Compiler.java:94
runScript at org/jruby/Ruby.java:830
runNormally at org/jruby/Ruby.java:749
runNormally at org/jruby/Ruby.java:767
runFromMain at org/jruby/Ruby.java:580
doRunFromMain at org/jruby/Main.java:417
internalRun at org/jruby/Main.java:305
run at org/jruby/Main.java:232
main at org/jruby/Main.java:204
Caused by:
java.lang.ClassNotFoundException: org.openqa.selenium.WebDriver
findClass at java/net/URLClassLoader.java:382
loadClass at java/lang/ClassLoader.java:418
loadClass at java/lang/ClassLoader.java:351
getDeclaredMethods0 at java/lang/Class.java:-2
privateGetDeclaredMethods at java/lang/Class.java:2729
getDeclaredMethods at java/lang/Class.java:2003
computeValue at org/jruby/javasupport/binding/Initializer.java:467
computeValue at org/jruby/javasupport/binding/Initializer.java:464
getFromHashMap at java/lang/ClassValue.java:227
getFromBackup at java/lang/ClassValue.java:209
get at java/lang/ClassValue.java:115
getMethods at org/jruby/javasupport/binding/Initializer.java:498
setupClassMethods at org/jruby/javasupport/binding/ClassInitializer.java:116
initialize at org/jruby/javasupport/binding/ClassInitializer.java:31
setupProxyClass at org/jruby/javasupport/binding/Initializer.java:100
createProxyClass at org/jruby/javasupport/Java.java:528
generateClassProxy at org/jruby/javasupport/Java.java:486
createProxyClassForClass at org/jruby/javasupport/Java.java:442
computeValue at org/jruby/javasupport/JavaSupportImpl.java:126
computeValue at org/jruby/javasupport/JavaSupportImpl.java:118
get at org/jruby/util/collections/MapBasedClassValue.java:25
getProxyClassFromCache at org/jruby/javasupport/JavaSupportImpl.java:199
getProxyClass at org/jruby/javasupport/Java.java:409
getProxyClass at org/jruby/javasupport/Java.java:402
getProxyClassOrNull at org/jruby/javasupport/Java.java:976
getProxyClassOrNull at org/jruby/javasupport/Java.java:927
getProxyOrPackageUnderPackage at org/jruby/javasupport/Java.java:885
relativeJavaClassOrPackage at org/jruby/javasupport/JavaPackage.java:188
const_missing at org/jruby/javasupport/JavaPackage.java:127
call at org/jruby/javasupport/JavaPackage$INVOKER$i$1$0$const_missing.gen:-1
finvoke at org/jruby/RubyClass.java:909
invoke at org/jruby/runtime/Helpers.java:442
callMethod at org/jruby/RubyBasicObject.java:363
searchModuleForConst at org/jruby/ir/targets/ConstantLookupSite.java:133
<main> at C:/src/energyflow/exdb/data/netlogix/scripts/google-screenshot-selenium.rb:12
invokeWithArguments at java/lang/invoke/MethodHandle.java:627
load at org/jruby/ir/Compiler.java:94
runScript at org/jruby/Ruby.java:830
runNormally at org/jruby/Ruby.java:749
runNormally at org/jruby/Ruby.java:767
runFromMain at org/jruby/Ruby.java:580
doRunFromMain at org/jruby/Main.java:417
internalRun at org/jruby/Main.java:305
run at org/jruby/Main.java:232
main at org/jruby/Main.java:204
It's funny that the error dump doesn't refer to AShot - but the error originates from the line instatiating AShot.

There is an open method in Selenium-webdriver method for capturing screenshots. You can use something like
#driver.save_screenshot('c:\data\google_screenshot.png')

Related

Cannot compile Spring Boot to native image with Python language support

I'm trying to build a native image (GraalVM 22.3) from a Spring Boot 3 RC1 application with Python language support on Apple M1. I can build the native image without Python language support. But when adding
<buildArgs combine.children="append">
<buildArg>--verbose</buildArg>
<buildArg>--language:python</buildArg>
<buildArg>-Dorg.graalvm.launcher.relative.python.home=${env.JAVA_HOME}/languages/python</buildArg>
<buildArg>-Dorg.graalvm.launcher.relative.llvm.home=${env.JAVA_HOME}/languages/llvm</buildArg>
</buildArgs>
without any polyglot code in the application, the build throws errors during the "Parsing methods" step. The error message is not always the same. It differs randomly (from my point of view):
[4/7] Parsing methods... [****] (17.8s # 4.40GB)
Fatal error: org.graalvm.compiler.java.BytecodeParser$BytecodeParserError: com.oracle.svm.core.util.VMError$HostedError: Discovered an unresolved callee while parsing org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:128).
at parsing org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:128)
at method: RequestAttributes org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes()
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.throwParserError(BytecodeParser.java:2518)
at com.oracle.svm.hosted.phases.SharedGraphBuilderPhase$SharedBytecodeParser.throwParserError(SharedGraphBuilderPhase.java:110)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.iterateBytecodesForBlock(BytecodeParser.java:3393)
at com.oracle.svm.hosted.phases.HostedBytecodeParser.iterateBytecodesForBlock(HostedGraphBuilderPhase.java:201)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.handleBytecodeBlock(BytecodeParser.java:3345)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.processBlock(BytecodeParser.java:3190)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.build(BytecodeParser.java:1138)
at com.oracle.svm.hosted.phases.HostedBytecodeParser.build(HostedGraphBuilderPhase.java:144)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.buildRootMethod(BytecodeParser.java:1030)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.GraphBuilderPhase$Instance.run(GraphBuilderPhase.java:97)
at com.oracle.svm.hosted.phases.SharedGraphBuilderPhase.run(SharedGraphBuilderPhase.java:84)
at jdk.internal.vm.compiler/org.graalvm.compiler.phases.Phase.run(Phase.java:49)
at jdk.internal.vm.compiler/org.graalvm.compiler.phases.BasePhase.apply(BasePhase.java:446)
at jdk.internal.vm.compiler/org.graalvm.compiler.phases.Phase.apply(Phase.java:42)
at jdk.internal.vm.compiler/org.graalvm.compiler.phases.Phase.apply(Phase.java:38)
at com.oracle.svm.hosted.code.CompileQueue.defaultParseFunction(CompileQueue.java:1145)
at com.oracle.svm.hosted.code.CompileQueue.doParse(CompileQueue.java:857)
at com.oracle.svm.hosted.code.CompileQueue$ParseTask.run(CompileQueue.java:386)
at com.oracle.graal.pointsto.util.CompletionExecutor.executeCommand(CompletionExecutor.java:193)
at com.oracle.graal.pointsto.util.CompletionExecutor.lambda$executeService$0(CompletionExecutor.java:177)
at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1395)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
at java.base/java.util.concurrent.ForkJoinPool.externalHelpQuiescePool(ForkJoinPool.java:2104)
at java.base/java.util.concurrent.ForkJoinPool.awaitQuiescence(ForkJoinPool.java:3321)
at com.oracle.graal.pointsto.util.CompletionExecutor.complete(CompletionExecutor.java:243)
at com.oracle.svm.hosted.code.CompileQueue.parseAll(CompileQueue.java:594)
at com.oracle.svm.hosted.code.CompileQueue.finish(CompileQueue.java:424)
at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:651)
at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:535)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:403)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:580)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:128)
at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:610)
Caused by: com.oracle.svm.core.util.VMError$HostedError: Discovered an unresolved callee while parsing org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:128).
at com.oracle.svm.core.util.VMError.shouldNotReachHere(VMError.java:68)
at com.oracle.svm.hosted.phases.SharedGraphBuilderPhase$SharedBytecodeParser.lookupMethodInPool(SharedGraphBuilderPhase.java:140)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.lookupMethod(BytecodeParser.java:4206)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.genInvokeStatic(BytecodeParser.java:1648)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.processBytecode(BytecodeParser.java:5288)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.iterateBytecodesForBlock(BytecodeParser.java:3385)
... 30 more
Other error message:
[4/7] Parsing methods... [****] (19.9s # 2.51GB)
2 fatal errors detected:
Fatal error: org.graalvm.compiler.java.BytecodeParser$BytecodeParserError: java.lang.NullPointerException: Cannot invoke "jdk.vm.ci.meta.JavaType.toJavaName()" because "type" is null
at parsing org.springframework.format.support.DefaultFormattingConversionService.addDefaultFormatters(DefaultFormattingConversionService.java:110)
at method: void org.springframework.format.support.DefaultFormattingConversionService.addDefaultFormatters(FormatterRegistry)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.throwParserError(BytecodeParser.java:2518)
at com.oracle.svm.hosted.phases.SharedGraphBuilderPhase$SharedBytecodeParser.throwParserError(SharedGraphBuilderPhase.java:110)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.iterateBytecodesForBlock(BytecodeParser.java:3393)
at com.oracle.svm.hosted.phases.HostedBytecodeParser.iterateBytecodesForBlock(HostedGraphBuilderPhase.java:201)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.handleBytecodeBlock(BytecodeParser.java:3345)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.processBlock(BytecodeParser.java:3190)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.build(BytecodeParser.java:1138)
at com.oracle.svm.hosted.phases.HostedBytecodeParser.build(HostedGraphBuilderPhase.java:144)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.buildRootMethod(BytecodeParser.java:1030)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.GraphBuilderPhase$Instance.run(GraphBuilderPhase.java:97)
at com.oracle.svm.hosted.phases.SharedGraphBuilderPhase.run(SharedGraphBuilderPhase.java:84)
at jdk.internal.vm.compiler/org.graalvm.compiler.phases.Phase.run(Phase.java:49)
at jdk.internal.vm.compiler/org.graalvm.compiler.phases.BasePhase.apply(BasePhase.java:446)
at jdk.internal.vm.compiler/org.graalvm.compiler.phases.Phase.apply(Phase.java:42)
at jdk.internal.vm.compiler/org.graalvm.compiler.phases.Phase.apply(Phase.java:38)
at com.oracle.svm.hosted.code.CompileQueue.defaultParseFunction(CompileQueue.java:1145)
at com.oracle.svm.hosted.code.CompileQueue.doParse(CompileQueue.java:857)
at com.oracle.svm.hosted.code.CompileQueue$ParseTask.run(CompileQueue.java:386)
at com.oracle.graal.pointsto.util.CompletionExecutor.executeCommand(CompletionExecutor.java:193)
at com.oracle.graal.pointsto.util.CompletionExecutor.lambda$executeService$0(CompletionExecutor.java:177)
at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1395)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
Caused by: java.lang.NullPointerException: Cannot invoke "jdk.vm.ci.meta.JavaType.toJavaName()" because "type" is null
at com.oracle.svm.hosted.phases.SharedGraphBuilderPhase$SharedBytecodeParser.handleUnresolvedType(SharedGraphBuilderPhase.java:290)
at com.oracle.svm.hosted.phases.SharedGraphBuilderPhase$SharedBytecodeParser.handleUnresolvedNewInstance(SharedGraphBuilderPhase.java:204)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.genNewInstance(BytecodeParser.java:4501)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.genNewInstance(BytecodeParser.java:4494)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.processBytecode(BytecodeParser.java:5291)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.iterateBytecodesForBlock(BytecodeParser.java:3385)
... 23 more
Fatal error: org.graalvm.compiler.java.BytecodeParser$BytecodeParserError: java.lang.NullPointerException: Cannot invoke "jdk.vm.ci.meta.JavaType.toJavaName()" because "type" is null
at parsing org.springframework.boot.autoconfigure.web.format.WebConversionService.addFormatters(WebConversionService.java:70)
at method: void org.springframework.boot.autoconfigure.web.format.WebConversionService.addFormatters(DateTimeFormatters)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.throwParserError(BytecodeParser.java:2518)
at com.oracle.svm.hosted.phases.SharedGraphBuilderPhase$SharedBytecodeParser.throwParserError(SharedGraphBuilderPhase.java:110)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.iterateBytecodesForBlock(BytecodeParser.java:3393)
at com.oracle.svm.hosted.phases.HostedBytecodeParser.iterateBytecodesForBlock(HostedGraphBuilderPhase.java:201)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.handleBytecodeBlock(BytecodeParser.java:3345)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.processBlock(BytecodeParser.java:3190)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.build(BytecodeParser.java:1138)
at com.oracle.svm.hosted.phases.HostedBytecodeParser.build(HostedGraphBuilderPhase.java:144)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.buildRootMethod(BytecodeParser.java:1030)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.GraphBuilderPhase$Instance.run(GraphBuilderPhase.java:97)
at com.oracle.svm.hosted.phases.SharedGraphBuilderPhase.run(SharedGraphBuilderPhase.java:84)
at jdk.internal.vm.compiler/org.graalvm.compiler.phases.Phase.run(Phase.java:49)
at jdk.internal.vm.compiler/org.graalvm.compiler.phases.BasePhase.apply(BasePhase.java:446)
at jdk.internal.vm.compiler/org.graalvm.compiler.phases.Phase.apply(Phase.java:42)
at jdk.internal.vm.compiler/org.graalvm.compiler.phases.Phase.apply(Phase.java:38)
at com.oracle.svm.hosted.code.CompileQueue.defaultParseFunction(CompileQueue.java:1145)
at com.oracle.svm.hosted.code.CompileQueue.doParse(CompileQueue.java:857)
at com.oracle.svm.hosted.code.CompileQueue$ParseTask.run(CompileQueue.java:386)
at com.oracle.graal.pointsto.util.CompletionExecutor.executeCommand(CompletionExecutor.java:193)
at com.oracle.graal.pointsto.util.CompletionExecutor.lambda$executeService$0(CompletionExecutor.java:177)
at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1395)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
Caused by: java.lang.NullPointerException: Cannot invoke "jdk.vm.ci.meta.JavaType.toJavaName()" because "type" is null
at com.oracle.svm.hosted.phases.SharedGraphBuilderPhase$SharedBytecodeParser.handleUnresolvedType(SharedGraphBuilderPhase.java:290)
at com.oracle.svm.hosted.phases.SharedGraphBuilderPhase$SharedBytecodeParser.handleUnresolvedNewInstance(SharedGraphBuilderPhase.java:204)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.genNewInstance(BytecodeParser.java:4501)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.genNewInstance(BytecodeParser.java:4494)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.processBytecode(BytecodeParser.java:5291)
at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.iterateBytecodesForBlock(BytecodeParser.java:3385)
... 23 more
This is a known bug, tracked here: https://github.com/oracle/graal/issues/4473

Getting error after entering a value in a text box in karate UI via Firefox

This issue is only when I invoke the scripts via firefox driver, after entering value in a text box getting an error and test is failing
configure driver = {type:'geckodriver' , executable:'C:\Users\dinesh\Downloads\geckodriver-v0.31.0-win64\geckodriver.exe'}
driver 'https://courses.ultimateqa.com/users/sign_in'
screenshot()
driver.maximize()
input("//*[#id='user[email]']","abc#gmail.com")
Error message
* input("//*[#id='user[first_name]']", 'welcome')
js failed:
>>>>
01: input("//*[#id='user[first_name]']", 'welcome')
<<<<
org.graalvm.polyglot.PolyglotException: Expected to find an object with property ['message'] in path $['value'] but found 'null'. This is not a json object according to the JsonProvider: 'com.jayway.jsonpath.spi.json.JsonSmartJsonProvider'.
- com.jayway.jsonpath.internal.path.PropertyPathToken.evaluate(PropertyPathToken.java:71)
- com.jayway.jsonpath.internal.path.PathToken.handleObjectProperty(PathToken.java:81)
- com.jayway.jsonpath.internal.path.PropertyPathToken.evaluate(PropertyPathToken.java:79)
- com.jayway.jsonpath.internal.path.RootPathToken.evaluate(RootPathToken.java:62)
- com.jayway.jsonpath.internal.path.CompiledPath.evaluate(CompiledPath.java:99)
- com.jayway.jsonpath.internal.path.CompiledPath.evaluate(CompiledPath.java:107)
- com.jayway.jsonpath.JsonPath.read(JsonPath.java:185)
Please help me the xpath is right, karate is writing the value in text box but after that it is failing
For me this code works, both with chromedriver and geckodriver. Of course these executables must be set in the PATH environment variable.
I added also the waitFor method to wait for the web element.
Feature: sample karate test script
for help, see: https://github.com/intuit/karate/wiki/IDE-Support
Background:
#* configure driver = { type: 'chromedriver', executable: 'chromedriver' }
* configure driver = { type: 'geckodriver', executable: 'geckodriver' }
#* def sleep = function(pause){ java.lang.Thread.sleep(pause) }
Scenario: test error
Given driver 'https://courses.ultimateqa.com/users/sign_in'
When waitFor("//*[#id='user[email]']").input('abc#gmail.com')
And waitFor("//*[#id='user[password]']").input('qwerty1234')
And waitFor("//input[#type='submit']").click()
* screenshot()
#* call sleep 3000

Getting Content is not allowed in prolog when running in Java

I am facing Content is not allowed in prolog exception when I run my xxx.jmx file from Java (Jmeter 5.0).
I tested the jmx in the GUI mode and everything works fine and in the Java I am just following the standard way to call the jmx file and execute it.
The jmx just have some normal stuff. Sending HTTP request and validate the expected and received XML (I am using this snipped to validate):
import org.apache.commons.io.FileUtils
expect = FileUtils.readFileToString(new File('some_path'))
XmlParser parser = new XmlParser()
expectedXML = new XmlSlurper().parseText(expect)
actualXML = new XmlSlurper().parseText(prev.getResponseDataAsString())
if (expectedXML != actualXML) {
AssertionResult.setFailure(true)
AssertionResult.setFailureMessage('Mismatch between expected and actual XML \n'+ prev.getResponseDataAsString())
and the stack trace:
2018/10/24 15:18:03,386 12675 [ERROR ] [Thread Group 1-1] (JSR223Assertion.java:52) – Problem in JSR223 script: Validate resposne
javax.script.ScriptException: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:320)
at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:72)
at javax.script.CompiledScript.eval(CompiledScript.java:92)
at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:221)
at org.apache.jmeter.assertions.JSR223Assertion.getResult(JSR223Assertion.java:49)
at org.apache.jmeter.threads.JMeterThread.processAssertion(JMeterThread.java:901)
at org.apache.jmeter.threads.JMeterThread.checkAssertions(JMeterThread.java:892)
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:565)
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:486)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:253)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at groovy.util.XmlSlurper.parse(XmlSlurper.java:207)
at groovy.util.XmlSlurper.parse(XmlSlurper.java:260)
at groovy.util.XmlSlurper.parseText(XmlSlurper.java:286)
at groovy.util.XmlSlurper$parseText.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at Script1.run(Script1.groovy:9)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:317)
... 10 more
UPDATE 1:
The problem of using Response Assertion is it cannot ignore the space or tab. So if the format is not exactly the same when I use equal will always fail. Any ideas how to ignore these things by using Response Assertion?
UPDATE 2:
I found out that the issue is not related to the BOM. Is becasue if I run the jmx from my Java application:
prev.getResponseDataAsString()
above function always return:
${__FileToString(${inputFilePath},,)}
but not the actual response. This function is come from the body data of the HTTP Request sampler!!!!!! If I give the acutal body there then I am able to run the jmx...... Any idea how to deal with this dynamic body data?
It might be the case your "expected" XML file contains BOM and it causes your code failure.
BOM is basically 3 first bytes so you can remove them using code like:
def expect = FileUtils.readFileToString(new File('some_path')).getBytes().flatten()
1.upto(3) {
expect.remove(0)
}
XmlParser parser = new XmlParser()
def expectedXML = parser.parseText(new String(expect.toArray(new Byte[0])))
The rest of your code should work fine.
Check out The Groovy Templates Cheat Sheet for JMeter article to learn more Groovy tips and tricks.
Also be informed that in majority of cases it's easier to use Response Assertion or when it comes to XML - XPath Assertion, Java code will work faster than Groovy in any case.

Smooks failed to filter source - java.lang.NoSuchMethodError: sun.misc.Unsafe.defineClass(Ljava/lang/String;[BII)Ljava/lang/Class

I am relatively new to EDIFACT/D96A. I am trying to convert from edi using the D96AInterchangeFactory.
Here is what i have:
D96AInterchangeFactory factory = D96AInterchangeFactory.getInstance();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(ediContent.getBytes());
UNEdifactInterchange interchange = factory.fromUNEdifact(byteArrayInputStream);
on this I get the following error:
org.milyn.SmooksException: Failed to filter source.
at org.milyn.delivery.sax.SmooksSAXFilter.doFilter(SmooksSAXFilter.java:97)
at org.milyn.delivery.sax.SmooksSAXFilter.doFilter(SmooksSAXFilter.java:64)
at org.milyn.Smooks._filter(Smooks.java:526)
at org.milyn.Smooks.filterSource(Smooks.java:482)
at .
.
.
org.milyn.smooks.edi.unedifact.UNEdifactReader.parse(UNEdifactReader.java:75)
at org.milyn.delivery.sax.SAXParser.parse(SAXParser.java:76)
at org.milyn.delivery.sax.SmooksSAXFilter.doFilter(SmooksSAXFilter.java:86)
... 22 more
Caused by: java.lang.NoSuchMethodError: sun.misc.Unsafe.defineClass(Ljava/lang/String;[BII)Ljava/lang/Class;
at
. .
org.milyn.javabean.BeanInstanceCreator.createAndSetBean(BeanInstanceCreator.java:296)
at org.milyn.javabean.BeanInstanceCreator.visitBefore(BeanInstanceCreator.java:241)
at org.milyn.delivery.sax.SAXHandler.visitBefore(SAXHandler.java:307)
... 40 more
I read and also added a dependency in d96a for mvel2 and version 2.2.0.Final. Still the same error pops up.
Using JAVA 8
What might i be doing wrong?
Thanking you in advance.
I fixed the same error by using mvel2 2.3.1.Final.
Bumped up the mylin dependency from 1.6 to 1.7.0
works now

CQ 5.6.1 getWorkflowSession cause Uncaught Throwable java.lang.NullPointerException

at com.cuso.Mao.doGet(Mao.java:97)
at org.apache.sling.api.servlets.SlingSafeMethodsServlet.mayService(SlingSafeMethodsServlet.java:268)
at org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:344)
at org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:375)
at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:508)
at org.apache.sling.engine.impl.filter.SlingComponentFilterChain.render(SlingComponentFilterChain.java:45)
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:64)
at com.day.cq.wcm.core.impl.WCMDebugFilter.doFilter(WCMDebugFilter.java:146)
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
at com.day.cq.wcm.core.impl.WCMComponentFilter.filterRootInclude(WCMComponentFilter.java:356)
at com.day.cq.wcm.core.impl.WCMComponentFilter.doFilter(WCMComponentFilter.java:168)
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
at com.day.cq.personalization.impl.TargetComponentFilter.doFilter(TargetComponentFilter.java:96)
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
at org.apache.sling.engine.impl.SlingRequestProcessorImpl.processComponent(SlingRequestProcessorImpl.java:254)
line 97 is just calling the WorkflowSession wf = workflowServiceObject.getWorkflowSession(jcrsessionObject);
Should I use JACKRABBIT SESSION instead of jcrSession? Which one is right?
I was facing a similar situation.There is nothing wrong with the model node that you are passing.
Getting new workflowSession from workflowService was giving nullpointer so I had to get the workflowService inside my Activator using the getServiceReference way and have it assigned to a static variable in a utility class.Still I got:
and following was getting logged:-
Cannot read workflow model from node: /etc/workflow/models/deletecontent/jcr:content/model
And there was one more "session already closed" issue. For that I again made the resolverFactory a part of my utility class using which I could get administrativeResourceResolver in my servlet.

Resources