您的位置:首页 > 其它

selenium测试框架使用xml作为对象库

2015-09-10 23:58 399 查看
之前已经写过一篇:

selenium测试框架篇,页面对象和元素对象的管理

上次使用的excel作为Locator对象管理,由于excel处理不够方便,有以下缺点:

不能实现分page 加载Locator对象

不能够实现Locator对象重名

文件比较大,读写速度没有xml快

所以,重新写了使用dom4j操作xml,使用xml管理Locator对象,能够有效解决以上问题

首先,定义Locator文件

<?xml version="1.0" encoding="UTF-8"?>

<map>
<!--locator of page map info -->
<page pageName="com.dbyl.libarary.pageAction.HomePage">
<!--Locator lists -->
<locator type="ByXpath" timeOut="3" value="//div[@class='top-nav-profile']//img[@class='avatar']">profile</locator>
</page>
<!--locator of page map info -->
<page pageName="com.dbyl.libarary.pageAction.LoginPage">
<!--Locator lists -->
<locator type="" timeOut="3" value="//input[@name='account' and  not(@autocomplete)]">loginEmailInputBox</locator>
<locator type="ByXpath" timeOut="3" value="//button[@class='sign-button submit' and text()='登录']">loginButton</locator>
<locator type="ByXpath" timeOut="3" value="//div[@class='top-nav-profile']//img[@class='avatar']">profile</locator>
<locator type="ByXpath" timeOut="3" value="//input[@name='password' and @placeholder='密码']">loginPasswordInputBox</locator>
</page>
</map>


每一个Page对应一个真实的页面,而每一个page下的Locator对应一个真实的页面element

public static HomePage login(String email, String password)
throws Exception {
loginPage = new LoginPage(getDriver());
loginPage.waitForPageLoad();
loginPage.typeEmailInputBox(email);
loginPage.typePasswordInputBox(password);
loginPage.clickOnLoginButton();
Assert.assertTrue(loginPage.isPrestentProfile(), "login failed");

return (HomePage) PageFactory.getPage(HomePage.class, getDriver());
}


View Code
这样,这个框架能够实现一些基本操作,下一步还需要实现失败重试截图,配合虚拟机

下载地址:https://github.com/tobecrazy/Demo
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: