zoukankan      html  css  js  c++  java
  • PageObject

    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.ie.InternetExplorerDriver;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.openqa.selenium.support.PageFactory;
    import org.openqa.selenium.support.PageFactory;
    public class BasePage { public static WebDriver driver; public static BaiduHomepage get(String url) throws InterruptedException { System.setProperty("webdriver.ie.driver", "IEDriverServer.exe文件的路径"); // 设置系统环境变量,key-value DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer(); ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true); driver=new InternetExplorerDriver(ieCapabilities); // 实例化一个浏览器对象 driver.get(url); return PageFactory.initElements(driver, BaiduHomepage.class); } public static void quit() { driver.quit(); } }
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.support.FindBy;
    import org.openqa.selenium.support.How;
    import org.openqa.selenium.support.PageFactory;
    //百度主页
    public class BaiduHomepage extends BasePage{ private WebDriver driver; @FindBy(id = "kw") public WebElement kw; public BaiduHomepage(WebDriver driver) { this.driver=driver; } public BaiduListPage searchListPage(String key) { try { Thread.sleep(10000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("keyWords="+kw); kw.sendKeys("selenium"); return PageFactory.initElements(driver, BaiduListPage.class); } }
    import org.openqa.selenium.WebDriver;
    //搜索结果页面
    public class BaiduListPage extends BasePage{
        private WebDriver driver;
        
        public  BaiduListPage( WebDriver driver) {
            this.driver=driver;
        }
    }
    package pageObject;
    import org.openqa.selenium.support.PageFactory;
    public class TestClass {
    
        /**
         * @param args
         * @throws InterruptedException 
         */
        public static void main(String[] args) throws InterruptedException {
            new BasePage().get("www.baidu.com").searchListPage("selenium");//在百度搜索关键字‘selenium’
        }
    }
  • 相关阅读:
    VUE 腾讯云 web端上传视频SDK 上传进度无法显示
    SQL Server 连接数据库报错 (ObjectExplorer)
    Docker 下,搭建 SonarQube 环境 (数据库为 postgres)
    静态代码扫描工具
    windows10 中为文件添加让自己可以使用查看、修改、运行的权限
    mysql8.0.21下载安装详细教程,mysql安装教程
    C# 关于构造函数引证次序讨教
    c# winfrom 读取app.config 自定义节点
    如何在C#中将项目添加到列表中
    如何在C#实现日志功能
  • 原文地址:https://www.cnblogs.com/changshuo/p/4638693.html
Copyright © 2011-2022 走看看