zoukankan      html  css  js  c++  java
  • Selenium PageFactory页面工厂

    使用Selenium PageFactory页面工厂的好处是:

    当页面元素的位置发生变化时,

    我们只需要去修改id或者xpath,

    而不用去修改测试用例。

    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.support.FindBy;
    import org.openqa.selenium.support.PageFactory;
    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;

    @FindBy(xpath = ".//*[@id='kw']")
    private WebElement inputBox;
    //输入框

    @FindBy(xpath = ".//*[@id='su']")
    private WebElement searchButton;
    //搜索按钮

    @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();
    PageFactory.initElements(driver, this);
    //构造函数,初始化PageFactory对象
    driver.manage().window().maximize();
    driver.get(baiduHomePage);
    Thread.sleep(2000);
    Assert.assertEquals(driver.getTitle(), "百度一下,你就知道");
    }

    @Test
    public void testNG() throws InterruptedException {
    inputBox.clear();
    inputBox.sendKeys("Selenium");

    searchButton.click();
    Thread.sleep(3000);

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

    @AfterMethod
    public void afterMethod(){
    driver.close();
    driver.quit();
    }

    }
  • 相关阅读:
    输入输出
    SpringCloud组件之HystrixDashbord
    SpringCloud组件之zuul的使用
    SpringCloud组件之Hystrix组件的使用
    负载均衡算法示例
    JavaScript基础知识总结
    SpringBoot收藏
    java虚拟机详细图解10--JVM类加载机制及类加载过程
    java虚拟机详细图解9--JVM机器指令集
    java虚拟机详细图解8--JVM运行时数据区
  • 原文地址:https://www.cnblogs.com/yjlch1016/p/8322131.html
Copyright © 2011-2022 走看看