您的位置:首页 > 移动开发 > Objective-C

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();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: