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_百度搜索"}
};
}
}

Selenium数据驱动

 


 
                    
            
                

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-16
  • 2022-03-03
  • 2021-08-21
  • 2022-12-23
  • 2021-07-08
  • 2021-09-30
  • 2022-01-09
相关资源
相似解决方案