Story Not Found error while running a test using Jbehave Junit - bdd

I have configured my Jbehave test project and has a .story file in the project. I tried using the configuration settings as I found on the internet but when I run the tests, it gives me an error, the stack trace is shown below
org.jbehave.core.io.StoryResourceNotFound: Story path 'D:\AutoRegression8.8\NewProject\src\BusinessCase1.story' not found by class loader sun.misc.Launcher$AppClassLoader#631d75b9
at org.jbehave.core.io.LoadFromClasspath.resourceAsStream(LoadFromClasspath.java:80)
at org.jbehave.core.io.LoadFromClasspath.loadResourceAsText(LoadFromClasspath.java:65)
at org.jbehave.core.io.LoadFromClasspath.loadStoryAsText(LoadFromClasspath.java:74)
at org.jbehave.core.embedder.PerformableTree.storyOfPath(PerformableTree.java:261)
at org.jbehave.core.embedder.StoryManager.storyOfPath(StoryManager.java:61)
at org.jbehave.core.embedder.StoryManager.storiesOf(StoryManager.java:92)
at org.jbehave.core.embedder.StoryManager.runStoriesAsPaths(StoryManager.java:86)
at org.jbehave.core.embedder.Embedder.runStoriesAsPaths(Embedder.java:213)
at org.jbehave.core.junit.JUnitStories.run(JUnitStories.java:20)
at TestRunner.run(TestRunner.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
However, I have my .story file in the same location at which the code tries to find it. To find the .story file, I have used the below code:
#Override
protected List<String> storyPaths() {
/*
* return new StoryFinder().findPaths(
* CodeLocations.codeLocationFromClass(this.getClass()), "**.story",
* "");
*/
String placetoSearch = System.getProperty("user.dir") + "\\src\\BusinessCase1.story";
/*return new StoryFinder().findPaths(CodeLocations.codeLocationFromClass(this.getClass()), placetoSearch, "");*/
return Arrays
.asList(placetoSearch);
}
Any help or reference in this regard would be appreciated.

There's a difference between looking for a file, and looking for a resource.
JBehave uses the classloader you set it up with to look for the story as a resource. A resource is normally part of the packages you're running. That means it needs a filename relative to the root of your classes, rather than an absolute path.
(If you were using myClass.getResource() rather than myClassLoader.getResource() it would be relative to your class.)
You can also use unix-style slashes if you want to. Try "/BusinessCase1.story" as the filename.

Related

Jenkins throwing an error when writing back an xml File

I have a stage on my Jenkins pipeline where I search for a .xml File, open it, change a node and write the changes back to the .xml File. It works fine when I do it on my local machine but it does not work when it is done on Jenkins.
This is the code I'm using:
def inFile = new File('myFile.xml')
def xml = new XmlSlurper(false,false).parse( inFile )
if(xml.repositories.repository.url.toString().contains("string to match") {
xml.repositories.repository.replaceNode {
repository{
id("id")
name("name")
url("url")
}
}
inFile.withWriter { outWriter ->
XmlUtil.serialize(xml, outWriter )
}
}
And Jenkins is showing this error:
java.lang.NoSuchMethodError: No such DSL method 'repository' found among steps[]
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:176)
at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
at groovy.lang.MetaClassImpl.invokeMethodOnGroovyObject(MetaClassImpl.java:1278)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1172)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:20)
at ___cps.transform___(Native Method)
at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:57)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:82)
at sun.reflect.GeneratedMethodAccessor204.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at com.cloudbees.groovy.cps.impl.ClosureBlock.eval(ClosureBlock.java:46)
at com.cloudbees.groovy.cps.Next.step(Next.java:83)
at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:122)
at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:261)
at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$101(SandboxContinuable.java:34)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.lambda$run0$0(SandboxContinuable.java:59)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:58)
at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:174)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:332)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:83)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:244)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:232)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
My xml file looks like this:
...
<repositories>
<repository>
<id>id old</id>
<url>url old</url>
</repository>
</repositories>
...
I have check the imports and have them all correct. I moved the write part to a function and added #NonCPS annotation and nothing changed. I think I'm having a problem with the BufferedWriter but I don't know how to continue on this. Any help is welcome, thank you so much!
I think your problem may not be a BufferedWriter, but more the reading part. The error message No such DSL method 'repository' found among steps points in that direction.
Line four of your code tries to access the XML object repository from your parsed myFile.xml:
if(xml.repositories.repository.url.toString().contains("string to match") {
Dereferencing xml.respositories.repository fails, maybe because the file can not be read or parsed. Can you check in your Groovy code, whether the file exists and is readable?
I'm following up on my comment with an actual solution advice:
No such DSL method 'repository' found among steps points to the fact that Jenkins is trying to interpret your repository as its own method. That could be happening actually on line 8 of your code as everywhere else it's explicitly defined what you're referencing.
So - in order to fix this ambiguity in your code, try this:
Define your repository node variable and then use it within the replaceNode so it's crystal clear to Jenkins what it should do.
Something likes this (you'll probably need it import groovy.util.Node probably too (but I don't know the rest of you pipeline code) + adjust your node attributes according to your needs):
import groovy.util.*
def repository = new Node(null, 'repository', [id:'3'])
xml.repositories.repository.replaceNode {
repository
}
To provide some references and further inspiration (as myself I'm not a groovy master at all):
I think this is the same exact root cause but with different method: How To Use groovy.xml.StreamingMarkupBuilder in Jenkins Pipeline (solution should be analogous)
How to define own XML node within Jenkins, e.g.: groovy create new xml node
The root case lies in CPS mismatch: https://www.jenkins.io/doc/book/pipeline/cps-method-mismatches/)
So the alternative solution (depends on your pipeline code could be also to use #NonCPS annotation). An example covered on a blog (just found on the internet): http://tdongsi.github.io/blog/2017/06/07/groovy-in-jenkinsfile/
groovy.util.Node docs: https://docs.groovy-lang.org/latest/html/api/groovy/util/Node.html

Processing Presto ResultSet in Java: 'SQLException: Not on a valid row'

My Presto plugin has two components:
An EventListener that logs stats of queries made to Presto
Some UDFs for hashing (MD5, SHA1) common datatypes (varchar, long) and returning result as varchar
I've already done:
Integration-test (mvn verify) of query-logging component
Unit-test of hashing UDFs
In integration test of UDF component, I'm tyring to assert value returned by my UDF by firing a query
Connection connection = DriverManager.getConnection(PRESTO_URL, PRESTO_USER, PRESTO_PASSWORD);
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT SHA1(9223372036854775807) AS hash");
assertEquals("458B642B137E2C76E0B746C6FA43E64C3D4C47F1", resultSet.getString("hash"));
This gives following stack-trace (PrestoResultSet.checkValidRow)
NOTE: ExtendedHashFunctionsTestIT.java:39 line is the one containing resultSet.getString(..)
java.sql.SQLException: Not on a valid row
at com.facebook.presto.jdbc.PrestoResultSet.checkValidRow(PrestoResultSet.java:1658)
at com.facebook.presto.jdbc.PrestoResultSet.column(PrestoResultSet.java:1690)
at com.facebook.presto.jdbc.PrestoResultSet.getString(PrestoResultSet.java:370)
at com.company.plugin.it.udfs.scalar.hash.ExtendedHashFunctionsTestIT.testBody(ExtendedHashFunctionsTestIT.java:39)
at com.company.plugin.it.AbstractIntegrationTest.test(AbstractIntegrationTest.java:77)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:774)
at org.testng.TestRunner.run(TestRunner.java:624)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
at org.testng.SuiteRunner.run(SuiteRunner.java:261)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1191)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1116)
at org.testng.TestNG.run(TestNG.java:1024)
at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:62)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:141)
at org.apache.maven.surefire.Surefire.run(Surefire.java:180)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:350)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1021)
I'm perplexed because error occurs only when I try to access ResultSet; commenting out the assertEquals(..) statement lets the test run successfully.
What's even more disturbing is that stack-trace is same for virtually any query:
SELECT 'some_string' AS some_alias
SHOW SCHEMAS
I'm using Spotify's dockerfile-maven-plugin for the tests. I've put up relevant files in this GitHub Gist
ExtendedHashFunctionsTestIT.java (simplified integration-test file)
pom.xml
Dockerfile
It laments me to think that the mistake that ate up my 2 days was this
Connection connection = DriverManager.getConnection(PRESTO_URL, PRESTO_USER, PRESTO_PASSWORD);
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT SHA1(9223372036854775807) AS hash");
resultSet.next();
assertEquals("458B642B137E2C76E0B746C6FA43E64C3D4C47F1", resultSet.getString("hash"));
That 4th line: I had missed resultSet.next() prior to resultSet.getString(..) :-(

Rest Assured Output : print URL

I would like to see which URL Rest assured has constructed for test.
My code is pretty vanilla.
ValidatableResponse response = given().
auth().preemptive().basic("User", "Passwd").
contentType(MediaType.APPLICATION_JSON).
log().all().
when().
get("/ping").
then().
statusCode(200);
But the output is a heck of a stack trace which does not even tell me what was the target URL.
checkServer
"java.lang.AssertionError: 1 expectation failed.
Expected status code <200> doesn't match actual status code <500>.
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrap.callConstructor(ConstructorSite.java:84)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:247)
at com.jayway.restassured.internal.ResponseSpecificationImpl$HamcrestAssertionClosure.validate(ResponseSpecificationImpl.groovy:598)
at com.jayway.restassured.internal.ResponseSpecificationImpl$HamcrestAssertionClosure$validate$1.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 com.jayway.restassured.internal.ResponseSpecificationImpl.validateResponseIfRequired(ResponseSpecificationImpl.groovy:760)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
at com.jayway.restassured.internal.ResponseSpecificationImpl.statusCode(ResponseSpecificationImpl.groovy:120)
at com.jayway.restassured.specification.ResponseSpecification$statusCode$0.callCurrent(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
at com.jayway.restassured.internal.ResponseSpecificationImpl.statusCode(ResponseSpecificationImpl.groovy:128)
at com.jayway.restassured.internal.ValidatableResponseOptionsImpl.statusCode(ValidatableResponseOptionsImpl.java:117)
at org.mystuff.EnvironmentCheck.checkServer(EnvironmentCheck.java:43)
at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:281)
at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:75)
at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:121)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121)
... Removed 31 stack frames
How would I go about that?
It looks like your request is using the default host and port number. From https://github.com/jayway/rest-assured/wiki/Usage#default-values: "By default REST assured assumes host localhost and port 8080 when doing a request."
If you want to actually see what RESTAssured is sending, rather than just inferring, see https://github.com/jayway/rest-assured/wiki/Usage#request-logging, which refers one to http://hc.apache.org/httpcomponents-client-ga/logging.html to see "what's actually sent on the wire." That document, under "Configuration Examples", has different options for enabling HttpClient communications logging.
From that document, the quick solution best suited to your question send to be the "Enable header wire + context logging - Best for Debugging" set of JVM system properties:
-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
-Dorg.apache.commons.logging.simplelog.showdatetime=true
-Dorg.apache.commons.logging.simplelog.log.org.apache.http=DEBUG
-Dorg.apache.commons.logging.simplelog.log.org.apache.http.wire=ERROR`

I tried using AppiumDriver.tap() with parameters but when it execute it throws server side error

org.openqa.selenium.WebDriverException An unknown server-side error occurred while processing the command. (WARNING: The server did not provide any stacktrace information)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:605)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at io.appium.java_client.AppiumDriver.performTouchAction(AppiumDriver.java:297)
at io.appium.java_client.MultiTouchAction.perform(MultiTouchAction.java:74)
at io.appium.java_client.AppiumDriver.tap(AppiumDriver.java:338)
at allpages.General.swipeLeft(General.java:44)
at test.testappandroid.eVerify(testappandroid.java:152)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Try typing adb devices into the console, is the device listed.
For anymore help please can you post your testng.xml, your test script and you grid configurations (if you are using selenium grid).
It seems like you are experiencing this issue
The developers recommend:
Make sure you are in a native view
Use mobile: tap which uses the click() method
If none of this helps it seems as if this is an open bug, keep and eye on the issue thread linked above and to get around this problem try to use the click method instead of tap.
Thanks,
Liam
I found the reason for my problem.
The error for me is because i missed to use "#Test" annotation in my code where i was using swipe function.
thanks

Disabling XML validation in WebHarvest

I have a mobile application already published in the Apple's app store.
This SPI client app uses a Rest API in the server side to retrieve real time information regarding buses arrivals in a specific bus stop.
The app was working like a charm for 6 months.
The Rest API uses WebHarvest to scrap the real data information from a website (for instance: http://www.metlink.org.nz/stop/4912/departures).
Few days ago the HTML page scraped from my server side code has changed by adding the following line:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
Since than, my app has stopped working.
I know I can strip the line above using regExp but I would like to know if there is a way to inform WebHarvest to disable the XML validation. Disabling XML validation, I don't need to go in every configuration that I have and change my xpath expression to a regExp to strip the line above.
Here is my configuration file:
<config charset="UTF-8">
<var-def name="pageContentStr">
<html-to-xml>
<http url="http://www.metlink.org.nz/stop/${stationID.toString()}/departures" />
</html-to-xml>
</var-def>
<var-def name="serverTime">
<xpath expression="/html/body/ul/li/span/text()">
<var name="pageContentStr" />
</xpath>
</var-def>
<var-def name="busRTI">
<xpath expression="//tbody/tr[#data-code]/concat(td[1]/a[starts-with(#href,'timetables/')]/span/text(),'::',td[1]/a[starts-with(#href,'timetables/bus/')]/span/attribute::style,'::',td[2]/span/text(),'::',td[3]/span/text())">
<var name="pageContentStr" />
</xpath>
</var-def>
</config>
The config file inserted above is working fine if I run it inside WebHarvest GUI (weird). However, I receive an error when running it inside my Rest API. Here is the error that I receive:
exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.webharvest.exception.ScraperXPathException: Error parsing XPath expression (XPath = [/html/body/ul/li/span/text()])!
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:948)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause
org.webharvest.exception.ScraperXPathException: Error parsing XPath expression (XPath = [/html/body/ul/li/span/text()])!
org.webharvest.runtime.processors.XPathProcessor.execute(XPathProcessor.java:70)
org.webharvest.runtime.processors.BaseProcessor.run(BaseProcessor.java:115)
org.webharvest.runtime.processors.BodyProcessor.execute(BodyProcessor.java:25)
org.webharvest.runtime.processors.VarDefProcessor.execute(VarDefProcessor.java:59)
org.webharvest.runtime.processors.BaseProcessor.run(BaseProcessor.java:115)
org.webharvest.runtime.Scraper.execute(Scraper.java:166)
org.webharvest.runtime.Scraper.execute(Scraper.java:179)
com.didibaba.services.adapters.metlink.MetLinkAdapterImpl.scrapeBusesForStation(MetLinkAdapterImpl.java:147)
com.didibaba.services.adapters.metlink.MetLinkAdapterImpl.getStationBuses(MetLinkAdapterImpl.java:118)
com.didibaba.services.BusStationServiceImpl.getBusStationInfoByName(BusStationServiceImpl.java:80)
com.didibaba.web.controllers.BusStationController.getBusStationInfo(BusStationController.java:36)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause
net.sf.saxon.trans.XPathException: org.xml.sax.SAXParseExceptionpublicId: -//W3C//DTD HTML 4.0 Transitional//EN; systemId: `http://www.w3.org/TR/REC-html40/loose.dtd`; lineNumber: 31; columnNumber: 3; The declaration for the entity "HTML.Version" must end with '>'.
net.sf.saxon.event.Sender.sendSAXSource(Sender.java:420)
net.sf.saxon.event.Sender.send(Sender.java:169)
net.sf.saxon.Configuration.buildDocument(Configuration.java:3346)
net.sf.saxon.Configuration.buildDocument(Configuration.java:3288)
net.sf.saxon.query.StaticQueryContext.buildDocument(StaticQueryContext.java:327)
org.webharvest.utils.XmlUtil.evaluateXPath(XmlUtil.java:77)
org.webharvest.runtime.processors.XPathProcessor.execute(XPathProcessor.java:68)
org.webharvest.runtime.processors.BaseProcessor.run(BaseProcessor.java:115)
org.webharvest.runtime.processors.BodyProcessor.execute(BodyProcessor.java:25)
org.webharvest.runtime.processors.VarDefProcessor.execute(VarDefProcessor.java:59)
org.webharvest.runtime.processors.BaseProcessor.run(BaseProcessor.java:115)
org.webharvest.runtime.Scraper.execute(Scraper.java:166)
org.webharvest.runtime.Scraper.execute(Scraper.java:179)
com.didibaba.services.adapters.metlink.MetLinkAdapterImpl.scrapeBusesForStation(MetLinkAdapterImpl.java:147)
com.didibaba.services.adapters.metlink.MetLinkAdapterImpl.getStationBuses(MetLinkAdapterImpl.java:118)
com.didibaba.services.BusStationServiceImpl.getBusStationInfoByName(BusStationServiceImpl.java:80)
com.didibaba.web.controllers.BusStationController.getBusStationInfo(BusStationController.java:36)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause
org.xml.sax.SAXParseExceptionpublicId: -//W3C//DTD HTML 4.0 Transitional//EN; systemId: http://www.w3.org/TR/REC-html40/loose.dtd; lineNumber: 31; columnNumber: 3; The declaration for the entity "HTML.Version" must end with '>'.
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:441)
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)
com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1388)
com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.scanEntityDecl(XMLDTDScannerImpl.java:1562)
com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.scanDecls(XMLDTDScannerImpl.java:1964)
com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.scanDTDExternalSubset(XMLDTDScannerImpl.java:297)
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(XMLDocumentScannerImpl.java:1162)
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(XMLDocumentScannerImpl.java:1049)
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:962)
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:607)
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:116)
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:489)
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:835)
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1210)
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:568)
net.sf.saxon.event.Sender.sendSAXSource(Sender.java:396)
net.sf.saxon.event.Sender.send(Sender.java:169)
net.sf.saxon.Configuration.buildDocument(Configuration.java:3346)
net.sf.saxon.Configuration.buildDocument(Configuration.java:3288)
net.sf.saxon.query.StaticQueryContext.buildDocument(StaticQueryContext.java:327)
org.webharvest.utils.XmlUtil.evaluateXPath(XmlUtil.java:77)
org.webharvest.runtime.processors.XPathProcessor.execute(XPathProcessor.java:68)
org.webharvest.runtime.processors.BaseProcessor.run(BaseProcessor.java:115)
org.webharvest.runtime.processors.BodyProcessor.execute(BodyProcessor.java:25)
org.webharvest.runtime.processors.VarDefProcessor.execute(VarDefProcessor.java:59)
org.webharvest.runtime.processors.BaseProcessor.run(BaseProcessor.java:115)
org.webharvest.runtime.Scraper.execute(Scraper.java:166)
org.webharvest.runtime.Scraper.execute(Scraper.java:179)
com.didibaba.services.adapters.metlink.MetLinkAdapterImpl.scrapeBusesForStation(MetLinkAdapterImpl.java:147)
com.didibaba.services.adapters.metlink.MetLinkAdapterImpl.getStationBuses(MetLinkAdapterImpl.java:118)
com.didibaba.services.BusStationServiceImpl.getBusStationInfoByName(BusStationServiceImpl.java:80)
com.didibaba.web.controllers.BusStationController.getBusStationInfo(BusStationController.java:36)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
Thanks in advance.
you could try using a omithtmlenvelope="true" in your html-to-xml call.
<var-def name="pageContentStr">
<html-to-xml omithtmlenvelope="true">
<http url="http://www.metlink.org.nz/stop/${stationID.toString()}/departures" />
</html-to-xml>
</var-def>
However, unfortunately, as you said I cannot reproduce the error you are getting, and cannot test the result...
Had a similar issue with the xpath evaluator throwing an org.xml.sax.SAXParseException
White spaces are required between publicId and systemId.
When you can change the origin xml, the solution for this problem is already solved here.
Webharvest uses html cleaner under the hood. I use the Complete Web-Harvest project and so could prevent adding the doctype-tag on the html-to-xml.
I use html cleaner version 2.6.1., and modified org.webharvest.runtime.processors.HtmlToXmlProcessor to support this newer version
HtmlCleaner cleaner = new HtmlCleaner( );
CleanerProperties cleanerProperties = cleaner.getProperties();
As html cleaner supports an omitDoctypeDeclaration - parameter ommiting the doctype at all, I added that (in future that might be done via an extra attribute with the scraper xml).
cleanerProperties.setOmitDoctypeDeclaration(true);
Hope it helps, and thanks to the creator of webharvest, it is a great and pretty reliable tool!

Resources