• 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’
        }
    }
  • 相关阅读:
    [Linux 流量管理] Cacti的插件安装和使用
    expdp impdp 数据库导入导出命令详解
    Dropping all user tables/sequences in Oracle
    Oracle RMAN 的 show,list,crosscheck,delete命令整理
    EXP00041错误,遇到字符集问题的解决方式
    ORA00312的解决方法
    如何禁止MSN传递文件
    如何解决Parallel query大于1的问题
    bzoj5028小Z的加油店(线段树+差分)
    [转]C# 互操作性入门系列(三):平台调用中的数据封送处理
  • 原文地址:https://www.cnblogs.com/changshuo/p/4638693.html
Copyright © 2020-2023  润新知