0

在下面的代码中,我试图通过使用 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();

  }

}
4

1 回答 1

0

由于您已经声明了 WebDriver 驱动程序;从 WebDriver 中删除 Webdriver driver==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();

}
}

接受它是否对您有用,或者如果这不起作用,请告诉我...谢谢

于 2015-08-19T21:58:45.000 回答