Is it possible to get test count of each class separately from testng xml file? - automated-tests

Currently we use testng ITestContext to get the test count running via testng xml file. My file contains multiple classes and
context.getPassedTests().size()
returns the total count of passed tests from all the classes mentioned in the xml file
my file looks like this :
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
<suite name="Main service" verbose="1" >
<test name="Smoke and Sanity" >
<classes>
<class name="tests.Service1" />
<class name="tests.Service2" />
<class name="tests.Service3" />
</classes>
</test>
<listeners>
<listener class-name="com.service.data.Base.TestResult"></listener>
</listeners>
</suite>
TestResult implements ITestListener and calculates the total number of tests being run by summing up context.getPassedTests().size() + context.getFailedTests().size() + context.getSkippedTests().size(), and this returns the total number of tests from classes service1, service2, service3
What i want is to get the total number of test cases from individual test class mentioned in xml and not the combined.
unable to find an approach

Related

How to poke connectionString in sqlmap.config?

In a similar way to what is done here, I would like to xmlpoke connectionString from an sqlmap.config file:
<?xml version="1.0" encoding="utf-8" ?>
<sqlMapConfig
xmlns="http://ibatis.apache.org/dataMapper"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<database>
<provider name="oracleClient1.0"/>
<dataSource name="DSExtranetAdherent"
connectionString="Data Source=MyInstance;User ID=MyUser;Password=MyPwd;Unicode=True;"/>
</database>
</sqlMapConfig>
I tried with this poke:
<xmlpoke
file="${ConfigPath}\sqlmap.config"
xpath="/sqlMapConfig/database/dataSource/#connectionString"
value="${ConnectionString}" />
But I get an error message:
[xmlpoke] No matching nodes were found with XPath expression '/sqlMapConfig/database/dataSource/#connectionString'.
The xpath is effective when I remove the xmlns property, but then I get this runtime error:
Unable to load file via resource "SqlMap.config" as resource.
Any idea on how to fix this xmlpoke with a good xpath?
xmlns is the default namespace, xmlpoke require a prefix for xpath parsing:
<xmlpoke
file="${ConfigPath}\sqlmap.config"
xpath="/iba:sqlMapConfig/iba:database/iba:dataSource/#connectionString"
value="${ConnectionString}">
<namespaces>
<namespace prefix="iba" uri="http://ibatis.apache.org/dataMapper" />
</namespaces>
</xmlpoke>
You should specify the <namespaces> child node for the <xmlpoke> task:
<namespaces>
<namespace prefix="xsi" uri="http://www.w3.org/2001/XMLSchema-instance" />
</namespaces>
The last sample on this page explains just your case.

XPROC - Generation of files in secondary port

My requirement is to generate one XML file and few HTML files in the secondary port. I have configured few steps in XProc.
Here’s the sample code:
<p:xslt name="create-document">
<p:input port="stylesheet">
<p:document href="stylesheet.xsl" />
</p:input>
</p:xslt>
<p:for-each>
<p:iteration-source>
<p:pipe step="create-document" port="secondary" />
</p:iteration-source>
<p:store>
<p:with-option name="doctype-public" select="'-//W3C//DTD XHTML 1.0 Frameset//EN'" />
<p:with-option name="doctype-system" select="'http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd'" />
<p:with-option name="encoding" select="'UTF-8'" />
<p:with-option name="media-type" select="'text/html'" />
<p:with-option name="method" select="'xhtml'" />
<p:with-option name="omit-xml-declaration" select="'no'" />
</p:store>
</p:for-each>
The problem here is HTML file is generated properly. And the XML file is generated, but I am not able to view the XML content. Instead it displays everything in HTML format.This is because of <p:store> in the above code snippet.
How do you have two <p:store> steps? (One for HTML and the other for XML)
It would be nice if you could somehow determine with which xsl:result-document parameters each document on the secondary output was written. You would be able to duplicate those for your p:store. But you can derive other things from each document. You can retrieve the document name using base-uri(), and you can look at for instance the root element. You can put these values in a variable using:
<p:variable name="path" select="base-uri(/*)"/>
<p:variable name="root" select="local-name(/*)"/>
(Put these just below the p:iteration-source.)
You then need to decide how to call p:store. You could use XPath if, provided your XProc parser supports XPath 2.0 (like XMLCalabash does). But I’d recommend using a p:choose like this:
<p:choose>
<p:when test="ends-with($path, '.xhtml')">
<p:store
doctype-public="-//W3C//DTD XHTML 1.0 Frameset//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"
encoding="UTF-8"
media-type="text/html"
method="xhtml"
omit-xml-declaration="no">
<p:with-option name="href" select="$path"/>
</p:store>
</p:when>
<p:otherwise>
<p:store
encoding="UTF-8"
media-type="application/xml"
method="xml"
omit-xml-declaration="no">
<p:with-option name="href" select="$path"/>
</p:store>
</p:otherwise>
</p:choose>
(This entire p:choose replaces the p:store you already have.)
The test in p:when only looks at $path, but you could include a test for $root as well, if you like.
It also requires you to use .xhtml as extension in your xsl:result-document statements for the HTML output, but you can easily tweak that if you like.
The var and the choose should be enough to get your XML written properly, at least.
Good luck!

Load variable from a file & pass as arg value in ant build

What I want to do is load the contents of a file and sent it to an mxmlc compiler as an argument parameter.
I can load and read the contents of a file using loadfile and setting a property value say propery="filecontent". But the problem is I can pass it into the mxmlc (flex) compiler.
I'm not able to pass it (tried with ${filecontent}) to the arg line. Its gives an error: "value contains unknown token 'filecontent'"
How will I pass the contents of the file as a argument value to a compiler argument?
Edit:
The problem is with the include-resource-bundles arguments. When using command line it works. But using ant build doesn't. Do we need to manually provide the name of resource bundles by generating the resource file?
<exec executable="${MXMLC}" dir="${APP_ROOT}/src" >
<arg line="-locale 'en_US'"/>
.. .. ..
<arg line="-include-resource-bundles 'collections,components,containers,controls,core,effects,formatters,layout,modules,skins,states,styles'"/>
.. ..
I'm trying to replace the arguments via something like:
... ....
<loadfile property="resources" srcFile="${APP_ROOT}/src/resources.txt"/>
... ....
<exec executable="${MXMLC}" dir="${APP_ROOT}/src" >
...
<arg line="-include-resource-bundles '${resources}'"/>
....
</exec>
which doesn't work and gives and error -> command line: Error: configuration variable 'include-resource-bundles' value contains unknown token 'resources'
So how to automate this?
There's nothing obviously wrong with the build file. But the error message suggests that ${resources} is not set when you call the MXMLC compiler. When an Ant property is not set, the property name (with dollar sign and enclosing curly brackets) is substituted instead anywhere that the property is used.
Can you insert something like
<echo message="Resources: ${resources}" />
after the 'loadfile' to check that that task is working? Note, for example, that if the resources.txt is empty the property will not be set.

Why doesn't ${locale} resolve in my <compc> Ant task?

I've seen a number of examples, e.g. here, where people are including locale resource bundles by referencing the locale attribute in the element. For some reason this doesn't work for me. Here's what I have for the task:
<compc output="${deploy.dir}/myfrmwrk.swc" locale="en_US">
<source-path path-element="${basedir}/src/main/flex"/>
<include-sources dir="${basedir}/src/main/flex" includes="*" />
<include-libraries file="${basedir}/libs"/>
<compiler.external-library-path dir="${FLEX_HOME}/frameworks/libs/player/9" append="true">
<include name="playerglobal.swc"/>
</compiler.external-library-path>
<compiler.library-path dir="${FLEX_HOME}/frameworks" append="true">
<include name="libs"/>
<include name="locale/${locale}"/>
</compiler.library-path>
<load-config filename="${basedir}/fb3config.xml" />
</compc>
This fails with a bunch of errors of the form:
[compc] Error: could not find source for resource bundle ...
I can make it build with this one change:
<include name="locale/en_US"/>
The configuration file generated by Flex Builder 3 actually renders this as "locale/{locale}" (notice the $ is missing). I've tried that as well with the same (failing) results.
For now, I'm doing OK directly injecting en_US as we won't be doing localization bundles for quite some time, but I will eventually need to get this working. Also, it bugs me that I can't make it work the way that it SHOULD work!
I think the problem here is that ${locale} is interpreted by ant as a property, rather than a string literal to pass to the compc task. What I mean is that ant sees ${locale} and thinks that you want to substitute the value of the property locale which is (supposedly) defined in your build file. Of course, this isn't what you want at all, and things break miserably because of it.
The way I've done things in my build files is to remove the $ prefix and everything seems to work as expected. So your example would look something like this:
<compc output="${deploy.dir}/myfrmwrk.swc" locale="en_US">
<source-path path-element="${basedir}/src/main/flex"/>
<include-sources dir="${basedir}/src/main/flex" includes="*" />
<include-libraries file="${basedir}/libs"/>
<compiler.external-library-path dir="${FLEX_HOME}/frameworks/libs/player/9" append="true">
<include name="playerglobal.swc"/>
</compiler.external-library-path>
<compiler.library-path dir="${FLEX_HOME}/frameworks" append="true">
<include name="libs"/>
<!-- Ditch the dollar sign and things should work! -->
<include name="locale/{locale}"/>
</compiler.library-path>
<load-config filename="${basedir}/fb3config.xml" />
</compc>

How to compile a SWC file with mulitple namespaces

I'm trying to compile an SWC file from a list of given ActionScript classes. I'm using the compc compiler. The problem is that there are so many classes grouped into multiple namespaces that I am finding it very tedious to specify each individual class to be included in the SWC. Is there any easier way of doing this like just simply specifying a root directory of these classes?
At the moment I have something like this:
<?xml version="1.0"?>
<flex-config xmlns="http://www.adobe.com/2006/flex-config">
<output>C:\SomeFolder\testSWC.swc</output>
<compiler>
<source-path>.</source-path>
</compiler>
<include-classes>
<class>SomeNamespaceOne.One</class>
<class>SomeNamespaceOne.Two</class>
<class>SomeNamespaceOne.Three</class>
<class>SomeNamespaceOne.Four</class>
...
<class>SomeNamespaceFifty.One</class>
</include-classes>
</flex-config>
But I want something like this:
<?xml version="1.0"?>
<flex-config xmlns="http://www.adobe.com/2006/flex-config">
<output>C:\SomeFolder\testSWC.swc</output>
<compiler>
<source-path>. </source-path>
</compiler>
<include-classes>
<class>SomeRootDirectoryOfClassesToCompile</class>
</include-classes>
</flex-config>
Is this possible?
We wanted something similar, in "Ant".
I am assuming you are not using Flex Builder. In that case, I will definitely recommend using Ant and Flex Ant tasks available from Adobe. Even when you use Ant, its not easy doing what you want to do, so I am including our code below.
Following is our code. I don't remember where I got the idea from, so cannot thank the source for it :)
<pathconvert property="XXX.classes" pathsep=" ">
<fileset dir="${basedir}/XXX/src">
<include name="**/*.as"/>
<include name="**/*.mxml"/>
</fileset>
<compositemapper>
<packagemapper from="${basedir}\XXX\src\*.as" to="*"/>
<packagemapper from="${basedir}/XXX/src/*.as" to="*"/>
<packagemapper from="${basedir}\XXX\src\*.mxml" to="*"/>
<packagemapper from="${basedir}/XXX/src/*.mxml" to="*"/>
</compositemapper>
</pathconvert>
<compc optimize="true" debug="false"
include-classes="${XXX.classes}" output="${BUILD_FOLDER}/XXX.swc">
</compc>
Like Tanmay said, you should use the ANT tasks to make life easier, but there's an even simpler wach include an entire directory in the compc ant task. If you just need to include everything in src.dir you can do it like this:
<compc output="${target.dir}/foo.swc">
<source-path path-element="${src.dir}"/>
<include-sources dir="${src.dir}">
<include name="**/*" />
</include-sources>
</compc>

Resources