zoukankan      html  css  js  c++  java
  • TestNG执行测试用例的顺序

    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(priority = 3)
    //预期会第3次执行
    public void testNG_1() throws InterruptedException {
    WebElement webElement = driver.findElement(By.xpath(".//*[@id='kw']"));
    webElement.clear();
    webElement.sendKeys("Selenium");

    driver.findElement(By.xpath(".//*[@id='su']")).click();
    Thread.sleep(3000);

    Reporter.log("搜索Selenium的测试用例");
    Assert.assertEquals(driver.getTitle(), "Selenium_百度搜索");
    driver.navigate().refresh();
    }

    @Test(priority = 2)
    //预期会第2次执行
    public void testNG_2() throws InterruptedException {
    WebElement webElement = driver.findElement(By.xpath(".//*[@id='kw']"));
    webElement.clear();
    webElement.sendKeys("JMeter");

    driver.findElement(By.xpath(".//*[@id='su']")).click();
    Thread.sleep(3000);

    Reporter.log("搜索JMeter的测试用例");
    Assert.assertEquals(driver.getTitle(), "JMeter_百度搜索");
    driver.navigate().refresh();
    }

    @Test(priority = 1)
    //预期会第1次执行
    public void testNG_3() throws InterruptedException {
    WebElement webElement = driver.findElement(By.xpath(".//*[@id='kw']"));
    webElement.clear();
    webElement.sendKeys("Appium");

    driver.findElement(By.xpath(".//*[@id='su']")).click();
    Thread.sleep(3000);

    Reporter.log("搜索Appium的测试用例");
    Assert.assertEquals(driver.getTitle(), "Appium_百度搜索");
    driver.navigate().refresh();
    }

    @AfterClass
    public void afterClass(){
    driver.close();
    driver.quit();
    }

    }

    
    
  • 相关阅读:
    Django学习路31_使用 locals 简化 context 写法,点击班级显示该班学生信息
    Django学习路30_view中存在重复名时,取第一个满足条件的
    【Python】基本统计值计算

    [CTSC2016]萨菲克斯·阿瑞
    Linux与WIN 网络连接 winscp 的连接问题
    MFC 文件详解
    Hadoop入门学习随笔
    Scala入门学习随笔
    大数据用到的技术
  • 原文地址:https://www.cnblogs.com/yjlch1016/p/8322059.html
Copyright © 2011-2022 走看看