ruby-jmeter
ruby-jmeter copied to clipboard
JsonPath assertion
Current jmeter does json assertion
<JSONPathAssertion guiclass="JSONPathAssertionGui" testclass="JSONPathAssertion" testname="JSON result Assertion" enabled="true">
<stringProp name="JSON_PATH">$.result</stringProp>
<stringProp name="EXPECTED_VALUE">Energy</stringProp>
<boolProp name="JSONVALIDATION">true</boolProp>
<boolProp name="EXPECT_NULL">false</boolProp>
<boolProp name="INVERT">false</boolProp>
<boolProp name="ISREGEX">true</boolProp>
</JSONPathAssertion>
This gem seems to be using a different java library.
You should be able to do this
module RubyJmeter
class DSL
def json_path_assertion(params={}, &block)
node = RubyJmeter::JSONPathAssertion.new(params)
attach_node(node, &block)
end
end
class JSONPathAssertion
attr_accessor :doc
include Helper
def initialize(params={})
testname = params.kind_of?(Array) ? 'JSONPathAssertion' : (params[:name] || 'JSONPathAssertion')
@doc = Nokogiri::XML(<<-EOS.strip_heredoc)
<JSONPathAssertion guiclass="JSONPathAssertionGui" testclass="JSONPathAssertion" testname="#{testname}" enabled="true">
<stringProp name="JSON_PATH">$</stringProp>
<stringProp name="EXPECTED_VALUE"></stringProp>
<boolProp name="JSONVALIDATION">true</boolProp>
<boolProp name="EXPECT_NULL">false</boolProp>
<boolProp name="INVERT">false</boolProp>
<boolProp name="ISREGEX">true</boolProp>
</JSONPathAssertion>)
EOS
update params
update_at_xpath params if params.is_a?(Hash) && params[:update_at_xpath]
end
end
end
Users should be able to use this with:
json_path_assertion JSON_PATH: '$.result[6]', EXPECTED_VALUE: 'Energy'