zoukankan      html  css  js  c++  java
  • Selenium数据驱动

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

    
    
  • 相关阅读:
    监控Nginx
    监控Tomcat
    监控memcache
    监控Redis
    14-SpringCloud Bus
    13-SpringCloud Config
    12-SpringCloud GateWay
    11-SpringCloud Hystrix
    10-SpringCloud OpenFeign
    09-SpringCloud Ribbon
  • 原文地址:https://www.cnblogs.com/yjlch1016/p/8321204.html
Copyright © 2011-2022 走看看