kulya / jmeter-gradle-plugin

Other
40 stars 27 forks source link

How to solve specific assertions? #48

Closed staleks closed 6 years ago

staleks commented 9 years ago

Hi,

I want to improve my tests, in a way, to test response, but not just response code but further more to test content of the response.

Response is XML, and I've added XMLAssertion and XPath assertion.

Now when I execute test I am getting this error:

2015/04/17 15:36:58 ERROR - jmeter.threads.JMeterThread: Error processing Assertion  java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at org.apache.xerces.parsers.AbstractDOMParser.startDocument(Unknown Source)
    at org.apache.xerces.impl.dtd.XMLDTDValidator.startDocument(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentScannerImpl.startEntity(Unknown Source)
    at org.apache.xerces.impl.XMLVersionDetector.startDocumentParsing(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
    at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121)
    at org.apache.jmeter.util.XPathUtil.makeDocument(XPathUtil.java:177)
    at org.apache.jmeter.util.XPathUtil.makeDocument(XPathUtil.java:145)
    at org.apache.jmeter.assertions.XPathAssertion.getResult(XPathAssertion.java:103)
    at org.apache.jmeter.threads.JMeterThread.processAssertion(JMeterThread.java:719)
    at org.apache.jmeter.threads.JMeterThread.checkAssertions(JMeterThread.java:690)
    at org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:453)
    at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:261)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: org.w3c.dom.ElementTraversal
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 30 more

Do you maybe know how to overcome this problem ?

Thank You

djangofan commented 9 years ago

If you can't find the way out of this dependency issue, one way to work around it is to create a JSR223 Assertion sampler, set it to use the groovy-all.jar, and then use XMLSlurper from the Groovy package to parse it.

Kulya doesn't add the groovy-all.jar by default, and so you will need to add that dependency. I think it is a basic .jar to add because SoapUI also includes it.

staleks commented 9 years ago

Hi @djangofan,

as I am new to this plugin, maybe I'm missing something from README.md.

How I can add 3rd party library to jmeter-plugin ?

djangofan commented 9 years ago

I have an example here: https://github.com/djangofan/launch-jmeter . Also , click the WIKI link in the main Kulya jmeter-gradle-plugin project for more info.

staleks commented 9 years ago

Today I found a few minutes to try following:

build.gradle file

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.github.kulya:jmeter-gradle-plugin:1.3.4-2.13'
    }

}

apply plugin: 'jmeter'

jmeterRun.configure {
    jmeterTestFiles = [file("src/test/jmeter/ADA-GetDeviceInformation.jmx")]
    jmeterUserPropertiesFiles = [file("src/test/jmeter/user.properties")]
}

task printBuildScriptClasspath << {
    println "\nLoading the following jmeter classpath jars..."
    project.buildscript.configurations.classpath.each {
        String jarName = it.getName();
        print jarName + ":"
    }
    println "\n"
}

When I execute task 'printBuildScriptClasspath', I've noticed that I have:

:printBuildScriptClasspath

Loading the following jmeter classpath jars...
jmeter-gradle-plugin-1.3.4-2.13.jar:
ApacheJMeter_mail-2.13.jar:
ApacheJMeter_monitors-2.13.jar:
ApacheJMeter-2.13.jar:
ApacheJMeter_jdbc-2.13.jar:
ApacheJMeter_ldap-2.13.jar:
ApacheJMeter_config-2.13.jar:
ApacheJMeter_core-2.13.jar:
commons-math3-3.4.1.jar:
bsh-core-2.0b4.jar:
ApacheJMeter_functions-2.13.jar:
ApacheJMeter_ftp-2.13.jar:
commons-pool2-2.3.jar:
ApacheJMeter_http-2.13.jar:
ApacheJMeter_components-2.13.jar:
ApacheJMeter_tcp-2.13.jar:ant-1.8.4.jar:
ApacheJMeter_jms-2.13.jar:
ApacheJMeter_junit-2.13.jar:
ApacheJMeter_java-2.13.jar:
jorphan-2.13.jar:
bsf-2.4.0.jar:
avalon-framework-4.1.4.jar:
bsh-2.0b5.jar:
bcmail-jdk15on-1.49.jar:
bcprov-jdk15on-1.49.jar:
bcpkix-jdk15on-1.49.jar:
commons-codec-1.10.jar:
commons-collections-3.2.1.jar:
commons-httpclient-3.1.jar:
commons-io-2.4.jar:
commons-jexl-1.1.jar:
commons-jexl-2.1.1.jar:
commons-lang3-3.3.2.jar:
commons-logging-1.2.jar:
commons-net-3.3.jar:
dnsjava-2.1.7.jar:
excalibur-datasource-2.1.jar:
excalibur-instrument-1.0.jar:
excalibur-pool-api-2.1.jar:
excalibur-pool-impl-2.1.jar:
excalibur-pool-instrumented-2.1.jar:
htmllexer-2.1.jar:htmlparser-2.1.jar:
httpclient-4.2.6.jar:
httpmime-4.2.6.jar:
httpcore-4.2.5.jar:
oro-2.0.8.jar:
jcharts-0.7.5.jar:
jdom-1.1.3.jar:
rhino-1.7R5.jar:
junit-4.12.jar:
logkit-2.0.jar:
soap-2.3.1.jar:
jtidy-r938.jar:
tika-core-1.7.jar:
tika-parsers-1.7.jar:
xstream-1.4.8.jar:
xmlpull-1.1.3.1.jar:
xpp3_min-1.1.4c.jar:
xalan-2.7.2.jar:
serializer-2.7.2.jar:
xercesImpl-2.11.0.jar:
xmlgraphics-commons-1.5.jar:
mail-1.5.0-b01.jar:
geronimo-jms_1.1_spec-1.1.1.jar:
jsoup-1.8.1.jar:
jodd-core-3.6.4.jar:
jodd-lagarto-3.6.4.jar:
jodd-log-3.6.4.jar:
mongo-java-driver-2.11.3.jar:
rsyntaxtextarea-2.5.6.jar:
slf4j-api-1.7.10.jar:
slf4j-nop-1.7.10.jar:
ant-launcher-1.8.4.jar:
hsqldb-1.8.0.1.jar:
avalon-framework-api-4.3.jar:
avalon-framework-impl-4.3.jar:
avalon-logkit-2.1.jar:
excalibur-instrument-api-2.1.jar:
concurrent-1.3.4.jar:
excalibur-testcase-2.1.jar:
excalibur-component-2.1.jar:
qdox-1.5.jar:
junitperf-1.8.jar:
vorbis-java-tika-0.6.jar:
netcdf-4.2.20.jar:
jmatio-1.0.jar:
apache-mime4j-core-0.7.2.jar:
apache-mime4j-dom-0.7.2.jar:
commons-compress-1.8.1.jar:
xz-1.5.jar:pdfbox-1.8.8.jar:
bcmail-jdk15-1.45.jar:
bcprov-jdk15-1.45.jar:
poi-3.11.jar:
poi-scratchpad-3.11.jar:
poi-ooxml-3.11.jar:
tagsoup-1.2.1.jar:
asm-debug-all-4.1.jar:
isoparser-1.0.2.jar:
metadata-extractor-2.6.2.jar:
boilerpipe-1.1.0.jar:
rome-1.0.jar:
vorbis-java-core-0.6.jar:
juniversalchardet-1.0.3.jar:
jhighlight-1.0.jar:
java-libpst-0.8.1.jar:
activation-1.1.jar:
xmlParserAPIs-2.0.2.jar:
xerces-2.4.0.jar:
log4j-1.2.11.jar:
jmock-1.0.1.jar:
servletapi-2.3.jar:
geronimo-spec-javamail-1.3.1-rc3.jar:
geronimo-spec-jms-1.1-rc4.jar:
excalibur-instrument-mgr-api-2.1.jar:
excalibur-instrument-mgr-impl-2.1.jar:
unidataCommon-4.2.20.jar:
fontbox-1.8.8.jar:
jempbox-1.8.8.jar:
poi-ooxml-schemas-3.11.jar:
aspectjrt-1.8.0.jar:
xmpcore-5.1.2.jar:
jdom-1.0.jar:
servlet-api-2.3.jar:
jcip-annotations-1.0.jar:
xmlbeans-2.6.0.jar:
hamcrest-core-1.3.jar:
excalibur-logger-2.1.jar:
xml-apis-2.0.2.jar:

NOTE: please note that there is: xml-apis-2.0.2.jar

I've downloaded this JAR and there is no ElementTraversal in org.w3.dom

There is such class in one of previous versions of xml-apis like 1.4.01.

Is there a way that I can exclude specific version of 3rd party library in buildscript and include specific version that I will specify ?

Thank You

staleks commented 9 years ago

I was asking for help too early :)

Here is a work arround:

build.gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath ('com.github.kulya:jmeter-gradle-plugin:1.3.4-2.13') {
            exclude group: 'xml-apis'
        }
        classpath 'xml-apis:xml-apis:1.4.01'
    }       
}
staleks commented 9 years ago

From my point of view, this ticket can be closed.