51Testing软件测试论坛
标题:
使用testng.xml组织测试用例
[打印本页]
作者:
yjlch1016
时间:
2018-1-24 16:06
标题:
使用testng.xml组织测试用例
使用testng.xml组织测试用例
测试用例类TeseNG.java:
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(dataProvider = "word")
public void testNG(String keyword, String case_1, String searchTitle)
throws InterruptedException {
WebElement webElement = driver.findElement(By.xpath(".//*[@id='kw']"));
webElement.clear();
webElement.sendKeys(keyword);
driver.findElement(By.xpath(".//*[@id='su']")).click();
Thread.sleep(3000);
Reporter.log(case_1);
Assert.assertEquals(driver.getTitle(), searchTitle);
driver.navigate().refresh();
}
@AfterClass
public void afterClass(){
driver.close();
driver.quit();
}
@DataProvider(name = "word")
public static Object[][] data(){
return new Object[][]{{"Selenium", "搜索Selenium的测试用例", "Selenium_百度搜索"},
{"JMeter", "搜索JMeter的测试用例", "JMeter_百度搜索"},
{"Appium", "搜索Appium的测试用例", "Appium_百度搜索"}
};
}
}
testng.xml文件:<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="百度搜索的测试计划" verbose="2" preserve-order="true">
<test name="分别搜索Selenium/JMeter/Appium的测试用例">
<classes>
<class name="TestNG" />
</classes>
</test>
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter" />
<listener class-name="org.uncommons.reportng.JUnitXMLReporter" />
</listeners>
</suite>
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2