• 使用testng.xml组织测试用例


    测试用例类TeseNG.java:

    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(dataProvider = "word")
    public void testNG(String keyword, String case_1, String searchTitle)
    throws InterruptedException {
    WebElement webElement = driver.findElement(By.xpath(".//*[@id='kw']"));
    webElement.clear();
    webElement.sendKeys(keyword);

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

    Reporter.log(case_1);
    Assert.assertEquals(driver.getTitle(), searchTitle);
    driver.navigate().refresh();
    }

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

    @DataProvider(name = "word")
    public static Object[][] data(){
    return new Object[][]{{"Selenium", "搜索Selenium的测试用例", "Selenium_百度搜索"},
    {"JMeter", "搜索JMeter的测试用例", "JMeter_百度搜索"},
    {"Appium", "搜索Appium的测试用例", "Appium_百度搜索"}
    };
    }
    }

    testng.xml文件:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
    <suite name="百度搜索的测试计划" verbose="2" preserve-order="true">

    <test name="分别搜索Selenium/JMeter/Appium的测试用例">
    <classes>
    <class name="TestNG" />
    </classes>
    </test>

    <listeners>
    <listener class-name="org.uncommons.reportng.HTMLReporter" />
    <listener class-name="org.uncommons.reportng.JUnitXMLReporter" />
    </listeners>
    </suite>

    
    
  • 相关阅读:
    3D流水线
    log4cplus 配置文件的编写
    linux下的log4cplus的安装和使用
    日志信息的编写与调用
    转C++内存池实现
    转:自定义内存池的使用
    在linux查看内存的大小
    转:C++内存池
    数组指针 和指针数组的区别
    new的三种形态
  • 原文地址:https://www.cnblogs.com/yjlch1016/p/8322027.html
Copyright © 2020-2023  润新知