Re: [testng-users] How can I use CDATA inside Parameters

528 views
Skip to first unread message
Message has been deleted

gwash95014

unread,
Oct 20, 2011, 2:49:18 PM10/20/11
to testng...@googlegroups.com

Did you ever get a solution for this? I want to do the same thing. thanks.

Ingrid Martínez wrote:
>
> Hi,
>
> I want to include some data as value in parameter using <![CDATA, how
> can use it ? I like to use to avoid escaping the special charaters.
>
> I'm try try to use like follow, but doesn't work
>
> <suite name="Suite1" verbose="1">
> <test name="Constraints">
> <classes>
> <class
>
> name="com.qoslabs.phronesis.episteme.constraints.ContraintParserTest" /
>>
> <methods>
> <include name="contraintParser" />
> </methods>
> </classes>
> <parameter>
> <name>constraint</name>
> <value>
> <![CDATA[
>
> Set { InstanceOf {T(otro)} Data Pattern {"qwe"}}
> Set { InstanceOf {T(otro)} Data Pattern {"qwe"}}
> Set { InstanceOf {T(otro)} Data Pattern {"qwe"}}
> Set { InstanceOf {T(otro)} Data Pattern {"qwe"}}
>
> }
>
> ]]>
> </value>
>
> </parameter>
>
> </test>
> </suite>
>
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "testng-users" group.
> To post to this group, send email to testng...@googlegroups.com.
> To unsubscribe from this group, send email to
> testng-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/testng-users?hl=en.
>
>
>

--
View this message in context: http://old.nabble.com/How-can-I-use-CDATA-inside-Parameters-tp29453592p32691791.html
Sent from the testng-users mailing list archive at Nabble.com.

Cédric Beust ♔

unread,
Oct 20, 2011, 7:08:35 PM10/20/11
to testng...@googlegroups.com
CDATA should work, did you try it? What error are you seeing?

-- 
Cédric

gwash95014

unread,
Oct 26, 2011, 11:12:35 AM10/26/11
to testng...@googlegroups.com

Here is my testng.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="Platform API Functional Test">

<test name="PLTFM-1">
<classes>
<class name="TestCase"/>
</classes>
<parameter name="description" value="Create an Account"/>
<parameter name="service" value="ipinfo.ondemand.production.quova"/>
<parameter name="APICalls" value="simple data"/>
</test>

<test name="PLTFM-2">
<classes>
<class name="TestCase"/>
</classes>
<parameter name="description" value="Create an Asset"/>
<parameter name="service" value="ipinfo.ondemand.production.quova"/>
<parameter name="APICalls" value="<![CDATA[<data>my data</data>]]>"/>
</test>

<test name="PLTFM-3">
<classes>
<class name="TestCase"/>
</classes>
<parameter name="description" value="Create an Identity"/>
<parameter name="service" value="ipinfo.ondemand.production.quova"/>
<parameter name="APICalls" value="simple data"/>
</test>

</suite>


Here is my Java:

import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class TestCase {
@Parameters ({ "description", "service", "APICalls" })
@Test
public void myMethod(String description, String service, String apiCalls)
{
System.out.println(description);
System.out.println(service);
System.out.println(apiCalls);
assert apiCalls.equals("simple data");
}
}


Here is the error:

org.testng.TestNGException: org.xml.sax.SAXParseException: The value of
attribute "value" associated with an element type "null" must not contain
the '<' character.
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:305)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:88)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:202)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:173)
Caused by: org.xml.sax.SAXParseException: The value of attribute "value"
associated with an element type "null" must not contain the '<' character.
at
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
at
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:174)
at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:388)
at
com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1414)
at
com.sun.org.apache.xerces.internal.impl.XMLScanner.scanAttributeValue(XMLScanner.java:932)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanAttribute(XMLDocumentFragmentScannerImpl.java:1539)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1316)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2747)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:198)
at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:17)
at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:10)
at org.testng.xml.Parser.parse(Parser.java:170)
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:275)
... 3 more

--
View this message in context: http://old.nabble.com/How-can-I-use-CDATA-inside-Parameters-tp29453592p32725097.html

Cédric Beust ♔

unread,
Oct 26, 2011, 12:16:05 PM10/26/11
to testng...@googlegroups.com
An attribute needs to be declared of CDATA type in order to allow CDATA value, which the TestNG DTD doesn't do in this case.


-- 
Cédric

gwash95014

unread,
Oct 26, 2011, 12:39:05 PM10/26/11
to testng...@googlegroups.com

Are you saying I can't do what I am trying to do, or that there is a
workaround?
Sorry, I don't understand.

http://testng.org/testng-1.0.dtd.php has this:
<!ELEMENT parameter ANY>
<!ATTLIST parameter
name CDATA #REQUIRED
value CDATA #REQUIRED >

shouldn't that take care of it?

thanks, Mark


Cedric Beust wrote:
>
> An attribute needs to be declared of CDATA type in order to allow CDATA
> value, which the TestNG DTD doesn't do in this case.
>

> Source <http://en.wikipedia.org/wiki/CDATA#CDATA-type_attribute_value>.

--
View this message in context: http://old.nabble.com/How-can-I-use-CDATA-inside-Parameters-tp29453592p32725742.html

Cédric Beust ♔

unread,
Oct 28, 2011, 1:02:14 AM10/28/11
to testng...@googlegroups.com
It should work since it's CDATA but it looks like even so, the parser doesn't like the closing > sign inside the double quote...

Maybe someone more versed in XML can chime in?

-- 
Cédric

Abraham Lin

unread,
Oct 28, 2011, 1:37:01 AM10/28/11
to testng...@googlegroups.com
The CDATA construct cannot be used for attribute values; it can only be used in lieu of text nodes. Refer to the grammar definition for attribute values in the XML specification: http://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue

-Abraham


2011/10/28 Cédric Beust ♔ <ced...@beust.com>

gwash95014

unread,
Oct 28, 2011, 9:58:50 AM10/28/11
to testng...@googlegroups.com

Thanks, that makes sense.

so, if the value attribute were a text element within the parameter element,
we could put CDATA in there.
example:

<test name="PLTFM-2">
<classes>
<class name="TestCase"/>
</classes>

<parameter name="APICalls">
<value> <![CDATA[<data>mydata</data>]]> </value>
</parameter>

</test>

But, value is an attribute, not a nested element within parameter. The
person who originally started this
thread (Martinez), appeared to be trying to use value as a nested element,
but was unsuccessful.
I was not able to get that to parse either.

Having CDATA as parameter input is very useful, if we could accomplish it.
Then we can have XML data
structures passed in as parameters to our tests without all the &lt; kind of
escaping.

thanks to all

--
View this message in context: http://old.nabble.com/How-can-I-use-CDATA-inside-Parameters-tp29453592p32738417.html

Reply all
Reply to author
Forward
0 new messages