0

I have a testNG suite with more than 10 classes. When I start testNG.xml as a suite, the browsers(ff) not closing before going to 2nd class where I have used to open the browser and close it in every class. I have tested it with giving only one class the browser is closed. Please check the below code for @AfterTest

@BeforeClass(alwaysRun = true)
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://www.example.com";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

@Test(priority=0)
public void testActivityMasterDBCheck() throws Exception {
--------------------
--------------------
@AfterTest
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) 
{
fail(verificationErrorString);
}
}

and XML is 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test name="Test">
<classes>
  <class name="Admin.ManagePackagesDBCheck"/>
  <class name="Reports.ActiveStatusReportDBCheck"/>
  ----------
 </classes>
 </test> <!-- Test -->
 </suite> <!-- Suite -->

2 Answers2

1

Use @AfterClass annotation like this:

@AfterClass
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) 
{
fail(verificationErrorString);
}
}
optimistic_creeper
  • 2,739
  • 3
  • 23
  • 37
0

Do that @AfterClass and (alwaysRun = true). Reason your browser may not be closing is simple, you are using one driver instance to initiate the browser. So once your execution is over, the next class will start execution, but your is not over yet. So try using @AfterClass or @AfterMethod. I would suggest @AfterClass as, you are initiating your driver @BeforeClass

Hope that helps.

Mayur Shah
  • 518
  • 3
  • 8
  • No, its not closing. i have deleted alwaysRun = true from BeforeClass and AfterClass---------------@BeforeClass public void setUp() throws Exception { driver = new FirefoxDriver();-------------------@AfterClass public void tearDown() throws Exception { driver.quit(); String verificationErrorString = verificationErrors.toString(); if (!"".equals(verificationErrorString)) { fail(verificationErrorString); } } – Suneel Kuppili Nov 24 '16 at 13:58
  • Is your test failing? What error do you get while executing test? – Mayur Shah Nov 24 '16 at 15:05
  • Not failing, the browsers are remaining opened for all the classes which were run and after running several classes, the browsers are struck! If I have 20 scripts/classes in single testng.xml, the browsers are not closing so after running 10 classes fro example, due to load on firefox, it is struck up! – Suneel Kuppili Nov 25 '16 at 05:54
  • Are you executing in parallel? Can you post your testng.xml with all 20 classes? – Mayur Shah Nov 25 '16 at 05:56
  • its too long to paste here, the same above testng.xml, but with 20 class names – Suneel Kuppili Nov 25 '16 at 06:06
  • okay. are you trying to execute those in parallel? Can you post your driver declaration? – Mayur Shah Nov 25 '16 at 06:26
  • not parallel, I am right clicking on testng.xml and run as testng test. so that it will run one by one. – Suneel Kuppili Nov 25 '16 at 10:13
  • Can anybody please help on this? – Suneel Kuppili Dec 13 '16 at 10:09