import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.Reporter;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class TestNG {
private WebDriver driver;

@BeforeMethod
//测试之前的准备工作
public void beforeMethod() 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(dataProvider = "word")
//测试用例
public void testNG(String keyword, String case_1, String searchTitle)
throws InterruptedException {
driver.findElement(By.xpath(".//*[@id='kw']")).sendKeys(keyword);
driver.findElement(By.xpath(".//*[@id='su']")).click();
Thread.sleep(2000);

Reporter.log(case_1);
Assert.assertEquals(driver.getTitle(), searchTitle);
}

@AfterMethod
//测试之后的清理工作
public void afterMethod(){
driver.close();
driver.quit();
}

@DataProvider(name = "word")
public static Object[][] data(){
return new Object[][]{{"Selenium", "搜索Selenium的测试用例", "Selenium_百度搜索"},
{"JMeter", "搜索JMeter的测试用例", "JMeter_百度搜索"},
{"Appium", "搜索Appium的测试用例", "Appium_百度搜索"}
};
}
}

 

    

  
内容来源于网络如有侵权请私信删除
你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!