I am trying to run the selenium tests with selenium grid 2 set up. My tests are more dependent . I have to well-define my sequential run & parallel run. Attaching my build.xml file for ref. Inside sequential node I have many parallel nodes with different targets. I am facing inconsistency issues in running this build.xml.
Some times it picks up the targets of 2nd parallel node & sometimes its not. It is not giving error also. I tried running ant command in verbose mode, still not getting ant exceptions.
Will be glad if someone helps in this regard.
<target name="startServerRC" depends="startServerhub">
<echo>Starting Selenium Server...</echo>
<java jar="${lib.dir}/selenium-server-standalone.jar" fork="true" spawn="true">
<arg line="-port 5555"/>
<arg line="-log log.txt"/>
<arg line="-firefoxProfileTemplate"/>
<arg value="${lib.dir}/ff_profile"/>
<arg line="-userExtensions"/>
<arg value="${lib.dir}/user-extensions.js"/>
<arg line="-role node"/>
<arg line="-hub http://localhost:4444/grid/register "/>
<arg line="-maxSession 10"/>
<arg line="-maxInstances=10"/>
</java>
</target>
<!-- Initialization -->
<target name="init" depends="startServerRC" >
<echo>Initlizing...</echo>
<delete dir="${classes.dir}" />
<mkdir dir="${classes.dir}"/>
</target>
<!-- Complies the java files -->
<target name="compile" depends="init">
<echo>Compiling...</echo>
<javac
debug="true"
srcdir="${src.dir}"
destdir="${classes.dir}"
classpathref="classpath" />
</target>
<target name="CItarget">
<sequential>
<antcall target="compile"/>
<parallel>
<antcall target="run"/>
<antcall target="run_PSDATA"/>
</parallel>
<parallel>
<antcall target="run_PreData"/>
<antcall target="run_DFPPulls"/>
<antcall target="run_AdTechPulls"/>
<antcall target="run_AppnexusPulls"/>
<antcall target="run_FTPPulls"/>
<antcall target="run_OASPulls"/>
<antcall target="run_GDFPPulls"/>
<antcall target="run_FreewheelPulls"/>
<antcall target="run_ThirdPartyPulls"/>
</parallel>
<parallel>
<antcall target="run_PostData"/>
<antcall target="run_Sales"/>
</parallel>
<parallel>
<antcall target="run_Administration"/>
<antcall target="run_E2EPartner360"/>
<antcall target="run_Sales"/>
<antcall target="run_Finance"/>
<antcall target="run_Loaders"/>
<antcall target="run_Accounts"/>
<antcall target="run_Adops"/>
</parallel>
<parallel>
<antcall target="run_Alerts"/>
<antcall target="run_CustomFields"/>
</parallel>
<antcall target="stop-selenium"/>
</sequential>
</target>
Thanks in advance
Anjana
Try QAF (formerly ISFW) where you can run test parallel with/without use of grid.
In Your case following config file can fulfill your requirement:
<suite name="Sample Test Automation" verbose="0" parallel="tests">
<test name="Set1" >
<parameter name="selenium.server" value="server1"/>
<parameter name="selenium.port" value="port"/>
<!-- group or class or package entry as per testNG standard
-->
<classes>
<class name="qualified name of class"></class>
</classes>>
</test>
<test name="set2" >
<parameter name="selenium.server" value="server2"/>
<parameter name="selenium.port" value="port"/>
<!-- <packages>
<package name="package name" />
</packages>
-->
<classes>
<class name="qualified name of class"></class>
</classes>
</test>
</suite>
It's much better to use tesng or junit to manager parallel testing instead of doing it directly in Build.xml.
here is a good tutorial on configuring testng, Ant and selenium grid :
http://technologyandleadership.com/six-steps-for-complete-test-automation-with-selenium-grid/
Related
Here i want to compile/run first ExceuteLeadTest.class and then ExceuteContactTest.class by the ant ..But while exceuting it first it comipling/running ExcecuteContactTest.java/ExceuteContactTest.class
<project>
<target name="run" depends="compile">
<include name="testScript/ExceuteLeadTest.class" />
<include name="testScript/ExceuteContactTest.class" />
</target>
<project>
In Ant you can use the sequential tag to run tasks in order. Normally Ant processes dependencies and runs each only once if they are included repeatedly in depends.
Example
<target name="run" depends="compile">
<sequential>
<antcall target="run1"/>
<antcall target="run2"/>
</sequential>
</target>
<target name="run1" depends="compile">
<!-- however you run the 1st class -->
</target>
<target name="run2" depends="compile">
<!-- however you run the 2nd class -->
</target>
I can run my build file from two targets as below
<target name="makeMinificationTarget" depends="inheritedTarget" />
<target name="skipMinificationTarget" depends="inheritedTarget" />
However, these both targets internally calls "inheritedTarget" and this "inheritedTarget" internally calls "makeMinification" target.
Following is "inheritedTarget" and "makeMinification"
<target name="makeMinification">
<echo message="makingMinification...">
</target>
<target name="inheritedTarget" depends="makeMinification"/>
<echo message="compileFiles">
<echo message="ExecuteFiles">
</target>
My question is i want to skip execution of "makeMinification" target from
this call <target name="skipMinificationTarget" depends="inheritedTarget" />
And
let it happen if we call <target name="makeMinificationTarget" depends="inheritedTarget" />
How can I achieve this ???
Does this work? Using "antcall" and passing the parameter. Instead of using "depends"
<target name="makeMinificationTarget" >
<antcall target="inheritedTarget">
<param name="Minification" value="true"/>
</antcall>
</target>
<target name="skipMinificationTarget" >
<antcall target="inheritedTarget">
<param name="Minification" value="false"/>
</antcall>
</target>
<target name="inheritedTarget" >
<if>
<equals arg1="${Minification}" arg2="true" />
<then>
<antcall target="makeMinification"/>
</then>
<else>
<!-- Do something else-->
</else>
</if>
<!-- Do other stuff -->
</target>
<target name="makeMinification" >
<!-- Do something -->
</target>
Is there a way to cause Ant to not quit even if one of a target completes?
For instance, several targets may execute, and if the first one stops,selenium will freeze.All the other testcases which are running parallel in other target stops.
How to make ant to continue executing other targets,even if one completes.
I tried giving -k at target level , but no use. We have failonerror set to true .Does that matter?
Here is my build file :
<target name="startServerRC" depends="startServerhub">
<echo>Starting Selenium Server...</echo>
<java jar="${lib.dir}/selenium-server-standalone.jar" fork="true" spawn="true">
<arg line="-port 5555"/>
<arg line="-log log.txt"/>
<arg line="-firefoxProfileTemplate"/>
<arg value="${lib.dir}/ff_profile"/>
<arg line="-userExtensions"/>
<arg value="${lib.dir}/user-extensions.js"/>
<arg line="-role node"/>
<arg line="-hub http://localhost:4444/grid/register "/>
<arg line="-maxSession 10"/>
<arg line="-maxInstances=10"/>
</java>
</target>
<!-- Initialization -->
<target name="init" depends="startServerRC" >
<echo>Initlizing...</echo>
<delete dir="${classes.dir}" />
<mkdir dir="${classes.dir}"/>
</target>
<!-- Complies the java files -->
<target name="compile" depends="init">
<echo>Compiling...</echo>
<javac
debug="true"
srcdir="${src.dir}"
destdir="${classes.dir}"
classpathref="classpath" />
</target>
<target name="CItarget">
<sequential>
<antcall target="compile"/>
<parallel>
<antcall target="run"/>
<antcall target="run_PSDATA"/>
</parallel>
<parallel>
<antcall target="run_PreData"/>
<antcall target="run_DFPPulls"/>
<antcall target="run_AdTechPulls"/>
<antcall target="run_AppnexusPulls"/>
<antcall target="run_FTPPulls"/>
<antcall target="run_OASPulls"/>
<antcall target="run_GDFPPulls"/>
<antcall target="run_FreewheelPulls"/>
<antcall target="run_ThirdPartyPulls"/>
</parallel>
<parallel>
<antcall target="run_PostData"/>
<antcall target="run_Sales"/>
</parallel>
<parallel>
<antcall target="run_Administration"/>
<antcall target="run_E2EPartner360"/>
<antcall target="run_Sales"/>
<antcall target="run_Finance"/>
<antcall target="run_Loaders"/>
<antcall target="run_Accounts"/>
<antcall target="run_Adops"/>
</parallel>
<parallel>
<antcall target="run_Alerts"/>
<antcall target="run_CustomFields"/>
</parallel>
<antcall target="stop-selenium"/>
</sequential>
</target>
Thanks in advance
You could try using try-catch from ant-contrib.
Example from the link:
<trycatch property="foo" reference="bar">
<try>
<fail>Tada!</fail>
</try>
<catch>
<echo>In <catch>.</echo>
</catch>
<finally>
<echo>In <finally>.</echo>
</finally>
</trycatch>
If someting fails, you would just echo something (or do noting). The finally part works great if you need to make sure, that servers are shut down at the end, even if something fails hard in between.
Also setting failonerror="false" should make ant not to fail the build on errors.
[Solved] - The correct ant contrib jar was not getting picked up from the default location on my system. Have to give path manually in the build xml like this:
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="/usr/share/ant/lib/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
-------------------------------------------
Q: I have a python script that is run through ant/Jenkins like this:
<project name="prjName">
<target name="preRun" description="do something">
....
</target>
<target name="Run" description="Run the python script">
<exec executable="python" failonerror="true">
<arg value="${basedir}/run.py" />
<arg value="something" />
</exec>
</target>
<target name="other1" description="do something">
....
</target>
<target name="other2" description="do something">
....
</target>
</project>
Now this python script runs an external tool (web-inject which produces some result files) and keeps on scanning for the word FAIL in the logs. As soon as it finds FAIL, it does sys.exit("Error")
Thus the build fails but I still want to execute the target - other1. Is it possible through try-catch? I am doing it like this but it isn't working
<macrodef name="test-case">
<sequential>
<trycatch>
<try>
<exec executable="python" failonerror="true">
<arg value="${basedir}/read.py" />
</exec>
</try>
<catch>
<echo>Investigate exceptions in the run!</echo>
</catch>
<finally>
<antcall target="other1" />
</finally>
</trycatch>
</sequential>
</macrodef>
<target name="other1" description="do something">
....
</target>
The following is my ant script:
<project name="nightly_build" default="main" basedir="C:\Work\6.70_Extensions\NightlyBuild">
<target name="init">
<sequential>
<exec executable="C:/Work/Searchlatestversion.exe">
<arg line='"/SASE Lab Tools" "6.70_Extensions/6.70.102/ANT_SASE_RELEASE_"'/>
</exec>
<property file="C:/Work/latestbuild.properties"/>
<sleep seconds="10"/>
<echo message="The product version is ${Product_Version}"/>
<exec executable="C:/Work/checksnapshot.exe">
<arg line='"ANT_SASE_RELEASE_${Product_Version}_SASE Lab Tools-NightlyBuild" ANT_SASE_RELEASE_${Product_Version}_AnalyzerCommon-NightlyBuild ${Product_Version}-AppsMerge' />
</exec>
<property file="C:/Work/checksnapshot.properties"/>
<tstamp>
<format property="suffix" pattern="ddMMyyyyHHmm"/>
</tstamp>
</sequential>
</target>
<target name="main" depends="init">
<echo message="loading properties files.." />
<sleep seconds="10"/>
<echo message="Backing up folder" />
<move file="C:\NightlyBuild\NightlyBuild" tofile="C:\NightlyBuild\NightlyBuild.${suffix}" failonerror="false" />
<parallel>
<exec executable="C:/Work/sortfolder.exe">
<arg line="6" />
</exec>
<exec executable="C:/Work/6.70_Extensions/NightlyBuild/antc.bat">
</exec>
</parallel>
</target>
</project>
Basically the sequence goes something like this:
I will run Searchlatestversion.exe and write latestbuild.properties
Using the latestbuild.properties i will obtain ${Product_Version} and would like to allow checksnapshot.exe access to latestbuild.properties and obtain ${Product_Version}
checksnapshot.exe will then generate checksnapshot.properties which will then be used by the target in main antc.bat
am i doing something wrong over here? seems like ${Product_Version} is not being received well by checksnapshot.exe
You appear to have a hard coded wait period of 10 seconds for Searchlatestversion to write out your file. If the executable does not complete inside that time, ${Product_Version} cannot be read from file.
Have you considered using the Waitfor Ant Task? As the name implies, this will wait for a certain condition before it will allow the rest of the task to progress. You could do something like
<property name="props.file" value="C:/Work/latestbuild.properties"/>
<waitfor maxwait="10" maxwaitunit="second">
<available file="${props.file}"/>
</waitfor>
<property file="${props.file}"/>
Does Searchlatestversion.exe produce the file C:/Work/latestbuild.properties?
If so, should you not sleep/wait before you load that properties file?
You have this:
<exec .../>
<property file="C:/Work/latestbuild.properties"/>
<sleep seconds="10"/>
Should you not have this:
<exec ... />
<sleep seconds="10"/>
<property file="C:/Work/latestbuild.properties"/>