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’
}
}

PageObject的更多相关文章

  1. UI自动化测试框架(项目实战)python、Selenium(日志、邮件、pageobject)

    其实百度UI自动化测试框架,会出来很多相关的信息,不过就没有找到纯项目的,无法拿来使用的:所以我最近就写了一个简单,不过可以拿来在真正项目中可以使用的测试框架. 项目的地址:https://githu ...

  2. 浅谈pageobject模式

    先来看两段代码 代码1: package com.zlshuo.selenium.nonaming.pageobject; /** * @author leshuo * @version 2014年5 ...

  3. page-object使用(2)---elements

    elements就是html元素下所有的标签.用page-object你可以找到并定位html页面下绝大多数的元素,这个文章列出了可定位的这些元素,生成的方法,和依据什么关键字来找到这些元素. BUT ...

  4. page-object使用(1)

    创建你的page 你必须做的第一件事情是创建你的page,这是一些包含了PageObject模块的简单的ruby类,请不要创建你自己的initialize方法,因为已经有一个存在而且不能被覆盖.如果你 ...

  5. Page-Object设计模式

    自动化脚本初写之际一定是只求完成功能测试,页面by.id.by.name.by.xpath满篇飞.业务逻辑代码重复率也是越来越高.慢慢的写着写着开始重构,开始封装一些方法.代码量好一些的人会在代码开始 ...

  6. selenium更加高效的PageObject 对象操作代码

    重新封装了的selenium代码,包括click事件,sendkeys事件,select事件,以及对readonly日期控件的处理 package com.common; import java.ut ...

  7. PageObject设计模式,在selenium自动化测试中的运用

    PageObject设计模式1. Web自动化测试框架(WebTestFramework)是基于Selenium框架且采用PageObject设计模式进行二次开发形成的框架. 2. web测试时,建议 ...

  8. 记我的第二次自动化尝试——selenium+pageobject+pagefactory实现自动化下单、退款、撤销回归测试

    需求: 系统需要做下单.退款.撤销的回归测试,有下单页面,所以就想到用selenium做WEB UI 自动化 项目目录结构: common包上放通用的工具类方法和浏览器操作方法 pageobject包 ...

  9. 【转】Webdriver的PageObject改造By 张飞

    Webdriver的PageObject改造 PageObject中提供了一个@FindBy注解,也非常好用,但由于其是一次性全部初始化所有的WebElement,对于当前还不存在于页面上的Eleme ...

  10. pageObject学习

    1.java代码层面的pageObject实现 参考:https://www.cnblogs.com/yytesting/p/6973474.html 是用java写的实例,优点是结构很清晰,缺点是p ...

随机推荐

  1. Python 摄像头 树莓派 USB mjpb

    import cv2 import urllib.request import numpy as np import sys host = "192.168.1.109:8080" ...

  2. webstorm不能中文输入问题

    版本:2018.1.4 原因:http://www.javatang.com/archives/2017/08/27/52101751.html 解决方案:https://www.cnblogs.co ...

  3. Django 报错no sucn column: OpretionalError

    1.报错原因:新增的字段未能同步数据库 2.解决办法:删除整个数据库,然后重新编译,然后over 1.rm -rf db.sqlites3 #删除数据库 2.rm -rf cmdb/migrarion ...

  4. java 反射获取设置私有成员变量的值

    for (Object arg:args) { //处理applicationCode Class<?> argClass = arg.getClass(); Field applicat ...

  5. pthon中的基本运算

    格式化输出的三种方式 1.占位符 程序中经常会有这样的场景:要求用户输入信息,然后打印成固定的格式 比如要求用户输入用户名和年龄,然后打印如下格式: my name is xxx,my age is ...

  6. SpringCloud或SpringBoot+Mybatis-Plus利用mybatis插件实现数据操作记录及更新对比

    引文 本文主要介绍如何使用mybatis插件实现拦截数据库操作并根据不同需求进行数据对比分析,主要适用于系统中需要对数据操作进行记录.在更新数据时准确记录更新字段 核心:mybatis插件(拦截器). ...

  7. JSON.parse()处理json字符串时需要处理的特殊字符

    var str= "json字符串"; str=str.replace(/\\/g,"\\\\"); str=str.replace(/\n/g,"\ ...

  8. mongdb 复制集

    步骤: 一.启动三台进程 1../bin/mongod --dbpath=/home/work/app/mongodb/mongodb-linux-x86_64-amazon-3.2.7/data/r ...

  9. Python - 静态方法@staticmethod和类方法classmethod

    传送门 https://github.com/jackfrued/Python-100-Days/blob/master/Day01-15/Day09/%E9%9D%A2%E5%90%91%E5%AF ...

  10. 棍子Sticks(poj_1011)[经典搜索]

    [题意描述] George用相同的长度棍子,将他们随机切成最多64个单位的长度,现在,他想回到原来的状态,但他忘了他原来的多少根,以及他们原本是多长.请帮助他和设计一个程序,计算最小的可能的原始长度. ...