Multiple classes with same driver instance

352 views
Skip to first unread message

Pavithra

unread,
Nov 13, 2015, 1:09:53 AM11/13/15
to testng-users
Hi all,
I am trying to run multiple classes inside my <test> and I am instantiating the driver (which is initialised as public variable) @BeforeTest and quitting in AfterTest.

I have 4 classes inside my TestNG.xml as below:
<suite>
<test>
<classes>
<class1/>
<class2/>
<class3/>
<class4/>
</classes>
</test>
</suite>

TestNG Version: 6.9.9

It runs the first three class without any issues. At the end of 3rd test, for some reason it fails (my after method is not getting called) and I see it is just going to After Test and doing driver.quit.
3rd class - After method not running (but it just goes to my TestListener - OnConfiguration failure). However I don't see no failure.
4th class - not being called (may be because of above failure) - but it doesnt even say that 4th class is being skipped.
Not showing any output related to failure or skip (in my suite report)
Emailable report not getting generated at all (when there is any failure or skip in my tests)

Kindly let me know if anyone has ideas or solution for the above issue.

Thanks,
Pavithra


Krishnan Mahadevan

unread,
Nov 13, 2015, 1:37:29 AM11/13/15
to testng...@googlegroups.com
Pavithra,

Can you please create a sample project which when executed can demonstrate this problem and perhaps post it on github ? I can try taking a look to see what may be going wrong.
Having a common webdriver instance being created at the <test> level to me sounds problematic. I say this because all of your test classes are now going to be literally competing with each other to work with the same webdriver instance [ especially if you resorting to parallel executions ]

Couple of things you can try :

Is the failure always at the 3rd class ? What happens if you re-order your classes such that the 3rd class runs first [ For this to happen you would need to disable parallelism and resort to using preserve-order = true ]

Are you gobbling up exception at any point which perhaps explains why you don't see any failures ?

Reporting listener [ emailable report gets generated as part of a default Reporting listener that TestNG invokes on its own ] is expected to run at all times. The only time when it would not run is if you have configured your project to disable all default listeners.

On the whole there are a lot of grey areas for which we dont have sufficient information. So posting a sample project is definitely something you should do.





Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

Pavithra Navaneeth

unread,
Nov 13, 2015, 1:59:04 AM11/13/15
to testng...@googlegroups.com
Thanks Krishnan for the info 😊 I would post the sample project once I am in front of my system. 

To answer your questions:

I create the driver instance in before test and putting the same in hasp map and for parallel runs - I created threads and calling current thread inside my test method.

During this run - this is just for single run (not parallel) and preserve order is set to true. 

I tried calling classes in testNG in different order - say I have put that in my second class and during the end of second class it happens again. Hence tried running that class alone which didn't created any issue. Also tried with just two classes - with problematic class as first class - again it ran properly. It happens only when I have all 4 classes.

I have my default reporting enabled in my listener. When I just run single classes or two classes - it creates emailable report properly. This doesn't get created only if any of my test fails. Not sure whether it's because of specific TestNG version.

I am using log4j logger and even reporter.log but still in this specific case I am not seeing any exceptions. For other failures - I do see.

Thanks
Pavithra
Sent from my iPhone
You received this message because you are subscribed to a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/testng-users/HSvXlGf5qgM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to testng-users...@googlegroups.com.

Krishnan Mahadevan

unread,
Nov 13, 2015, 2:01:21 AM11/13/15
to testng...@googlegroups.com
That's really interesting. Can't wait to see the sample code so that I can take a dig at this one 😁

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

Marina Touceda

unread,
Dec 1, 2015, 1:45:20 PM12/1/15
to testng-users
Hi. There!
Have you found a solution to this. I believe I have a similar issue.When I run the testng xml, the drivers fail and my test does not work. When I run them individually they do. I have issues with the driver.
How should I implement it?
I have instanciate it in a common class, and then I extend that class in each test.I use a @BeforeTest and @AfterTest to open the URL. run the test and close it.
Any advice, I will be grateful!

Krishnan Mahadevan

unread,
Dec 1, 2015, 9:33:03 PM12/1/15
to testng...@googlegroups.com
Marina,
Can you please share sample code that shows us what you are running with and if needed can be executed to simulate the problem.
Please feel free to add as much as contextual information as possible.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

Reply all
Reply to author
Forward
0 new messages