任何人都可以帮助我,我的 Test Ng 注释不是 运行 。在下面的代码中,我的 @before class 只有 运行 而不是其他

Can any one help me , my Test Ng annotations are not running .In the Below code my @before class only running but not other

在下面的代码中,我尝试使用 TestNg 通过数据驱动的框架工作来自动化 gmail,但我的代码 @Before 注释只执行而不执行其他两个。请帮助我。

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;

public class LoginData  {
WebDriver driver;
  @Test
  public void login() {

      driver.findElement(By.linkText("Sign in")).click();
      System.out.println("hello");
  }
  @BeforeTest
  public void beforeTest() throws Exception  {
      WebDriver driver=new FirefoxDriver();
      driver.get("https://www.gmail.com/intl/en/mail/help/about.html");
      Thread.sleep(2000);


  }

  @AfterTest
  public void fterTest() {
      driver.close();

  }

}

因为你已经声明了 WebDriver 驱动; 从 WebDriver 驱动程序中删除 Webdriver==new FirefoxDriver();

我在下面尝试并为我工作。

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;

public class LoginData1  {
WebDriver driver;


@Test
public void login() {

    driver.findElement(By.linkText("Sign in")).click();
    System.out.println("hello");
}
@BeforeTest
public void beforeTest() throws Exception  {
    driver=new FirefoxDriver();
    driver.get("https://www.gmail.com/intl/en/mail/help/about.html");
    Thread.sleep(2000);


}

@AfterTest
public void fterTest() {
    driver.close();

}
}

如果它对你有用,请接受,如果这不起作用,请告诉我... 谢谢