Can I set the value of test element's name attribute in dynamic way? not static - pom.xml

I want to set the value of name element in testng.xml in dynamic way.
See below.
<test thread-count="5" name="${browser}">
<parameter name="browser" value="${browser}"/>
The command line comes with this option -Dbrowser=firefox.
This above testng.xml code works fine in the parameter element but test element.
See the test result in Allure report.
What I want is to have Allure report displays testname with browser.

Related

Ant xmlproperty task fails due to validation error

I want to extract an application version from a DITA map file. The ditamap file is valid and looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE map PUBLIC "-//OASIS//DTD DITA Map//EN" "map.dtd">
<map id="user-manual">
<title><ph keyref="product"/> User Manual</title>
<topicmeta>
<prodinfo>
<prodname><keyword keyref="product"/></prodname>
<vrmlist>
<vrm version="4" release="3" modification="0"/>
</vrmlist>
</prodinfo>
</topicmeta>
<!--
[...]
-->
</map>
The information I want to get is in the <vrm> element.
"Easy peasy," I think to myself. So I use Ant's <xmlproperty> task to just load this XML file.
<project default="test">
<!-- notice #validate -->
<xmlproperty file="path/to/user-manual.ditamap" validate="false"/>
<target name="test">
<echo>${map.topicmeta.prodinfo.vrmlist.vrm(version)}</echo>
</target>
</project>
I don't want it to validate because Ant isn't going to find map.dtd.
Loading the file returns an error:
java.io.FileNotFoundException: /home/user/user-manual/map.dtd (No such file or directory)
If I remove the <!DOCTYPE> declaration or add a nested <xmlcatalog> with the path to the DTD, the file loads and I can use the properties from it.
I tested this with Ant 1.7.1 and 1.9.4. Is this a bug with Ant, or am I misunderstanding how Ant loads XML properties and the purpose of the validate attribute?
How can I make Ant obey my will?
I recommend to not use the <xmlproperty> for this. Please have a look at the docs:
For example, with semantic attribute processing enabled, this XML
property file:
<root>
<properties>
<foo location="bar"/>
<quux>${root.properties.foo}</quux>
</properties>
</root>
is roughly equivalent to the following fragments in a build.xml file:
<property name="root.properties.foo" location="bar"/>
<property name="root.properties.quux" value="${root.properties.foo}"/>
So the name of the properties you set is generated using their paths to the root element, so they rely on the structure of your DITA Map. But many elements in DITA may be set at different positions on your DITA Map. That means, if you move your metadata to another parent element, the property name changes and your build fails. This is probably not, what you want.
I'd recommend to grab those values via XSLT and than set the properties. That way, you could, for example, say, "give me the first occurance of that element with a simple //foo[1] XPath selector. Further on, you have the power of XSLT and XPath to slice values, format dates and so on before setting a property.
Update
You can use the oops consultancy Ant xmltask for that. It is very easy to set a property using <copy>:
<copy path="//critdates/created/#date"
property="document.date"
append="false"/>

Prevent echo in ant input task

How do you prevent ant's input task from echoing/printing in the console?
When requesting input in ant, it echoes the characters as you type. This isn't ideal for password inputs.
I ended up finding a solution.
As of Ant 1.7.1, this can be done by setting the handler to SecureInputHandler, see code below:
<input
message=" [input] password(Appserver):${line.separator}"
addproperty="password">
<handler classname="org.apache.tools.ant.input.SecureInputHandler" />
</input>
Strangely, when you set the handler to org.apache.tools.ant.input.SecureInputHandler, it doesn't display as it does with other input in that:
It doesn't have " [input]" prepended
Doesn't move the cursor to the next line
As such, I have achieved these 2 by modifying the message, see above.

What is source data for the report generated by junitreport ant task?

The JUnit official documentation states:
junitreport collects individual xml files generated by the JUnit task using the nested element.
Other part of the same page states:
<junitreport todir="./reports">
<fileset dir="./reports">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="./report/html"/>
</junitreport>
would generate a TESTS-TestSuites.xml file in the directory reports
and generate the default framed report in the directory report/html.
Let's say, I have file TEST-all.xml generated by junit task in the "reports" directory. I want to use it as data source for junitreport task:
<fileset dir="./reports">
<include name="TEST-all*.xml"/>
</fileset>
I would expect html report based on my data will be generated.
I tried to do it. Empty TESTS-TestSuites.xml file was generated and as a result empty html file.
Two documentation statements I quoted above somehow contradict each other: the first one says it will use already generated files to create a report and the second one says it will generate new file. Can somebody explain how it works? How can I control what data source will be used to generate html report?
Thanks.
Try running ant with -debug. I suspect
<include name="TEST-all*.xml"/>
is not matching any files. Please try with
<fileset dir="./reports">
<include name="TEST-*.xml"/>
</fileset>
Well, I figured out what was the problem: file TEST-all.xml was generated in wrong format. It seems the correct format is:
<testsuite>
<testcase classname="..." name="..." ...>
<properties>
<property name="..."/>
</properties>
</testcase>
</testsuite>
It didn't solve the problem completely though. The html report is still not generated properly:
In spite the fact that file TESTS-TestSuits.xml is not empty now and contains all necessary tests' information, main page of HTML report (index.html) still shows 0 tests.
If I click the link in Tests column (0 in this case) it opens list of tests, but if I try to open individual test in this page, I get "File not found" error.
I suspect the problem is still with the format of TEST-all.xml. I was looking for the description of the format, but found only pieces of information here and there. Any ideas?

Override one value in properties file

I have a properties file:
custom.properties
the content of this properties file is:
id=sf2j2345kkklljhlaasfsdfafsf543
name=SOME_NAME
The value of id is a long random string.
I want to make an Ant script to replace/over-write the value of id to another one, I tried with Ant <replace> syntax:
<target name="change-id">
<replace file="custom.properties" token="id" value="aaa" />
</target>
I run ant change-id , the content of the properties file becomes:
aaa=sf2j2345kkklljhlaasfsdfafsf543
name=SOME_NAME
That's the key "id" get replaced instead of its value. But I need to replace the value to "aaa" , how to achieve this in Ant?
Please do not recommend me to set token to id's random value, because that value is random generated and put there. I only want to over-write the random value of "id" by Ant script, how to achieve this?.
You can do it using replaceregexp task. Try to do it like in this example
conf.ini (utf-8)
aaa=sf2j2345kkklljhlaasfsdfafsf543
name=SOME_NAME
build.xml
<project name="regexp.replace.test" default="test">
<target name="test">
<replaceregexp file="conf.ini" match="^aaa=.*" replace="aaa=newId" encoding="UTF-8" />
</target>
</project>
I don't know exactly if this regular expression is correct but this is the way you can do it.

In FitNesse - is there a way to see programmatically if a test failed/passed

In my CI server, I'm implementing some logging/audit functionality - after every Fit test runs, in the TearDown page I'm logging some stuff to DB - Test Name, TimeStamp, some variables; I would also like to log if the test failed or passed - don't seem to find any global variable readily available in FitNess that would help. Could anyone give me some ideas how to do that?
thanks!
O.
TearDown doesn't know if a test passed or failed. That is only known by FitNesse after the test is complete. What you can do is run fetch the last execution as XML and then parse that. Here is a snipped from ANT that will do something like that.
<!--Then run the page history responder to get the latest run of fitnesse in xml format-->
<java classpath="${toString:compile.classpath};build\classes" fork="true" jar="javalib/fitnesse.jar" maxmemory="256m" output="${fitnesse.output.file}.temp">
<arg value="-c" />
<arg value="${fitnesseSuite}?pageHistory&resultDate=latest&format=xml" />
<arg value="-p" />
<arg value="${fitnesse_port}" />
</java>
The one catch is that after you fetch it, you have to strip the http headers from the temp file that is created. But once you do that, you can use the test result data for your database. You can also create junit style results. Check out this example on transforming to junit: http://whotestedthis.squarespace.com/journal/2012/1/26/transforming-fitnesse-results-to-junit.html (shameless self promotion).

Resources