selenium page object & Page Factory
package demo; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement; public class HomePage
{
public String base_url = "https://www.baidu.com/";
public WebDriver driver; WebElement inputBox;
WebElement searchButton; /**
* @author Young
* @param message
*/
public void typeInputBox(String message)
{
inputBox = driver.findElement(By.id("kw"));
inputBox.clear();
inputBox.sendKeys(message);
} /**
* @author Young
*/
public void clickSearchButton() {
searchButton = driver.findElement((By.cssSelector("input#su")));
searchButton.click();
driver.manage().timeouts().pageLoadTimeout(90, TimeUnit.SECONDS);
} /**
* @author Young
* @param d
*/
HomePage(WebDriver d)
{
this.driver = d;
driver.get(base_url);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(90, TimeUnit.SECONDS);
} /**
* @author Young
* @return
*/
public String getTitle()
{
return driver.getTitle();
} }
Page factory:
package demo; import java.util.concurrent.TimeUnit;
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;
import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory; public class HomePage
{
public String base_url = "https://www.baidu.com/";
public WebDriver driver; @FindBy(how = How.ID, using = "kw")
WebElement inputBox;
@FindBy(how = How.CSS, using = "input#su")
WebElement searchButton; /**
* @author Young
* @param message
*/
public void typeInputBox(String message)
{
inputBox.clear();
inputBox.sendKeys(message);
} /**
* @author Young
*/
public void clickSearchButton()
{
searchButton.click();
driver.manage().timeouts().pageLoadTimeout(90, TimeUnit.SECONDS);
} /**
* @author Young
* @param d
*/
HomePage(WebDriver d)
{
this.driver = d;
driver.get(base_url);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(90, TimeUnit.SECONDS);
PageFactory.initElements(new AjaxElementLocatorFactory(driver, 15), this);
} /**
* @author Young
* @return
*/
public String getTitle()
{
return driver.getTitle();
} }
selenium page object & Page Factory的更多相关文章
- Selenium(十九):unittest单元测试框架(五) Page Object设计模式
1. Page Object设计模式 Page Object是Selenium自动化测试项目开发实践的最佳设计模式之一,它主要体现在对界面交互细节的封装,这样可以使测试方案更关注于业务而非界面细节.从 ...
- python+ selenium&APPium自动化 page Object 设计模式
题记: 之前公司项目比较稳定, 在进行了系统测试,想用自动化测试进行冒烟测试,或者对主要功能进行测试, 因此用到了PO模式 因此做个记录: Page Object Page Object模式是使用Se ...
- 这可能是最简单的Page Object库
做过web自动化测试的同学,对Page object设计模式应该不陌生. Page object库应该根据以下目标开发: Page object应该易于使用 清晰的结构 PageObjects 对于页 ...
- UI自动化测试的Page Object模式
在UI级的自动化测试框架中,当页面样式改变或者页面元素属性改变,那么代码也要随之进行修改,如何做到高效快速的修改代码来适应这些改变呢,这个时候可以引入Page Object模式,也是页面对象设计模式. ...
- 初识Page Object
PageObject是UI自动化测试项目开发实践的最佳设计模式之一,它的主要特点体现在对界面交互细节的封装上,使测试用例更加专注于业务的操作,从而提高测试用例的可维护性. 1.认识Page Objec ...
- Page Object Model (Selenium, Python)
时间 2015-06-15 00:11:56 Qxf2 blog 原文 http://qxf2.com/blog/page-object-model-selenium-python/ 主题 Sel ...
- selenium page object model
Page Object Model (POM) & Page Factory in Selenium: Ultimate Guide 来源:http://www.guru99.com/page ...
- Selenium的PO模式(Page Object Model)[python版]
Page Object Model 简称POM 普通的测试用例代码: .... #测试用例 def test_login_mail(self): driver = self.driver driv ...
- Selenium的PO模式(Page Object Model)|(Selenium Webdriver For Python)
研究Selenium + python 自动化测试有近两个月了,不能说非常熟练,起码对selenium自动化的执行有了深入的认识. 从最初无结构的代码,到类的使用,方法封装,从原始函数 ...
随机推荐
- 理解javascript里的ABC--apply bind call
一,三者共同点 js中的apply,call,bind是对于初学者比较难的概念之一,比如说我..参考几篇文章之后,统一来讲, 1.这三个函数都属于Function.prototype下面的方法,如下图 ...
- CADisplayLink 及定时器的使用
第一种: 用CADisplayLink可以实现不停重绘. 例子: CADisplayLink* gameTimer; gameTimer = [CADisplayLink displayLinkW ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
- SVG中 transform矩阵遇到的兼容性问题
SVG transform矩阵遇到的兼容性问题.在chrome.safari.火狐.360极速浏览器上都正常显示的图,在手机端就不行啊!!! 先上图. 图1 PC端浏览器 图2 iPho ...
- Xamarin.ios 目录结构
1.Resources: 文件夹存放应用程序所. 2.AppDelegate.cs: 主要的应用程序类别(class) ,并接听 系统事件及相对应的事件处理. 3.Entitlements.plist ...
- Chrome 开发工具之Timeline
之前有说到Element,Console,Sources大多运用于debug,Network可用于debug和查看性能,今天的主角Timeline更多的是用在性能优化方面,它的作用就是记录与分析应用程 ...
- zookeeper原理解析-序列化
1)底层通信数据封装与操作 BinaryInputArchive& BinaryOutputArchive底层通信数据封装与操作 BinaryInputArchiv ...
- python中文编码问题
第一步:在代码中输入以下命令,执行: #在Python中显示中文注释和输出中文a ="中文"print a 返回错误: d:\Python27\python.exe "D ...
- 个人对B/S项目的一些理解(二)
以下是我自工作以来,结合对C/S项目的认知,对B/S项目的一些理解. 如有不足或者错误,请各位指正. ----数据处理的升级 在上面的描述中,大家也看到了,远古时期的程序员,其实也听不容易 ...
- asp.net反向代理
https://www.codeproject.com/Articles/18490/Reverse-Proxy-in-C-NET-v https://www.codeproject.com/Arti ...