Webdriver的设计模式:Page Object(页面模型)
2016-09-17 22:26
573 查看
设计思想:面向对象,将单个页面所有可能用到元素封装到一个page类中,并提供一些常用的方法,其属性就代表页面元素,普通方法代表对元素所做的操作
以博客园的登录页面为例:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class BlogLogin {
//登陆账号元素
WebElement account;
//登陆密码元素
WebElement password
//登录按钮元素
WebElement loginBtn;
//构造方法,用于初始化页面对象及其页面元素
public BlogLogin(WebDriver driver) {
//定位账号输入框
account=driver.findElement(By.id("input1"));
//定位到密码输入框
password=driver.findElement(By.id("input2"));
//定位到登录按钮
loginBtn=driver.findElement(By.id("signin"));
}
//提供一个登录的方法,只需要提供用户名,密码即可登录
public void Login(String username,String userpassword){
account.sendKeys(username);
password.sendKeys(userpassword);
loginBtn.click();
}
}
以博客园的登录页面为例:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class BlogLogin {
//登陆账号元素
WebElement account;
//登陆密码元素
WebElement password
//登录按钮元素
WebElement loginBtn;
//构造方法,用于初始化页面对象及其页面元素
public BlogLogin(WebDriver driver) {
//定位账号输入框
account=driver.findElement(By.id("input1"));
//定位到密码输入框
password=driver.findElement(By.id("input2"));
//定位到登录按钮
loginBtn=driver.findElement(By.id("signin"));
}
//提供一个登录的方法,只需要提供用户名,密码即可登录
public void Login(String username,String userpassword){
account.sendKeys(username);
password.sendKeys(userpassword);
loginBtn.click();
}
}
相关文章推荐
- Selenium+Python :WebDriver设计模式( Page Object )
- Selenium的PO模式(Page Object Model)|(Selenium Webdriver For Python)
- Selenium-webdriver 页面模式在实际项目中的实际运用,大量Page页面如何初始化?
- Selenium的PO模式(Page Object Model)|(Selenium Webdriver For Python)
- Python3-Selenium3使用PO设计模式(Page Object)实现简单的页面登录操作
- Page Object设计模式
- 什么是Web 2.0:下一代软件的设计模式和商业模型
- Selenium2(java)页面对象模型(Page Object) 八
- JAVA自动化测试之页面对象模型(Page Object)
- 使用Micrisoft.net设计方案 第三章Web表示模式 Web模式集群详细介绍 Page Cache(页面缓存)
- selenium Object Page 设计模式理解及实现!
- QTP - PageObject设计模式
- Cucumber java + Webdriver (7) 结合Page Object,使用LoadableComponent
- 页面显示This is the initial start page for the WebDriver server.的解决办法
- Page Object 设计模式
- Selenium Page Object(PO)设计模式
- 使用Micrisoft.net设计方案 第三章Web表示模式 Web模式集群详细介绍 PageController(页面控制器)
- RFS(六)Open Browser后,页面显示This is the initial start page for the WebDriver server.的解决办法
- Page Object设计模式实践
- Selenium自动化测试Python五:WebDriver设计模式