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’
}
}
PageObject的更多相关文章
- UI自动化测试框架(项目实战)python、Selenium(日志、邮件、pageobject)
其实百度UI自动化测试框架,会出来很多相关的信息,不过就没有找到纯项目的,无法拿来使用的:所以我最近就写了一个简单,不过可以拿来在真正项目中可以使用的测试框架. 项目的地址:https://githu ...
- 浅谈pageobject模式
先来看两段代码 代码1: package com.zlshuo.selenium.nonaming.pageobject; /** * @author leshuo * @version 2014年5 ...
- page-object使用(2)---elements
elements就是html元素下所有的标签.用page-object你可以找到并定位html页面下绝大多数的元素,这个文章列出了可定位的这些元素,生成的方法,和依据什么关键字来找到这些元素. BUT ...
- page-object使用(1)
创建你的page 你必须做的第一件事情是创建你的page,这是一些包含了PageObject模块的简单的ruby类,请不要创建你自己的initialize方法,因为已经有一个存在而且不能被覆盖.如果你 ...
- Page-Object设计模式
自动化脚本初写之际一定是只求完成功能测试,页面by.id.by.name.by.xpath满篇飞.业务逻辑代码重复率也是越来越高.慢慢的写着写着开始重构,开始封装一些方法.代码量好一些的人会在代码开始 ...
- selenium更加高效的PageObject 对象操作代码
重新封装了的selenium代码,包括click事件,sendkeys事件,select事件,以及对readonly日期控件的处理 package com.common; import java.ut ...
- PageObject设计模式,在selenium自动化测试中的运用
PageObject设计模式1. Web自动化测试框架(WebTestFramework)是基于Selenium框架且采用PageObject设计模式进行二次开发形成的框架. 2. web测试时,建议 ...
- 记我的第二次自动化尝试——selenium+pageobject+pagefactory实现自动化下单、退款、撤销回归测试
需求: 系统需要做下单.退款.撤销的回归测试,有下单页面,所以就想到用selenium做WEB UI 自动化 项目目录结构: common包上放通用的工具类方法和浏览器操作方法 pageobject包 ...
- 【转】Webdriver的PageObject改造By 张飞
Webdriver的PageObject改造 PageObject中提供了一个@FindBy注解,也非常好用,但由于其是一次性全部初始化所有的WebElement,对于当前还不存在于页面上的Eleme ...
- pageObject学习
1.java代码层面的pageObject实现 参考:https://www.cnblogs.com/yytesting/p/6973474.html 是用java写的实例,优点是结构很清晰,缺点是p ...
随机推荐
- 二次封装 Reponse,视图家族
复习 """ 1.整体修改与局部修改 # 序列化 ser_obj = ModelSerializer(model_obj) # 反序列化,save() => cre ...
- 使用docker容器时遇到的2个问题
最近项目在centOS7服务器上用docker部署了几个服务,在运行的时候发现,总是过一段时间,容器内的根目录就变为只读而无法写入了. 经过调查都是因为docker/devicemapper/devi ...
- kafka集群搭建记录
本文记录搭建kafka搭建过程. 一.硬件机器介绍 192.168.183.195 master-node 192.168.183.194 data-node1 192.168.183.196 dat ...
- 使用Python处理非对称加密-测试大佬常用的处理方式
一.思考❓❔ 1.什么是非对称加密? 公钥加密系统,广泛用于数据加密传输 更详细的解释可参考维基百科( https://en.wikipedia.org/wiki/RSA_(cryptosystem) ...
- [Python] Tkinter的食用方法_01_简单界面
#开始 放假之后感觉整个人已经放飞自我了,完全不知道自己一天天在干什么,明明有很多的事情需要做,但是实际上每天啥都没做,,,虚度光阴... 晚上突然心烦意乱,开始思考今天一天都做了什么,感觉很有负罪感 ...
- 对象的上转型和下转型 (instanceof关键字)
1.对象的上转型,就是多态的一种写法 格式:父类名称 对象名 = new 子类名称(): Animal animal = new Cat(); 含义:右侧创建一个子类对象,把它当作父类来使用 向上转型 ...
- 一、Python概念知识点汇总
一.编译型语言和解释性语言的区别 二.Python的设计目标 1.一门简单直观的语言并与主要竞争者一样强大 2.开源,以便使任何人都可以为它做贡献 3.代码像纯英文那样容易理解 4.适用于短期开发的日 ...
- yii2.0 验证码
首先我们在控制器里创建一个actions方法,用于使用yii\captcha\CaptchaAction <?php namespace app\controllers; use YII; us ...
- html5的canvas2
http://www.cnblogs.com/liugang-vip/p/5360283.html http://www.cnblogs.com/liugang-vip/p/5364292.html ...
- [JLOI2009]神秘的生物
题目链接 题目大意 给定一个\(n*n\)的矩阵,从其中选取恰好一个连通块,使选取的格子所对应的权值和最大. \(n\leq 9\) 解题思路 由于\(n\)特别小,考虑插头dp. 和一般的插头dp不 ...