XML responses
DrevOps\BehatSteps\Steps\Web\XmlTrait - Source, Example, Helpers
Assert XML responses with element and attribute checks.
- Assert response is valid XML format.
- Assert XML element existence and content.
- Assert XML attribute values.
- Assert XML structure and namespace usage.
Steps
@Given the response XML is loaded from the file :filename
Set the response XML content from a fixture file
Given the response XML is loaded from the file "xml_valid.xml"
@Given the response XML is the following:
Set the response XML content directly from a PyString
Given the response XML is the following:
"""
<?xml version="1.0"?><root><item>value</item></root>
"""
@When I print the last XML response
Print the last XML response
When I print the last XML response
@Then the response should be in XML format
Assert that a response is valid XML
Then the response should be in XML format
# Content set by a fixture step is validated instead of the page content.
Given the response XML is loaded from the file "xml_valid.xml"
Then the response should be in XML format
@Then the response should not be in XML format
Assert that a response is not valid XML
Then the response should not be in XML format
# Content set by a fixture step is validated instead of the page content.
Given the response XML is loaded from the file "xml_invalid.xml"
Then the response should not be in XML format
@Then the XML element :element should exist
Assert that an XML element exists
Then the XML element "//book" should exist
Then the XML element "/library/book[@id='123']" should exist
@Then the XML element :element should not exist
Assert that an XML element does not exist
Then the XML element "//nonexistent" should not exist
Then the XML element "/library/book[@id='999']" should not exist
@Then the XML element :element should have the value :value
Assert that an XML element content equals specified text
Then the XML element "//title" should have the value "The Great Adventure"
Then the XML element "/library/book[1]/author" should have the value "John Doe"
@Then the XML element :element should not have the value :value
Assert that an XML element content does not equal specified text
Then the XML element "//title" should not have the value "Wrong Title"
Then the XML element "/library/book[1]/author" should not have the value "Wrong Author"
@Then the XML element :element should contain :value
Assert that an XML element contains specified text
Then the XML element "//description" should contain "sample book"
Then the XML element "/library/book[1]/description" should contain "detailed"
@Then the XML element :element should not contain :value
Assert that an XML element does not contain specified text
Then the XML element "//description" should not contain "nonexistent"
Then the XML element "/library/book[1]/title" should not contain "wrong"
@Then the XML attribute :attribute on the element :element should exist
Assert that an XML attribute exists on an element
Then the XML attribute "id" on the element "//book" should exist
Then the XML attribute "category" on the element "/library/book[1]" should exist
@Then the XML attribute :attribute on the element :element should not exist
Assert that an XML attribute does not exist on an element
Then the XML attribute "nonexistent" on the element "//book" should not exist
Then the XML attribute "missing" on the element "/library/book[1]" should not exist
@Then the XML attribute :attribute on the element :element should have the value :value
Assert that an XML attribute value equals specified text
Then the XML attribute "id" on the element "//book" should have the value "123"
Then the XML attribute "category" on the element "/library/book[1]" should have the value "fiction"
@Then the XML attribute :attribute on the element :element should not have the value :value
Assert that an XML attribute value does not equal specified text
Then the XML attribute "id" on the element "//book" should not have the value "999"
Then the XML attribute "category" on the element "/library/book[1]" should not have the value "science"
@Then the XML attribute :attribute on the element :element should contain :value
Assert that an XML attribute value contains specified text
Then the XML attribute "category" on the element "//book" should contain "fic"
Then the XML attribute "id" on the element "/library/book[1]" should contain "12"
@Then the XML attribute :attribute on the element :element should not contain :value
Assert that an XML attribute value does not contain specified text
Then the XML attribute "category" on the element "//book" should not contain "science"
Then the XML attribute "id" on the element "/library/book[1]" should not contain "999"
@Then the XML element :element should have :count element(s)
Assert that an XML element has a specific number of child elements
Then the XML element "//library" should have "3" elements
Then the XML element "/library" should have "3" elements
@Then the XML should use the namespace :namespace
Assert that the XML uses a specific namespace
Then the XML should use the namespace "http://example.com/custom"
@Then the XML should not use the namespace :namespace
Assert that the XML does not use a specific namespace
Then the XML should not use the namespace "http://example.com/nonexistent"
@Then the response should match the following XSD schema:
Assert that the response validates against an inline XSD schema
Then the response should match the following XSD schema:
"""
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="note" type="xs:string"/>
</xs:schema>
"""
@Then the response should match the XSD schema in the file :filename
Assert that the response validates against an XSD schema from a file
Then the response should match the XSD schema in the file "xml_schema.xsd"
@Then the response should match the following DTD:
Assert that the response validates against an inline DTD
Then the response should match the following DTD:
"""
<!ELEMENT note (#PCDATA)>
"""
@Then the response should match the DTD in the file :filename
Assert that the response validates against a DTD from a file
Then the response should match the DTD in the file "xml_schema.dtd"
@Then the response should match the following RelaxNG schema:
Assert that the response validates against an inline RelaxNG schema
Then the response should match the following RelaxNG schema:
"""
<element name="note" xmlns="http://relaxng.org/ns/structure/1.0">
<text/>
</element>
"""
@Then the response should match the RelaxNG schema in the file :filename
Assert that the response validates against a RelaxNG schema from a file
Then the response should match the RelaxNG schema in the file "xml_schema.rng"
@Then the response should be a valid RSS feed
Assert that the response is a valid RSS 2.0 feed
Then the response should be a valid RSS feed
@Then the response should be a valid Atom feed
Assert that the response is a valid Atom feed
Then the response should be a valid Atom feed