A High-Level Overview of XML , XML stands for Extensible Markup Language,
and is a specification for storing information. The World Wide Web Consortium
describes XML as “a simple, very flexible text format derived from SGML (ISO
8879). Originally designed to meet the challenges of large-scale electronic
publishing, XML is also playing an increasingly important role in the exchange
of a wide variety of data on the Web and elsewhere.” When testing modern
applications, we often find ourselves needing to handle Extensible Markup
Language --XML. Testing XML requires the ability to parse, read , and dissect
it and as we have seen in previous chapters many web services’s SOAP messages
make use of XML. Like HTML, XML uses tags, but unlike HTML XML
- Import XSD to test folder = false
-XSD = C:\ shiporder.xsd
has no tags of its own. The user creates whichever tags best
describe the data he or she is dealing with. XML allows the user to create his
or her own markup language. Unlike HTML, which is concerned with the
presentation of data, XML was designed to address two other important areas: -
Data Storage - Carrying Information UFT API testing includes common XML
activities that help you to test and verify XML.
UFT API XML Activities There are five XML activities
available to you under UFT API’s
Toolbox: - Transform XML - transforms an XML
file to another structure based on XSLT.
-Compare XMLs – performs a comparison between two XML
strings.
- String to XML - converts
a string into an XML structure.
- XML to string - converts an XML documents into a string.
- Validate XML - validates an XML file against its XSD
schema.
Before we can start using the XML activities, we’ll need to
have an XML and XSD files to test against. For this we’ll use some sample XML
found on ww.w3school.com’s web site.
UFT XML example files Before we get started, let’s create an
XML file to work with. Rather than reinvent the wheel, we’ll simply use the
shiporder.xml and the shiporder.xsd from w3school, which is a great web site
that offers free tutorials on many web technologies, including XML. For this
example we will also be using XSD, or XML Schema Definition, which uses XML
elements and attributes to describe the structure of a custom markup language.
Before we get started lets create some XML and XSD file that we will use in our
UFT XML examples. Create an XML file
1) Open up Notepad.
2) Navigate to: http:// www.w3schools.com/ schema/
schema_example.asp .
3) Highlight and copy the shiporder.xml and paste it into
Notepad.
4) Save the file to a
directory on your C drive as shiporder.xml. Your shiporder.xml should look like
this:
<? xml version =" 1.0" encoding ="
ISO-8859-1"? >
< shiporder
orderid =" 889923" xmlns:xsi =" http:// www.w3. org/ 2001/
XMLSchema-instance" xsi:noNamespaceSchemaLocation ="
shiporder.xsd" >
< orderperson >
John Smith </ orderperson >
< shipto >
< name > Ola
Nordmann </ name >
< address > Langgt 23 </ address >
< city > 4000 Stavanger </ city >
< country >
Norway </ country >
</ shipto >
< item >
< title >
Empire Burlesque </ title >
< note >
Special Edition </ note >
< quantity > 1
</ quantity >
< price > 10.90
</ price >
</ item >
< item >
< title > Hide
your heart </ title >
< quantity > 1
</ quantity >
< price > 9.90
</ price >
</ item >
</ shiporder >
Create an XSD file
1) Open up Notepad.
2) Navigate to: http:// www.w3schools.com/ schema/
schema_example.asp .
3) Highlight and copy the shiporder.xsd and paste into
Notepad.
4) Save the file to your C drive as shiporder.xsd Your
shiporder.xsd should look like this:
<? xml version
=" 1.0" encoding =" ISO-8859-1" ?>
< xs:schema
xmlns:xs =" http:// www.w3. org/ 2001/ XMLSchema" >
< xs:element name =" shiporder" >
< xs:complexType
>
< xs:sequence >
< xs:element name
=" orderperson" type =" xs:string"/ >
< xs:element name
=" shipto" >
< xs:complexType
> < xs:sequence >
< xs:element name =" name" type ="
xs:string"/ >
< xs:element name
=" address" type =" xs:string"/ >
< xs:element name
=" city" type =" xs:string"/ >
< xs:element name
=" country" type =" xs:string"/ >
</ xs:sequence
> </ xs:complexType > </ xs:element >
< xs:element name =" item" maxOccurs ="
unbounded" >
< xs:complexType
> < xs:sequence >
< xs:element name =" title" type ="
xs:string"/ >
< xs:element name =" note" type ="
xs:string" minOccurs =" 0"/ >
< xs:element name
=" quantity" type =" xs:positiveInteger"/ >
< xs:element name
=" price" type =" xs:decimal"/ >
</ xs:sequence
>
</ xs:complexType >
</ xs:element >
</ xs:sequence
>
< xs:attribute name =" orderid" type ="
xs:string" use =" required"/ >
</ xs:complexType >
</ xs:element >
</ xs:schema >
Validate XML Activity UFT’s has a Validate XML activity that
allows a user to validate an XML document or XML string against an XML Schema
Definition (XSD).
1) Create a new UFT API test named ValidateXML
2) In UFT, drag a File > Read from File activity onto the
canvas.
3) Under Read from
File Properties, set the following Input values:
- File path = c:\
shiporder.xml
- Encoding = Automatic
4) Drag an XML > Validate XML onto the canvas under Read
from File.
5) Under Validate XML Properties, set the following Input
values:
- XML String = Click
on the Link to data source. In the Select Link Source for XML string, point to
the Read from File’s Content output property. Click OK.
- Import XSD to test folder = false
-XSD = C:\ shiporder.xsd
6) Run the test and look at the Run Results Viewer’s Validate XML Captured Date section. You should now see the message Validation ended successfully.
No comments:
Post a Comment