Pageobject思路改造小项目

思路:
1.三个文件
a-元素的定位和操作,已经跳转到 resultpage
b-result>元素的检查
public void checkKeyword(){ //Assert是TestNG提供的一个断言操作,assertEquals(实际值,期望值),判断两个值是不是相等的。
Assert.assertEquals(RP_INPT_KEYWORD.getAttribute("value"), "selenium");

c-测试文件
hsp.openUrl(); //使用页面封装的输入操作,验证搜索结果输入框页面的值是不是selenium
hsp.searchByKeyword("selenium").checkKeyword();//使用页面封装的退出操作
hsp.close();

findby的常用方法,可以详见扩展目录 http://blog.csdn.net/u013840366/article/details/68944845
public void A_AddAllEvent() throws InterruptedException {
//实例化BDPage对象
//ListPage page = PageFactory.initElements(driver, ListPage.class);
ListPage bdp = new ListPage(driver);
//bdp调用添加event元素,然后单击click
SwitchTo.getWindowHandle(driver);
logger.info("Go to this new event action");
Thread.sleep(5000);
bdp.AddEvent_Link.click();
Thread.sleep(4000);
//bdp调用添加event title,输入内容
SwitchTo.getWindowHandle(driver);
bdp.Event_Input.sendKeys("All-Day Event");
//bdp调用勾选all day event,输入内容,
bdp.AllDay_Input.click();
//bdp调用添加notes,输入内容
bdp.Notes_TextArea.sendKeys("Calendar Note");
//bdp调用添加location,输入内容
bdp.location_TextArea.sendKeys("Calendar Location");
bdp.Save_Input.click();
bdp.Tips_Div.getText();
}

具体的一个小实例如下:
list page
public class ListPage {
/ / Personal Calenar页面添加event按钮
@FindBy(xpath = ".//*[@id='ccTgArea']/div[9]/div[1]/a[1]")
@CacheLookup
public WebElement AddEvent_Link;
// Event详情页面,event subject
@FindBy(name = "title")
@CacheLookup
public WebElement Event_Input;
// Event详情页面,event all day event
@FindBy(id = "eteevent")
@CacheLookup
public
WebElement AllDay_Input;
// Event详情页面,event all day event
@FindBy(id = "notes")
@CacheLookup
public
WebElement Notes_TextArea;
// Event详情页面,event all day event
@FindBy(id = "location")
@CacheLookup
public
WebElement location_TextArea;


// Event详情页面,event all day event
@FindBy(linkText = "Save")
@CacheLookup
public
WebElement Save_Input;
// Event创建后,页面定位提示信息
@FindBy(xpath = "html/body/div[1]/div/div[2]")
@CacheLookup
public
WebElement Tips_Div;
public ListPage(WebDriver driver) {
PageFactory.initElements(driver, this);
}

}

猜你喜欢

转载自blog.csdn.net/liangdeniu/article/details/80167008