1

I'm using JMeter 2.6, and have the following setup for my test:

-
|-test.jmx
|-myschema.xsd

I've set up an XML Schema Assertion, and typed "myschema.xsd" in the File Name field. Unfortunately, this doesn't work:

HTTP Request
Output schema : error: line=1 col=114 schema_reference.4:
Failed to read schema document 'myschema.xsd', because 
1) could not find the document; 
2) the document could not be read; 
3) the root element of the document is not <xsd:schema>.

I've tried adding several things to the path, including ${__P(user.dir)} (points to the home dir of the user) and ${__BeanShell(pwd())} (doesn't return anything). I got it working by giving the absolute path, but the script is supposed to be used by others, so that's no good.

I could make it use a property value defined in the command line, but I'd like to avoid it as well, for the same reason.

How can I correctly point the Assertion to the schema under these circumstances?

Aliaksandr Belik
  • 12,725
  • 6
  • 64
  • 90
mikołak
  • 9,605
  • 1
  • 48
  • 70

3 Answers3

2

Looks like you have to in this situation

  • validate your xml against xsd manually: simply use corresponding java code from e.g. BeanShell Assertion or BeanShell PostProcessor;
    here is a pretty nice solution: https://stackoverflow.com/a/16054/993246 (as well you can use any other you want for this);
  • dig into jmeter's sources, amend XML Schema file obtaining to support variables in path (File Name field) - like CSV Data Set Config does;
    but the previous way seems to be much easier;
  • run your jmeter test-scenario from shell-script or ant-task which will first copy your xsd to jmeter's /bin dir before script execution - at least XML Schema Assertion can be used "as is".

Perhaps if you will find any other/better - please share it.
Hope this helps.

Community
  • 1
  • 1
Aliaksandr Belik
  • 12,725
  • 6
  • 64
  • 90
  • 3
    Well, I did find another solution by taking your advice and looking into the sources. Whether it's better - that depends on your requirements :). I'll post in a moment, and thanks for the inspiration! – mikołak May 29 '12 at 09:01
2

Summary: in the end I've used http://path.to.schema/myschema.xsd as the File Name parameter in the Assertion.

Explanation: following Alies Belik's advice, I've found that the code for setting up the schema looks something like this:

DocumentBuilderFactory parserFactory = DocumentBuilderFactory.newInstance();
...
parserFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", xsdFileName);

where xsdFileName is a string (the attribute string is actually a constant, I inlined it for readability).

According to e.g. this page, the attribute, when in the form a String, is interpreted as an URI - which includes HTTP URLs. Since I already have the schema accessible through HTTP, I've opted for this solution.

mikołak
  • 9,605
  • 1
  • 48
  • 70
1

Add the 'myschema.xsd' to the \bin directory of your apache-jmeter next to the 'ApacheJMeter.jar' or set the 'File Name' from the 'XML Schema Assertion' to your 'myschema.xsd' from this starting point.

E.g.

JMeter: C:\Users\username\programs\apache-jmeter-2.13\bin\ApacheJMeter.jar

Schema: C:\Users\username\workspace\yourTest\schema\myschema.xsd

File Name: ..\\..\\..\workspace\yourTest\schema\myschema.xsd
Mogsdad
  • 44,709
  • 21
  • 151
  • 275
ronny
  • 11
  • 1