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

    
    
  • 相关阅读:
    csrf漏洞
    WebServer远程部署
    URL跳转与钓鱼
    代码注入
    暴跌之后-如何低位灵活补仓
    操盘策略:在交易之前做好应变准备
    操盘策略:股价异动未必主力所为
    赖在长沙的50个理由
    倒在黎明前:融资客股市震荡中被强*损失850万
    操盘策略:巧用盘中T+0交易
  • 原文地址:https://www.cnblogs.com/yjlch1016/p/8321204.html
Copyright © 2011-2022 走看看