Ajinkya Pisal
Ajinkya Pisal

Reputation: 591

how to create response assertion in ruby-jmeter

I am using ruby-jmeter to create jmeter plan. So far I have gone thorught various DSL given at https://github.com/flood-io/ruby-jmeter/blob/master/lib/ruby-jmeter/DSL.md

But I am not understanding how to use reponse assertion DSL. https://github.com/flood-io/ruby-jmeter/blob/master/lib/ruby-jmeter/dsl/response_assertion.rb

def initialize(params={})
      testname = params.kind_of?(Array) ? 'ResponseAssertion' : (params[:name] || 'ResponseAssertion')
      @doc = Nokogiri::XML(<<-EOS.strip_heredoc)
<ResponseAssertion guiclass="AssertionGui" testclass="ResponseAssertion" testname="#{testname}" enabled="true">
  <collectionProp name="Asserion.test_strings">
    <stringProp name="0"/>
  </collectionProp>
  <stringProp name="Assertion.test_field">Assertion.response_data</stringProp>
  <boolProp name="Assertion.assume_success">false</boolProp>
  <intProp name="Assertion.test_type">16</intProp>
  <stringProp name="Assertion.scope">all</stringProp>
</ResponseAssertion>)
      EOS
      update params
      update_at_xpath params if params.is_a?(Hash) && params[:update_at_xpath]
    end

How do I use it?

For csv_data_set_config,

DLS was like

def initialize(params={})
      testname = params.kind_of?(Array) ? 'CsvDataSetConfig' : (params[:name] || 'CsvDataSetConfig')
      @doc = Nokogiri::XML(<<-EOS.strip_heredoc)
<CSVDataSet guiclass="TestBeanGUI" testclass="CSVDataSet" testname="#{testname}" enabled="true">
  <stringProp name="delimiter">,</stringProp>
  <stringProp name="fileEncoding"/>
  <stringProp name="filename"/>
  <boolProp name="quotedData">false</boolProp>
  <boolProp name="recycle">true</boolProp>
  <stringProp name="shareMode">shareMode.all</stringProp>
  <boolProp name="stopThread">false</boolProp>
  <stringProp name="variableNames"/>
</CSVDataSet>)
      EOS
      update params
      update_at_xpath params if params.is_a?(Hash) && params[:update_at_xpath]
    end

I used it like

csv_data_set_config filename: "/Users/ajinkya41/projects/scout_tools/users.csv", variableNames: "username,password"

It was simple enough to use, but this response assertion is little difficult for me.

Upvotes: 0

Views: 689

Answers (1)

Tim Koopmans
Tim Koopmans

Reputation: 788

There's a basic example of using response assertions here amongst others ..

visit name: 'Altentee', url: 'http://altentee.com/' do
  assert contains: 'We test, tune and secure your site'
  assert 'not-contains' => 'Something in frames', scope: 'children'
end

Upvotes: 3

Related Questions