zoukankan      html  css  js  c++  java
  • Selenium搭配TestNG

    用Maven来构建TestNG依赖:

    <dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.11</version>
    </dependency>

    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.Test;

    public class TestNG {
    private WebDriver driver;

    @BeforeMethod
    //测试之前的准备工作
    public void beforeMethod(){
    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);
    try {
    Thread.sleep(2000);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }

    Assert.assertEquals(driver.getTitle(), "百度一下,你就知道");
    }

    @Test
    //测试用例
    public void testNG(){
    driver.findElement(By.xpath(".//*[@id='kw']")).sendKeys("Selenium");
    driver.findElement(By.xpath(".//*[@id='su']")).click();
    try {
    Thread.sleep(2000);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }

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

    @AfterMethod
    //测试之后的清理工作
    public void afterMethod(){
    driver.close();
    driver.quit();
    }
    }
  • 相关阅读:
    LeetCode 25 Reverse Nodes in k-Group
    圆桌派:家世背景对人的影响有多大
    BibTex 学习笔记
    R parallel包实现多线程1
    IIS学习笔记
    高效完成R代码
    圆桌派 :我们,朋友一生一起走
    高文欣个人简介
    R语言函数话学习笔记5
    git学习笔记1
  • 原文地址:https://www.cnblogs.com/yjlch1016/p/8321106.html
Copyright © 2011-2022 走看看