how to run several test cases in one file - selenium-webdriver

I have a tricky question again and I hope you have a solution for me again.
Currently I have 2 testng.xml (testng1.xml and testng2.xml)
in testng1.xml
---------------
...
<suite name="Firefox Browser" verbose="1">
<test name="FF">
<parameter name="browserType" value="Firefox" />
<classes>
<class name="demo.Test01" />
<class name="demo.Test02" />
</classes>
</test>
</suite>
in testng2.xml
---------------
...
<suite name="Chrome Browser" verbose="1">
<test name="CH">
<parameter name="browserType" value="Chrome" />
<classes>
<class name="demo.Test01" />
<class name="demo.Test02" />
</classes>
</test>
</suite>
Okay,because of another issue (ATU report issue) I cannot combine these 2 testng files as 1 file (testng.xml) together, e.g.
testng.xml
----------
...
<suite name="Testsuite" verbose="1">
<test name="FF">
<parameter name="browserType" value="Firefox" />
<classes>
<class name="demo.Test01" />
<class name="demo.Test02" />
</classes>
</test>
<test name="CH">
<parameter name="browserType" value="Chrome" />
<classes>
<class name="demo.Test01" />
<class name="demo.Test02" />
</classes>
</test>
</suite>
Question: Ist there a way how to define an xml file, e.g. allTestng.xml
where I can run testng1.xml and testng2.xml ?
Important: testng1.xml should start and finish before testng2.xml can start.

You can create new testng.xml file and can call these suite testng.xml files with preserver-order='true' to execute in specified order. for example
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="My test suite" preserve-order="true">
<suite-files>
<suite-file path="Testng1.xml"></suite-file>
<suite-file path="Testng2.xml"></suite-file>
</suite-files>
above testng.xml file calls Testng1.xml suite file and then Testng2.xml.
I hope this is what you are looking for..

You can also use simply one testng.xml file with all your test cases inside, where cases are run one by one in following order. You are deciding which one to exclude or include into such test suite.
<suite name="Suite" parallel="none">
<parameter name="properties" value="Test.properties" />
<test name="Test checks xyz">
<classes>
<class name="testpackage.testClass" />
<methods>
<include name="firstTestMethod" />
<exclude name="secondTestMethod" />
</methods>
</classes>
</test>
</suite>

Related

How to use a variable in testng.xml file

i have following xml file in which i want to create variables and use them in all the test tags.
In below xml file, the property tag is what i tried to create a variable which is not working.
I want to create two variables env and browser in this testng.xml and use them within the same testng.xml.
Following is my code.
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="VW SRSTN-1152 suite">
<property name = "env" value = "qa">qa</property>
<property name = "browser" value = "firefox">firefox</property>
<listeners>
<listener
class-name="com.utility.CustomTestNGReporter" />
</listeners>
<test name="Test-1">
<parameter name = "environment" value="${env}"/>
<parameter name = "browser" value="${browser}"/>
<classes>
<class name="com.TC1"/>
<class name="com.TC2"/>
</classes>
</test> <!-- Test1 -->
<test name="Test-2">
<parameter name = "environment" value="${env}"/>
<parameter name = "browser" value="${browser}"/>
<classes>
<class name="com.TC1"/>
<class name="com.TC2"/>
</classes>
</test> <!-- Test2 -->
</suite> <!-- Suite -->```
See this,
<suite name="Parameter test Suite" verbose="1">
<!-- This parameter will be passed to every test in this suite -->
<parameter name="suite-param" value="suite level parameter" />
<test name="Parameter Test one">
<classes>
<class name="com.myclass1Here"/>
</classes>
</test>
<test name="Parameter Test two">
<!-- This parameter will be passed this test only -->
<parameter name="test-two-param" value="Test two parameter" />
<classes>
<class name="com.myclass2Here"/>
</classes>
</test>
<test name="Parameter Test three">
<!-- Overriding suite level parameter -->
<parameter name="suite-param" value="overiding suite parameter" />
<!-- Test specific parameter -->
<parameter name="test-three-param" value="test three parameter" />
<classes>
<class name="com.myClass3Here"/>
</classes>
</test>
depends upon your requirement you can use suite level par or test level par. You can override suite level par in test also

Error in TestNG Test execution in parallel

I am getting "
Failed to create file" error in console log when running testng test cases in parallel. Am i missing something or do i need to add something in pom.xml ?
Something like below error is observed:
[TestNG] Running:
C:\Users\askha2\git\sxyz.test\Copy of mnopqrst.xml
Test case: tigermania
Test case: applemania
Test case: potatomania
Failed to create file
Failed to create file
XML URL: JOB ...
My xml file looks something like this as shown below :
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="DEV XYZ Service Smoke Test Suite"
allow-return-values="true" verbose="1" parallel="tests" thread-count="2">
<test name="Test Context URL - 1">
<parameter name="sUrl" value="JOB" />
<classes>
<class
name="com.abc.tigermania"></class>
</classes>
</test>
<test name="Test Context URL - 2">
<parameter name="sUrl" value="JOB" />
<classes>
<class
name="com.abc.applemania"></class>
</classes>
</test>
<test name="Test Context URL - 3">
<parameter name="sUrl" value="JOB" />
<classes>
<class
name="com.abc.potatomania"></class>
</classes>
</test>
I also see more failures when i increase thread-count="2"

How to run test classes one by one inside <test> tag using maven

I have below testng xml but its not working. Every time running by maven it strat execution on three browsers. I want to run all classes one by one.
<?xml version="1.0" encoding="UTF-8"?>
<parameter name="browser" value="${browser}" />
<parameter name="execution" value="${execution}" />
<test name="POC Test" preserve-order="true" thread-count="1" >
<classes>
<class name="com.testscript.OurPurposeTest" />
<class name="com.testscript.ContactUsTest" />
<!-- <class name="com.testscript.ChevronTest" /> -->
<class name="com.testscript.SearchTest" />
<class name="com.testscript.FinancialRegulatoryReportsTest" />
<class name="com.testscript.CompanyHistoryTest" />
<class name="com.testscript.HomePageTest" />
</classes>
</test> <!-- POC Test -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>

ant run target if file has specifc suffix

I pass a filename to ant script via
ant -Dfilepath=/foo/bar/foobar.suffix
I want to copy it to a destination and if it is a .js file generate a compiled version of it.
This works but currently the compile task runs on all files not just .js file.
How do I exclude non .js files in the "runjscompile" task?
In a fileset I would do this (but I don't get how to apply this on the task):
<fileset dir="${foo}" casesensitive="yes">
<exclude name="**/*.min.js" />
<include name="**/*.js" />
</fileset>
My build.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project name="test" basedir="." default="build">
<taskdef name="jscomp" classname="com.google.javascript.jscomp.ant.CompileTask" classpath="/home/bar/bin/compiler.jar" />
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="/usr/share/java/ant-contrib.jar" />
</classpath>
</taskdef>
<property name="serverRoot" value="/home/bar/server/public_html" />
<property name="foo" value="${serverRoot}/foo/" />
<property name="workspaceRoot"
value="/home/bar/Zend/workspaces/DefaultWorkspace/" />
<property name="foo_service" value="${workspaceRoot}/foo_service/" />
<property name="filepath" value="${filepath}" />
<target name="build" depends="transferFile, runjscompile" />
<target name="transferFile" description="overwrite old file">
<basename property="filename" file="${filepath}" />
<dirname property="path" file="${filepath}" />
<pathconvert property="path.fragment" pathsep="${line.separator}">
<propertyresource name="path" />
<mapper type="regexp" from="^/[^/]+/(.*)" to="\1" />
</pathconvert>
<echo message="copy ${workspaceRoot}${filepath} to ${foo}${path.fragment}${filename}" />
<copy file="${workspaceRoot}${filepath}" tofile="${foo}${path.fragment}${filename}"
overwrite="true" force="true" />
<property name="destFile" value="${foo}${path.fragment}${filename}" />
</target>
<target name="runjscompile">
<echo message="compile ${destFile}" />
<basename property="file" file="${destFile}" />
<basename property="prefix" file="${destFile}" suffix=".js" />
<dirname property="directory" file="${destFile}" />
<echo message="Compressing file ${file} to ${directory}/${prefix}.min.js" />
<jscomp compilationLevel="simple" debug="false" output="${directory}/${prefix}.min.js" forceRecompile="true">
<sources dir="${directory}">
<file name="${file}" />
</sources>
</jscomp>
</target>
</project>
Add another target which checks the file suffix with a <condition> and sets a property if it matches, then make the jscompile target conditional on that. Following your fileset example you probably want something like:
<target name="check.js">
<condition property="do.jscompile">
<!-- check for filepath that ends .js but not .min.js -->
<matches string="${filepath}" pattern=".*(?<!\.min)\.js$$" />
</condition>
</target>
<target name="build" depends="check.js, transferFile, runjscompile" />
<target name="runjscompile" if="do.jscompile">

nHibernate Master Detail Deletion

I have a Master Detail relationship configured. The hbm file is below. When I run some code like this
Favourite favourite = favourites.Find(f => f.Id== id);
user.Favourites.Remove(favourite);
m_UserRepository.Save(ref user);
I get the error message
NHibernate.Exceptions.GenericADOException: could not delete collection rows: [Model.Entities.User.Favourites#249][SQL: SQL not available] ---> System.Data.SqlClient.SqlException: Cannot insert the value NULL into column 'UserId', table 'BE.Favourite'; column does not allow nulls. UPDATE fails.
Any suggestions on what this means please help.
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Model.Entities" schema="BE" assembly="Model" default-lazy="false">
<class name="Model.Entities.User, Model" table="Users" >
<id name="UserId" column="UserId" type="int" unsaved-value="0">
<generator class="native" />
</id>
<property name="UserName" column="UserName" type="string" />
<bag name="Favourites" cascade="all" lazy="true">
<key column="UserId"/>
<one-to-many class="Model.Entities.Favourite, Model"/>
</bag>
</class>
</hibernate-mapping>
Have you tried setting inverse="true" on your bag?
You actually need a many-to-many relationship in this case:
<class name="User">
<id name="Id">
<generator class="native">
<param name="sequence">object_sequence</param>
</generator>
</id>
<version name="Version" />
<property name="Name" />
<set name="Roles" table="User_Favourite">
<key column="UserId"/>
<many-to-many column="FavouriteId" class="Favourite"/>
</set>
</class>
And the same on the other side: (*note the inverse="true")
<class name="Favourite">
<id name="Id">
<generator class="native">
<param name="sequence">object_sequence</param>
</generator>
</id>
<version name="Version" />
<property name="RoleName" />
<set name="Users" table="User_Favourite" inverse="true">
<key column="FavouriteId"/>
<many-to-many column="UserId" class="User"/>
</set>
</class>
From the NHibernate 2.0 Documentation:
Very Important Note: If the <key> column of a <one-to-many> association is declared NOT NULL, NHibernate may cause constraint violations when it creates or updates the association. To prevent this problem, you must use a bidirectional association with the many valued end (the set or bag) marked as inverse="true". See the discussion of bidirectional associations later in this chapter.
Finally, I'm unsure if you really want to use a bag here. One user can have the same favorite two or more times?
P.S.: Also, note that lazy="true" is the default behavior since NHibernate 1.2.
try changing your cascade rule to:
<bag name="Favourites" cascade="all,delete-orphan" lazy="true">
<key column="UserId" not-null="true"/>
<one-to-many class="Model.Entities.Favourite, Model"/>
</bag>

Resources