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

发表于:2015-9-11 11:01

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:to be crazy    来源:51Testing软件测试网采编

  上次使用的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;
}
}
31/3123>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号