TestNG执行测试用例的顺序

任意键 2018-01-20

import org.openqa.selenium.By;<br />import org.openqa.selenium.WebDriver;<br />import org.openqa.selenium.WebElement;<br />import org.openqa.selenium.firefox.FirefoxDriver;<br />import org.testng.Assert;<br />import org.testng.Reporter;<br />import org.testng.annotations.*;<br /><br />public class TestNG {<br />    private WebDriver driver;<br /><br />    @BeforeClass<br />    public void beforeClass() throws InterruptedException {<br />        System.setProperty("webdriver.firefox.marionette",<br />                "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(priority = 3)<br />    //预期会第3次执行<br />    public void testNG_1() throws InterruptedException {<br />        WebElement webElement = driver.findElement(By.xpath(".//*[@id='kw']"));<br />        webElement.clear();<br />        webElement.sendKeys("Selenium");<br /><br />        driver.findElement(By.xpath(".//*[@id='su']")).click();<br />        Thread.sleep(3000);<br /><br />        Reporter.log("搜索Selenium的测试用例");<br />        Assert.assertEquals(driver.getTitle(), "Selenium_百度搜索");<br />        driver.navigate().refresh();<br />    }<br /><br />    @Test(priority = 2)<br />    //预期会第2次执行<br />    public void testNG_2() throws InterruptedException {<br />        WebElement webElement = driver.findElement(By.xpath(".//*[@id='kw']"));<br />        webElement.clear();<br />        webElement.sendKeys("JMeter");<br /><br />        driver.findElement(By.xpath(".//*[@id='su']")).click();<br />        Thread.sleep(3000);<br /><br />        Reporter.log("搜索JMeter的测试用例");<br />        Assert.assertEquals(driver.getTitle(), "JMeter_百度搜索");<br />        driver.navigate().refresh();<br />    }<br /><br />    @Test(priority = 1)<br />    //预期会第1次执行<br />    public void testNG_3() throws InterruptedException {<br />        WebElement webElement = driver.findElement(By.xpath(".//*[@id='kw']"));<br />        webElement.clear();<br />        webElement.sendKeys("Appium");<br /><br />        driver.findElement(By.xpath(".//*[@id='su']")).click();<br />        Thread.sleep(3000);<br /><br />        Reporter.log("搜索Appium的测试用例");<br />        Assert.assertEquals(driver.getTitle(), "Appium_百度搜索");<br />        driver.navigate().refresh();<br />    }<br /><br />    @AfterClass<br />    public void afterClass(){<br />        driver.close();<br />        driver.quit();<br />    }<br /><br />}<br /><br />
TestNG执行测试用例的顺序
 

相关推荐

zhengzf0 / 0评论 2011-02-24
spring艳 / 0评论 2019-06-21
MAGI的专栏 / 0评论 2018-01-20