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
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"
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>
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>
When I test my project, just 4 tables are created in the database but not the others and I do not know why. The tables notification, position, dernierePosition and user are created but not the table demande and other tables that I didn't put in this example. There are some properties that i forgot?
Thanks for your help.
Here are some files:
hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="">
<!-- Database connection settings, Connect to HSQL, IN Memory -->
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/***</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.username">***</property>
<property name="hibernate.connection.password"/>
<!-- DB schema will be updated if needed -->
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- JDBC connection pool (use the built-in)
List of XML mapping files -->
<mapping class="modele.Demande" resource="Demande.hbm.xml"/>
<mapping class="modele.DernierePosition" resource="DernierePosition.hbm.xml"/>
<mapping class="modele.Group" resource="Group.hbm.xml"/>
<mapping class="modele.Invitation" resource="Invitation.hbm.xml"/>
<mapping class="modele.Marqueur" resource="Marqueur.hbm.xml"/>
<mapping class="modele.Notification" resource="Notification.hbm.xml"/>
<mapping class="modele.NotificationMarqueur" resource="NotificationMarqueur.hbm.xml"/>
<mapping class="modele.Position" resource="Position.hbm.xml"/>
<mapping class="modele.User" resource="User.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Position.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 15 févr. 2014 01:46:28 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="modele.Position" table="POSITION">
<id name="id" type="int">
<column name="ID" />
<generator class="native" />
</id>
<property name="lattitude" type="double">
<column name="LATTITUDE" />
</property>
<property name="longitude" type="double">
<column name="LONGITUDE" />
</property>
</class>
</hibernate-mapping>
DenierePosition.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 15 févr. 2014 01:46:28 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<joined-subclass name="modele.DernierePosition" extends="modele.Position" table="DERNIEREPOSITION" lazy="false">
<key>
<column name="ID" />
</key>
<property name="time" type="java.util.Date">
<column name="TIME" />
</property>
<one-to-one name="user" class="modele.User"></one-to-one>
</joined-subclass>
</hibernate-mapping>
Notification.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 15 févr. 2014 01:46:28 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="modele.Notification" table="NOTIFICATION">
<id name="id" type="int">
<column name="ID" />
<generator class="native" />
</id>
<many-to-one name="user" class="modele.User" fetch="join">
<column name="USER" />
</many-to-one>
</class>
</hibernate-mapping>
Demande.java
#XmlRootElement
public class Demande extends Notification {
private Group group;
private User demandeur;
public Demande(){
}
public Demande(Group group, User demandeur) {
super(group.getProprietaire());
this.group = group;
this.demandeur=demandeur;
}
// Getters and setters
}
Demande.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 15 févr. 2014 01:46:28 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<joined-subclass name="modele.Demande" extends="modele.Notification" table="DEMANDE" lazy="false">
<key>
<column name="ID" />
</key>
<many-to-one name="group" class="modele.Group" fetch="join">
<column name="GROUP" />
</many-to-one>
<many-to-one name="demandeur" class="modele.User" fetch="join">
<column name="DEMANDEUR" />
</many-to-one>
</joined-subclass>
</hibernate-mapping>
User.java
#XmlRootElement
public class User {
/** Attributs */
private int id;
private String pseudo;
private String telephone;
private String email;
#XmlTransient
private Set<Demande> demandes;
#XmlTransient
private Set<Invitation> aInvite;
#XmlTransient
private Set<Notification> notifications;
private DernierePosition dernierePosition;
#XmlTransient
private Set<Group> groups;
#XmlTransient
private Set<Group> proprietaire;
/** Constructeur */
public User() {
}
public User(String telephone, String pseudo, String email) {
super();
this.pseudo = pseudo;
this.telephone = telephone;
this.email = email;
}
// Getters and setters
}
User.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 15 févr. 2014 01:46:28 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="modele.User" table="USER">
<id name="id" type="int">
<column name="ID" />
<generator class="native" />
</id>
<property name="pseudo" type="java.lang.String">
<column name="PSEUDO" />
</property>
<property name="telephone" type="java.lang.String" not-null="true" unique="true">
<column name="TELEPHONE" />
</property>
<property name="email" type="java.lang.String">
<column name="EMAIL" />
</property>
<set name="demandes" table="DEMANDE" inverse="false" lazy="true">
<key>
<column name="ID" />
</key>
<one-to-many class="modele.Demande" />
</set>
<set name="aInvite" table="INVITATION" inverse="false" lazy="true" access="field">
<key>
<column name="ID" />
</key>
<one-to-many class="modele.Invitation" />
</set>
<set name="notifications" table="NOTIFICATION" inverse="false" lazy="true">
<key>
<column name="ID" />
</key>
<one-to-many class="modele.Notification" />
</set>
<one-to-one name="dernierePosition" class="modele.DernierePosition"></one-to-one>
<set name="groups" table="GROUP" inverse="false" lazy="true">
<key>
<column name="ID" />
</key>
<one-to-many class="modele.Group" />
</set>
<set name="proprietaire" table="GROUP" inverse="false" lazy="true">
<key>
<column name="ID" />
</key>
<one-to-many class="modele.Group" />
</set>
</class>
</hibernate-mapping>
Group.java
#XmlRootElement
public class Group {
/** Attributs */
private int id;
private String description;
private String hashtag;
private String password;
private Set<Marqueur> marqueurs;
#XmlTransient
private Set<Invitation> invitations;
#XmlTransient
private Set<Demande> demandes;
private User proprietaire;
private Set<User> invites;
/**
* Constructeur
* */
public Group()
{
}
public Group(String description, String hashtag, User proprietaire, String password) {
super();
this.description = description;
this.hashtag = hashtag;
this.proprietaire = proprietaire;
this.setPassword(password);
}
Group.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 16 f?vr. 2014 11:30:30 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="modele.Group" table="GROUP">
<id name="id" type="int">
<column name="ID" />
<generator class="assigned" />
</id>
<property name="description" type="java.lang.String">
<column name="DESCRIPTION" />
</property>
<property name="hashtag" type="java.lang.String">
<column name="HASHTAG" />
</property>
<property name="password" type="java.lang.String">
<column name="PASSWORD" />
</property>
<set name="marqueurs" table="MARQUEUR" inverse="false" lazy="true">
<key>
<column name="ID" />
</key>
<one-to-many class="modele.Marqueur" />
</set>
<set name="invitations" table="INVITATION" inverse="false" lazy="true">
<key>
<column name="ID" />
</key>
<one-to-many class="modele.Invitation" />
</set>
<many-to-one name="proprietaire" class="modele.User" fetch="join">
<column name="PROPRIETAIRE" />
</many-to-one>
<set name="invites" table="USER" inverse="false" lazy="true">
<key>
<column name="ID" />
</key>
<one-to-many class="modele.User" />
</set>
</class>
</hibernate-mapping>
Test User
package dao;
import java.util.List;
import junit.framework.Assert;
import modele.User;
import org.junit.Test;
public class UserDaoTest {
private final String tel = "0601020304";
private final String pseudo = "pseudo";
private final String pseudoModified = "pseudo2";
private final String email = "email#email.com";
#Test
public void addUserTest(){
User initialUser = new User(tel, pseudo, email);
UserDao.addUser(initialUser);
User addedUser = UserDao.getUser(tel);
Assert.assertEquals(addedUser.getTelephone(), initialUser.getTelephone());
Assert.assertEquals(addedUser.getPseudo(), initialUser.getPseudo());
Assert.assertEquals(addedUser.getEmail(), initialUser.getEmail());
}
#Test
public void modifyUserTest(){
UserDao.modifyUser(tel, pseudoModified, email);
User modifiedUser = UserDao.getUser(tel);
Assert.assertEquals(modifiedUser.getTelephone(), tel);
Assert.assertEquals(modifiedUser.getPseudo(), pseudoModified);
Assert.assertEquals(modifiedUser.getEmail(), email);
}
#Test
public void listUserTest(){
User modifiedUser = UserDao.getUser(tel);
List<User> listUsers = UserDao.listUser();
User listedUser = listUsers.get(listUsers.indexOf(modifiedUser));
Assert.assertEquals(listedUser.getTelephone(), modifiedUser.getTelephone());
Assert.assertEquals(listedUser.getPseudo(), modifiedUser.getPseudo());
Assert.assertEquals(listedUser.getEmail(), modifiedUser.getEmail());
}
#Test
public void deleteUserTest(){
User user = UserDao.getUser(tel);
UserDao.deleteUser(user.getTelephone());
List<User> listUsers = UserDao.listUser();
Assert.assertEquals(listUsers.indexOf(user), -1);
}
}
It seems that there's a problem with many-to-one and joined-subclass. It's explained in detail over on the hibernate forums; I'm not entirely clear on why it's the case, but the explanation from sdknott (on that site) is:
The problem you have is with your mapping. By stating that your constraining column of the many-to-one is in fact your primary key column of table A, Hibernate will always try and resolve an entity B since the many-to-one column will never be empty.
I've used your source and changed the various many-to-one mappings in joined-subclasses to one-to-one mappings, and it all works for me now. Hopefully that will allow you to express your schema correctly.
(Aside) Original answer that didn't solve the problem
I see that you have two members called "user" in the Demande class; remember that Demande is a subclass of Notification and gets its members. I've never tried that and it looks odd, and it's definitely going to be confusing. It might be what's causing your problem.
If you really want two "user" members, give them more suitable names (maybe "requester" and "responder"? Just guessing from the context). If you only want one "user", then you don't need to put it in Demande, it's already in Notification.