亚洲好骚综合-亚洲黄色录像-亚洲黄色网址-亚洲黄色网址大全-99久久99久久-99久久99久久精品国产

您的位置:軟件測試 > 開源軟件測試 > 開源功能測試工具 > Selenium
Selenium測試框架使用xml作為對象庫
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時間:[ 2015/9/14 10:53:03 ] 推薦標(biāo)簽:軟件測試工具,功能測試工具

  每一個Locator對象包含3屬性 ByType 、timeOut時間和相應(yīng)的xpath、id......的value
  接下來需要寫一個wrapper
package com.dbyl.libarary.utils;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
import com.dbyl.libarary.utils.Locator.ByType;
public class xmlUtils {
/**
* @author Young
* @param path
* @param pageName
* @return
* @throws Exception
*/
public static HashMap<String, Locator> readXMLDocument(String path,
String pageName) throws Exception {
System.out.print(pageName);
HashMap<String, Locator> locatorMap = new HashMap<String, Locator>();
locatorMap.clear();
File file = new File(path);
if (!file.exists()) {
throw new IOException("Can't find " + path);
}
SAXReader reader = new SAXReader();
Document document = reader.read(file);
Element root = document.getRootElement();
for (Iterator<?> i = root.elementIterator(); i.hasNext();) {
Element page = (Element) i.next();
if (page.attribute(0).getValue().equalsIgnoreCase(pageName)) {
System.out.println("page Info is:" + pageName);
for (Iterator<?> l = page.elementIterator(); l.hasNext();) {
String type = null;
String timeOut = "3";
String value = null;
String locatorName = null;
Element locator = (Element) l.next();
for (Iterator<?> j = locator.attributeIterator(); j
.hasNext();) {
Attribute attribute = (Attribute) j.next();
if (attribute.getName().equals("type")) {
type = attribute.getValue();
System.out.println(">>>>type " + type);
} else if (attribute.getName().equals("timeOut")) {
timeOut = attribute.getValue();
System.out.println(">>>>timeOut " + timeOut);
} else {
value = attribute.getValue();
System.out.println(">>>>value " + value);
}
}
Locator temp = new Locator(value,
Integer.parseInt(timeOut), getByType(type));
locatorName = locator.getText();
System.out.println("locator Name is " + locatorName);
locatorMap.put(locatorName, temp);
}
continue;
}
}
return locatorMap;
}
/**
* @param type
*/
public static ByType getByType(String type) {
ByType byType = ByType.xpath;
if (type == null || type.equalsIgnoreCase("xpath")) {
byType = ByType.xpath;
} else if (type.equalsIgnoreCase("id")) {
byType = ByType.id;
} else if (type.equalsIgnoreCase("linkText")) {
byType = ByType.linkText;
} else if (type.equalsIgnoreCase("name")) {
byType = ByType.name;
} else if (type.equalsIgnoreCase("className")) {
byType = ByType.className;
} else if (type.equalsIgnoreCase("cssSelector")) {
byType = ByType.cssSelector;
} else if (type.equalsIgnoreCase("partialLinkText")) {
byType = ByType.partialLinkText;
} else if (type.equalsIgnoreCase("tagName")) {
byType = ByType.tagName;
}
return byType;
}
/**
* @author Young
* @throws IOException
*/
public static void writeXMLDocument() throws IOException {
OutputFormat format = OutputFormat.createPrettyPrint();
XMLWriter writer = new XMLWriter(new FileWriter("output.xml"), format);
Document document = DocumentHelper.createDocument();
Element root = document.addElement("map");
root.addComment("locator of page map info");
Element page = root.addElement("page").addAttribute("pageName",
"com.dbyl.libarary.pageAction.HomePage");
page.addComment("Locator lists");
page.addElement("locator").addAttribute("type", "ByName")
.addAttribute("timeOut", "3")
.addAttribute("value", "\\div[@name]").addText("loginButton");
page.addElement("locator").addAttribute("type", "ById")
.addAttribute("timeOut", "3")
.addAttribute("value", "\\div[@id]").addText("InputButton");
writer.write(document);
writer.close();
}
}
  定義一個readXMLDocument 方法,返回一個hashMap用來和頁面元素名字和Locator對象match起來,也算是一種關(guān)鍵字驅(qū)動.
  傳入的兩個參數(shù)分別是library的路徑和對應(yīng)的page
上一頁123下一頁
軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd
主站蜘蛛池模板: 不卡视频免费在线观看 | 视频一区二区国产 | 欧美亚洲国产一区二区三区 | 欧美日韩一区二区在线观看 | 亚洲精品一二区 | 成人18xxxx网站 | 福利片在线观看免费高清 | 狠狠色狠色综合曰曰 | 国产一区二区三区亚洲欧美 | 激情五月社区 | 97久久久久| 欧美日韩大片在线观看 | 91短视频在线观看免费最新 | 国产视频第一页 | 精品剧情v国产在线麻豆 | 黄色大片在线播放 | 午夜日韩在线 | 色偷偷亚洲第一成人综合网址 | 日韩欧美国产综合 | 免费大黄| 国产免费无遮挡在线观看视频 | 天堂资源wwww在线看 | 免费一级a毛片在线播出 | 国产免费人成在线看视频 | 日本三级韩国三级三级a级按摩 | 国产色手机在线观看播放 | 免费网站成人亚洲 | 青草视频在线观看视频 | 中文字幕天天躁日日躁狠狠躁免费 | 91香蕉国产线观看免 | yy3341殇情影院理论片 | 在线观看黄色网页 | 久久亚洲热 | 国产精品视频人人做人人爱 | 欧美一级黄色录相 | 欧美日本一 | 日韩一区二区三区在线免费观看 | 人人人人凹人人爽人人澡 | 国产在线一卡 | 精品久久久久久亚洲精品 | 成人私人影院www片免费高清 |