上次使用的excel作為Locator對象管理,由于excel處理不夠方便,有以下缺點:
不能實現(xiàn)分page 加載Locator對象
不能夠?qū)崿F(xiàn)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對應(yīng)一個真實的頁面,而每一個page下的Locator對應(yīng)一個真實的頁面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;
}
}