在下面的代码中,我试图通过使用TestNg的数据驱动框架工作来自动化gmail,但是我的代码@Before注释只执行了其他两个。请告诉我。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table border="1" id="staff">
<thead>
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
</thead>
<tbody>
<tr id="1">
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr id="2">
<td>Berglunds snabbköp</td>
<td>Christina Berglund</td>
<td>Sweden</td>
</tr>
<tr id="5">
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
<tr id="8">
<td>Ernst Handel</td>
<td>Roland Mendel</td>
<td>Austria</td>
</tr>
<tr id="9">
<td>Island Trading</td>
<td>Helen Bennett</td>
<td>UK</td>
</tr>
<tr id="12">
<td>Königlich Essen</td>
<td>Philip Cramer</td>
<td>Germany</td>
</tr>
<tr id="13">
<td>Laughing Bacchus Winecellars</td>
<td>Yoshi Tannamuri</td>
<td>Canada</td>
</tr>
<tr id="15">
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
<tr id="16">
<td>North/South</td>
<td>Simon Crowther</td>
<td>UK</td>
</tr>
</tbody>
</table>
答案 0 :(得分:0)
因为您已经声明了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();
}
}
接受它是否适合您或让我知道这是否有效...... 感谢