How to pass parameter to ant scripts?

Recently, I am working on selenium webdriver 2.0 (development of an automation system). In accordance with the requirements for each screen, the screenshot must be captured (file path and file name: ./ screenshots / testcases / ddmmyyyy / scenario_hhmmss.png), however I am already taking screenshots. when I run the entire test package (I want to generate a JUNIT report so that the repost link should have a link to the screenshot.) Now the problem is that the screenshot path is generated dynamically (by selenium java code), and in the Junit report I want to set a hyperlink to recently generated screenshots (I have already updated the frames-report.xslt files, using which we can create a link, but it was hard-coded)? Please suggest any way to do this?

Here is part of my build.xml file

<target name="exec" depends="compile"> <delete dir="${report}" /> <mkdir dir="${report}" /> <mkdir dir="${report}/xml" /> <junit printsummary="yes" haltonfailure="no"> <classpath refid="project-classpath" /> <classpath> <pathelement location="${bin}" /> <fileset dir="${lib}"> <include name="**/*.jar" /> </fileset> </classpath> <test name="com.example.tests.NormanTestSuite" haltonfailure="no" todir="${report}/xml" outfile="TEST-result"> <formatter type="xml" /> </test> </junit> <junitreport todir="${report}"> <fileset dir="${report}/xml"> <include name="TEST*.xml" /> </fileset> <report styledir="C:\apache-ant-1.8.4\custom" format="frames" todir="${report}/html" > </report> </junitreport> </target> 
+7
source share
2 answers

Using the Java System Property

You can pass a variable as an argument to the JVM. Assuming you have a variable called "screenShotRoot" defined as follows

 ant -DscreenShotRoot=/screenshots/testcases 

you can read it in build.xml file like this

 <property name="screenshot.root" value="${screenShotRoot}" /> 

Then your ANT task can use this root path to create the appropriate paths to your PNG files on the expected date.

See this Apache ANT FAQ page.

Using environment variables

You can also use operating system environment variables by setting them before calling the script. Assuming you have an environment variable called "screenShotRoot" defined like this on Windows

 SET screenShotRoot=/screenshots/testcases 

you can read it in build.xml file like this

 <property environment="env"/> <property name="screenshot.root" value="${env.screenShotRoot}" /> 

Using Property Files

You can also write your links to a properties file that loads your ANT script, for example

 <property file="build.properties"/> 
+15
source

According to the JUnitReport task documentation, you can pass XSL parameter parameters using the nested param tag in the report element.

Since Ant 1.7, the report tag supports nested param tags. These tags can pass XSL parameters to the stylesheet.

So, you can pass the parameter value to the stylesheet like this:

 <report styledir="C:\apache-ant-1.8.4\custom" format="frames" todir="${report}/html" > <param name="screenshots_link" expression="${screenshots.link}"/> </report> 

I was not clear from your question. I think you said that you already support the option in your XSL stylesheet. Anyway, here is a brief description of how you can use it:

 <xsl:stylesheet> <!-- declare the parameter you will pass. Could also define a default value --> <xsl:param name="screenshot_link"/> <xsl:template> <!-- use the parameter value --> <xsl:value-of select="$screenshot_link"/> 
+1
source

All Articles