Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3242620
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:20:12+00:00 2026-05-17T18:20:12+00:00

In using TestNG for my Selenium framework, the setUp method is relatively complex. There

  • 0

In using TestNG for my Selenium framework, the setUp method is relatively complex. There are multiple points that it can break and I would like to split it into separate steps.

Ideally it would look something like this:

// Does some DB stuff, logs some messages
@BeforeMethod(alwaysRun = true)
preTestCase


// Instantiates and opens up Selenium
@BeforeMethod(dependsOnMethods = {"preTestCase"})
seleniumSetup


// Closes Selenium only if it was properly setup
@AfterMethod(dependsOnMethods = {"seleniumSetup"})
seleniumTearDown


// All other test case teardown, error logging
@AfterMethod(alwaysRun=true)
postTestCase

What I want to avoid is failing in preTestCase due to a DB issue and then getting a secondary failure due to seleniumTearDown trying to close a non-existent instance. In that situation, only postTestCase should be run. I am getting this error: seleniumTearDown() is not allowed to depend on public void seleniumSetUp(org.testng.ITestContext). Is this not allowed / bad design? How do I enforce run-order between the two tearDown methods so that postTestCase() is always run last, regardless of if seleniumTearDown is run?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T18:20:12+00:00Added an answer on May 17, 2026 at 6:20 pm

    Your model seems a little washy, Setup and Teardown shouldn’t fail. Although they could possibly no-op. As in; “Attempted to make a db connection, wasn’t available so did nothing instead” then in tear down you should check if their is a connection before attempting to close it.

    Otherwise if you want to maintain your current model you could use some sort of manual check instead of the annotation (a boolean or a singleton class would work).

    In Setup:
    if(dbGetConnected()) {
    ....
    } else {
      dbisntconnected = true;
    }
    
    In tearDown:
    if(!dbisntconnected) {
        dbClose();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Selenium RC with Java using TestNG as Test Framework. I'm using
I am using Selenium WebDriver with Java & TestNG framework. I want to use
I have created a project in Eclipse for Selenium automation using testNG framework. I
I have 4 selenium projects that starts from command line using TestNG at same
My code in Visual studio is using selenium webdriver 2.24.0. My testing framework I'm
I'm using Selenium WebDriver with Testng (started using an .xml file) to test a
I am using selenium rc in eclipse with testNG. I need to click on
I am testing an application using Selenium IDE. There is a table with unstable
Currently I'm using TestNG framework for testing application business logic, i added some Servlet
I'm using TestNG to run Selenium based tests in Java. I have a bunch

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.