1

I have following yaml for Taurus tests :

- url: 'someURL'
    method: POST
    label: 'SomeLabel'
    headers:
     Content-Type: "application/xml"
     Authorization: "auth"
     remote_user: "someUser"
    body-file: './requests/some.xml'
    assert:
      - contains:
        - 200
        subject: http-code
        regexp: true
    assert-xpath:
      - xpath: "//response//someId[.='00001']"

So when I run these test someId gets returned. Id gets returned according to the data in some.xml. Recently our requirement was to someIds gets returned according to if data is seen in previous requests then someIDs will change, that I don't want. What I want is whenever the tests run one field in xml should change in a way it wasn't seen before, is there something in Taurus to get this requirement.

1 Answers1

0

If you need to extract data from file prior to running a request you can add an extra HTTP Request sampler and use file protocol in order to allow XPath Extractor to fetch "interesting" value from the XML so you will be able to reuse it later on, example Taurus test plan demonstrating the approach will look something like:

scenarios:
  get-value-from-xml:
    requests:
    - url: file:///path/to/requests/some.xml
      extract-xpath:
        someid: //response//someId

execution:
- scenario: get-value-from-xml

You will be able to refer the extracted value as ${someid} where required.

See Taurus JMeter Executor: Requests for more information.


If you need to modify the file you can do it with JSR223 Block, check out below example for details:

scenarios:
  replace-value-in-xml:
    requests:
    - url: http://example.com
      jsr223:
      - language: groovy
        script-text: 'new File("/path/to/requests/some.xml").text = new File("/path/to/requests/some.xml").text.replace("oldId","newId")'
        execute: before
execution:
  - scenario: replace-value-in-xml
Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • I wanted to change the field someID in xml every-time tests are executed, but I do not need that anymore due to some requirement changes. – Saurabh Prajapati Jan 02 '18 at 11:35
  • You can do it with [JSR223 Blocks](http://gettaurus.org/docs/JMeter/#JSR223-Blocks) and [Groovy language](https://www.blazemeter.com/blog/groovy-new-black), see update under the horizontal line for details. – Dmitri T Jan 02 '18 at 12:11