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"
Related
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 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>
I have 2 classes like this :
Message(id, title, content)
MessageEmployee(id, messageId, employeeId, readFlag)
and 2 tables like this :
MESSAGE(mess_id, mess_title, mess_content)
MESSAGE_EMPLOYEE(mess_empl_id, mess_id, empl_id, read_fg)
Mapping files :
<hibernate-mapping package="core">
<class name="Message" table="MESSAGE">
<!-- class id -->
<id name="id" type="int" column="MESS_ID" length="11">
<generator class="native"/>
</id>
<property name="content" type="string" column="MESS_CONTENT" />
<property name="title" type="string" column="MESS_TITLE" />
</class>
</hibernate-mapping>
<hibernate-mapping package="core">
<class name="MessageEmployee" table="MESSAGE_EMPLOYEE">
<!-- class id -->
<id name="id" type="int" column="MESS_EMPL_ID" length="11">
<generator class="native"/>
</id>
<!-- employee -->
<many-to-one name="employee" class="core.Employee"
column="EMPL_ID" cascade="save-update,merge" lazy="false" />
<!-- message -->
<many-to-one name="message" class="core.Message"
column="MESS_ID" cascade="save-update,merge" lazy="false" />
<property name="readFlag" type="character" column="READ_FG" />
</class>
</hibernate-mapping>
Here is my problem :
let's say I already have a message in database, and I want to create a messageEmployee and save it.
Code snippet :
Message sent = new Message(content, title);
Employee e = employeeDao.loadEmployeeWithId(Integer.valueOf(to));
messageDao.merge(sent)
MessageEmployee m = new MessageEmployee(sent, e, null);
m.setReadFlag('N');
messageEmployeeDao.mergeMessageEmploye(m);
When I merge(messageEmployee), it creates a new message and a new messageEmployee in database, but I don't want it to create a new message.
I'm quite sure my mapping is wrong since I am no expert, so what could I change to get the behaviour I want ?
It will create a new Message object because you are not providing id in your message object sent. When you execute messageDao.merge(sent), the sent object doesn't have and id to merge with. It is pure transient object. Try loading it from database like Employee.
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>