user7739551
user7739551

Reputation: 1

driver object in the susbsequent test method is not getting executed

public class One {

    public WebDriver driver;

    @Test 
    public void test1() {
        /*System.setProperty("webdriver.chrome.driver", "Y:\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();*/

        driver.findElement(By.id("username")).sendKeys("[email protected]");
        driver.findElement(By.id("password")).sendKeys("password!1");
        System.out.println("im in first test case from demoTwo Class");
    }

    @BeforeMethod 
    public void test() {
        System.setProperty("webdriver.chrome.driver", "Y:\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();

        driver.get("https://app.anywebsite.com");
        System.out.println("im in first test case from demoONE Class");
    }

    @AfterMethod
    public void afterMethod() {

        // Close the driver
        driver.quit();
    }
}
  1. How do I pass the driver object to subsequent test methods?

  2. Sample code available for testng on web shows this kind of structure but none executes.

Upvotes: 0

Views: 25

Answers (1)

Tung Thanh
Tung Thanh

Reputation: 36

You just set your driver by this way:

@BeforeMethod 
public void test() {
    System.setProperty("webdriver.chrome.driver", "Y:\\chromedriver.exe");
    this.driver = new ChromeDriver();

    driver.get("https://app.anywebsite.com");
    System.out.println("im in first test case from demoONE Class");
}

Upvotes: 1

Related Questions