TestNG執行測試用例的順序
阿新 • • 發佈:2018-01-20
itl send .get err ndk interrupt row setprop property
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.Reporter;
import org.testng.annotations.*;
public class TestNG {
private WebDriver driver;
@BeforeClass
public void beforeClass() throws InterruptedException {
System.setProperty("webdriver.firefox.marionette",
"src/main/resourcec/geckodriver.exe");
String baiduHomePage;
baiduHomePage = "https://www.baidu.com/";
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get(baiduHomePage);
Thread.sleep(2000);
Assert.assertEquals(driver.getTitle(), "百度一下,你就知道");
}
@Test(priority = 3)
//預期會第3次執行
public void testNG_1() throws InterruptedException {
WebElement webElement = driver.findElement(By.xpath(".//*[@id=‘kw‘]"));
webElement.clear();
webElement.sendKeys("Selenium");
driver.findElement(By.xpath(".//*[@id=‘su‘]")).click();
Thread.sleep(3000);
Reporter.log("搜索Selenium的測試用例");
Assert.assertEquals(driver.getTitle(), "Selenium_百度搜索");
driver.navigate().refresh();
}
@Test(priority = 2)
//預期會第2次執行
public void testNG_2() throws InterruptedException {
WebElement webElement = driver.findElement(By.xpath(".//*[@id=‘kw‘]"));
webElement.clear();
webElement.sendKeys("JMeter");
driver.findElement(By.xpath(".//*[@id=‘su‘]")).click();
Thread.sleep(3000);
Reporter.log("搜索JMeter的測試用例");
Assert.assertEquals(driver.getTitle(), "JMeter_百度搜索");
driver.navigate().refresh();
}
@Test(priority = 1)
//預期會第1次執行
public void testNG_3() throws InterruptedException {
WebElement webElement = driver.findElement(By.xpath(".//*[@id=‘kw‘]"));
webElement.clear();
webElement.sendKeys("Appium");
driver.findElement(By.xpath(".//*[@id=‘su‘]")).click();
Thread.sleep(3000);
Reporter.log("搜索Appium的測試用例");
Assert.assertEquals(driver.getTitle(), "Appium_百度搜索");
driver.navigate().refresh();
}
@AfterClass
public void afterClass(){
driver.close();
driver.quit();
}
}
TestNG執行測試用例的順序