Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.
Auto Populating parametized attributes
LegacyForum
Posts: 1,664 ✭✭
We're using the populate to map large (and small) tests. I've not been able to find an Xpath that will auto-populate an attribute. e.g.
We have an element to ship:
<MyDt myattr="true">2008-03-11</MyDt>
After a populate with the following fields:
Record/MyDt/myattr
Record/MyDtXL
Record/MyDt
The test will populate as follows:
Use Data Source: Exclude with empty string [Record/MyDtXL]
X myattr [Fixed] _________
[Parameterized] [Record/MyDt]
When we really wanted the "myattr" to be parametized to "Record/MyDt/myattr"
our "myattr" is pretty much the same name across 100's of elements, so an Xpath of some sort is requisite
Is there a format that will work?
Roxanne
We have an element to ship:
<MyDt myattr="true">2008-03-11</MyDt>
After a populate with the following fields:
Record/MyDt/myattr
Record/MyDtXL
Record/MyDt
The test will populate as follows:
CODE
Use Data Source: Exclude with empty string [Record/MyDtXL]
X myattr [Fixed] _________
[Parameterized] [Record/MyDt]
When we really wanted the "myattr" to be parametized to "Record/MyDt/myattr"
our "myattr" is pretty much the same name across 100's of elements, so an Xpath of some sort is requisite
Is there a format that will work?
Roxanne
0
Comments
-
When including attributes of elements in the xpath, the character is used to indicate it's an attribute. In your example it should be Record/MyDt@myattr
A tip for future reference is to use the XML Transformer which provides you the GUI interface to create XPaths. For example you could create a Messaging Client or SOAP Client and use Literal XML view and paste in the XML content:
<Record>
<MyDt myattr="true">2008-03-11</MyDt>
</Record>
And put in a valid endpoint, for example: http://www.foo.com
Attach the XML Transformer to the Request. Run the test, and go to the XML Transformer and click on myattr and add it. Click modify and copy and paste the XPath that's been generated. In this case the XML transformer will generate a namespace aware XPath, you could modify it if you wish, but in essence it will provide you with the correct syntax/structure of the desired XPath.We're using the populate to map large (and small) tests. I've not been able to find an Xpath that will auto-populate an attribute. e.g.
We have an element to ship:
<MyDt myattr="true">2008-03-11</MyDt>
After a populate with the following fields:
Record/MyDt/myattr
Record/MyDtXL
Record/MyDt
The test will populate as follows:CODE
Use Data Source: Exclude with empty string [Record/MyDtXL]
X myattr [Fixed] _________
[Parameterized] [Record/MyDt]
When we really wanted the "myattr" to be parametized to "Record/MyDt/myattr"
our "myattr" is pretty much the same name across 100's of elements, so an Xpath of some sort is requisite
Is there a format that will work?
Roxanne0 -
aha! [duh] thxWhen including attributes of elements in the xpath, the character is used to indicate it's an attribute. In your example it should be Record/MyDt@myattr
having implemented it... I have found that it has to be
Record/MyDt/@myattr
for the populate to find and use it.
good information. I was familiar with the Transformer from prior work, we used it to ALTER certain values, but hadn't noticed how to use it to generate REQUEST Xpaths..A tip for future reference is to use the XML Transformer which provides you the GUI interface to create XPaths.
...
In this case the XML transformer will generate a namespace aware XPath, you could modify it if you wish,
thx for fixing this one for me.
Roxanne0