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 ...
随机推荐
- 网络技能大赛A卷测试
这个测试对我来言有些难度,短时间内做不了太多.首先是思路的理清,登录后的界面有好几种,而且公文的状态也有好几种.理清思路就花了一些时间 然后大致的框架做了做,然后将用户的增删改查还有公文的增删改查写了 ...
- 【游戏体验】Haunted House(鬼屋历险记)
>>>点此处可试玩无敌版<<< 这款游戏可谓是经典,很多人的童年都有过它的陪伴,不妨重拾当年的快乐 个人测评 游戏性 9/10 音乐 7/10 剧情 4/10 总评 ...
- Educational Codeforces Round 80 (Rated for Div. 2)D(二分答案,状压检验)
这题1<<M为255,可以logN二分答案后,N*M扫一遍表把N行数据转化为一个小于等于255的数字,再255^2检验答案(比扫一遍表复杂度低),复杂度约为N*M*logN #define ...
- C语言随笔2: rom ram 及其运行的过程
内存的分配方式 五个区 :堆区.栈区.全局区.文字常量区.程序代码区 这五个区是ram中的.或者说,堆栈段.数据段.代码段 而rom中,没有堆区和栈区,只有数据段和代码段. ram是在程序运行是的内存 ...
- 记录STM32调试
问题:加入红外初始化后,程序卡在红外初始化处 解决思路: 1.确认时钟是不是好的 2.把定时器分解调试(输入捕获.溢出分开一步一步弄) 已解决:定时器的溢出中断 注意:STM32Cube配置好后,需要 ...
- WordPress 安装教程
1.要安装WordPress,先看他的环境要求 2.环境符合后,直接去官网下载 WordPress(点击去官网) 下载最新的安装包 3.下载解压后,直接在浏览器中访问 会自动跳转到安装界面 http: ...
- Go语言基础之Path包与FilePath包
文章引用自 path包的使用 package main; import ( "fmt" "path" ) //go语言path包的学习 func main() ...
- 关于iOS appIcon launchImage 尺寸
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/IconMatrix ...
- 搭建第一个django项目
django是python做web最为强大和全能的后端框架,不会django的python如一条咸鱼... 所以开始学习django框架. 首选得在python中下载django 下载命令: pip ...
- Tarjan's algorithm
Tarjan算法可以用来求有向图的强连通分量个数,之前十分粗略的写了Kosaraju算法,这里打算比较认真的分析一下Tarjan算法,然后给出算法实现代码. Tarjan算法的主要算法部分也是dfs( ...