上次使用的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
之前定义过的Locator类如下:
package com.dbyl.libarary.utils;
/**
* This is for element library
*
* @author Young
*
*/
public class Locator {
private String element;
private int waitSec;
/**
* create a enum variable for By
*
* @author Young
*
*/
public enum ByType {
xpath, id, linkText, name, className, cssSelector, partialLinkText, tagName
}
private ByType byType;
public Locator() {
}
/**
* defaut Locator ,use Xpath
*
* @author Young
* @param element
*/
public Locator(String element) {
this.element = element;
this.waitSec = 3;
this.byType = ByType.xpath;
}
public Locator(String element, int waitSec) {
this.waitSec = waitSec;
this.element = element;
this.byType = ByType.xpath;
}
public Locator(String element, int waitSec, ByType byType) {
this.waitSec = waitSec;
this.element = element;
this.byType = byType;
}
public String getElement() {
return element;
}
public int getWaitSec() {
return waitSec;
}
public ByType getBy() {
return byType;
}
public void setBy(ByType byType) {
this.byType = byType;
}
}