@BeforeThread

42 views
Skip to first unread message

edwolb

unread,
Sep 12, 2012, 11:05:29 AM9/12/12
to testng...@googlegroups.com
We're using TestNG with Selenium, and need to do certain things to setup a browser before a test.  In some cases, we want to parallelize based on classes, but we have some tests that have many iterations of data that take a long time, and we would like to parallelize them with methods instead.  However it would be ideal if we could setup the test to be able to setup based on a parallel of methods or classes.

The only way I can think of is to setup a @BeforeClass as well as a @BeforeMethod, and do an XmlSuite.getParallel to detect one of the other, but this gets really messy.  Is there a better way to say "when starting a new thread, whether its as part of a parallel class or method, setup a new browser window"?

--
Chris

Krishnan Mahadevan

unread,
Sep 13, 2012, 3:15:40 AM9/13/12
to testng...@googlegroups.com
Chris,
I dont think there is anything within TestNG that gives you this, out of the box. You may have to build this logic on your own.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"



--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/8KfBNl06O3IJ.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

niharika varshney

unread,
Sep 13, 2012, 5:58:08 AM9/13/12
to testng...@googlegroups.com
Wouldn't creating different tests in the xmlsuite help your problem..something like

<test name="SlowTests" annotations="JDK" parallel="methods">
and another with  
<test name="FastTests" annotations="JDK" parallel="classes"> 

And probably add a TestListener to do setup based on the test name?

Apologies if I didn't get the actual issue :)

Regards,
Niharika

edwolb

unread,
Sep 19, 2012, 9:23:13 AM9/19/12
to testng...@googlegroups.com
As I understand it, TestListeners receive the result of the test once its been completed.  What I was looking to do was to be able to control browser and test setup based on the parallel test setting, rather than hardcoding it into our test architecture as @BeforeClass or @BeforeMethod.

It seems this is more complex than I may have first thought.  For example, if I dynamically move a @BeforeClass to a @BeforeMethod, then there is no need for an @AfterMethod that performs a cleanup, since the cleanup in this case would be the closure of the browser.  Since this introduces some logical changes, it'd be difficult to do it dynamically.

--
Chris

Roman Hiden

unread,
Sep 26, 2012, 4:23:30 PM9/26/12
to testng...@googlegroups.com
ITestListeners receive test results in realTime or closed to that. IReporter extends ITestListener and generatesReport at the end of the run
Reply all
Reply to author
Forward
0 new messages