is there a way to use the same webdriver object for multiple java classes when running within a testng suite?

10,722

Put all your classes in a <test> tag and initialize the driver in a @BeforeTest method which you store in the base class so that all your test methods can access it.

Share:
10,722
Manpreet Singh
Author by

Manpreet Singh

Updated on June 04, 2022

Comments

  • Manpreet Singh
    Manpreet Singh almost 2 years

    is there a way to use the same webdriver object for multiple tests/classes when run within a testng suite? What I mean is to start the WebDriver instance with one class, but continue using it over subsequent classes/tests in the suite?

    The problem I am facing is that 10 differect classes have this statement:

    WebDriver driver = new FirefoxDriver();

    and it open 10 different instances even after I restrict TestNG with parallel mode set a s false. It really sucks up my system memory.

    I wat a solution to use same WebDriver and run different classes over without having to multiple browser and Webdriver insntances.