Selenium数据驱动
import org.openqa.selenium.By;<br />import org.openqa.selenium.WebDriver;<br />import org.openqa.selenium.firefox.FirefoxDriver;<br />import org.testng.Assert;<br />import org.testng.Reporter;<br />import org.testng.annotations.AfterMethod;<br />import org.testng.annotations.BeforeMethod;<br />import org.testng.annotations.DataProvider;<br />import org.testng.annotations.Test;<br /><br />public class TestNG {<br /> private WebDriver driver;<br /><br /> @BeforeMethod<br /> //测试之前的准备工作<br /> public void beforeMethod() throws InterruptedException {<br /> System.setProperty("webdriver.firefox.marionette", "src/main/resourcec/geckodriver.exe");<br /> String baiduHomePage;<br /> baiduHomePage = "https://www.baidu.com/";<br /><br /> driver = new FirefoxDriver();<br /> driver.manage().window().maximize();<br /> driver.get(baiduHomePage);<br /> Thread.sleep(2000);<br /> Assert.assertEquals(driver.getTitle(), "百度一下,你就知道");<br /> }<br /><br /> @Test(dataProvider = "word")<br /> //测试用例<br /> public void testNG(String keyword, String case_1, String searchTitle)<br /> throws InterruptedException {<br /> driver.findElement(By.xpath(".//*[@id='kw']")).sendKeys(keyword);<br /> driver.findElement(By.xpath(".//*[@id='su']")).click();<br /> Thread.sleep(2000);<br /><br /> Reporter.log(case_1);<br /> Assert.assertEquals(driver.getTitle(), searchTitle);<br /> }<br /><br /> @AfterMethod<br /> //测试之后的清理工作<br /> public void afterMethod(){<br /> driver.close();<br /> driver.quit();<br /> }<br /><br /> @DataProvider(name = "word")<br /> public static Object[][] data(){<br /> return new Object[][]{{"Selenium", "搜索Selenium的测试用例", "Selenium_百度搜索"},<br /> {"JMeter", "搜索JMeter的测试用例", "JMeter_百度搜索"},<br /> {"Appium", "搜索Appium的测试用例", "Appium_百度搜索"}<br /> };<br /> }<br />}<br /><br />
相关推荐
Lzs 2020-10-23
聚合室 2020-11-16
零 2020-09-18
Justhavefun 2020-10-22
jacktangj 2020-10-14
ChaITSimpleLove 2020-10-06
Andrea0 2020-09-18
周游列国之仕子 2020-09-15
afanti 2020-09-16
88234852 2020-09-15
YClimb 2020-09-15
风雨断肠人 2020-09-04
卖口粥湛蓝的天空 2020-09-15
stulen 2020-09-15
pythonxuexi 2020-09-06
abfdada 2020-08-26
梦的天空 2020-08-25