网站建设资讯

NEWS

网站建设资讯

Java+Appium自动化测试框架(二)定位方式

package com.appium.test;

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名与空间、网页空间、营销软件、网站建设、兴安网站维护、网站推广。

/**

* @author YuFeifei

* @version 2017年11月15日 上午11:41:21

* 类说明

* 根据读取的配置文件,将key和value拆分

* 再通过split将value分成定位类型(locatorType)和元素(locatorValue)

*/

import org.openqa.selenium.By;

public class GetByLocatorTest {

public static By getLocator(String key){

ProUtilTest properties = new ProUtilTest("./configs/test1.properties");

/**属性locator 是通过key获取的value*/

String locator = properties.getProp(key);

/**属性locatorType 获取的value中通过split分离出的>前面的数据==id、name等*/

String locatorType = locator.split(">")[0];

/**属性locatorType 获取的value中通过split分离出的>后面的数据==元素*/

String locatorValue = locator.split(">")[1];

System.out.println("获取的定位类型:" + locatorType + "\t获取的元素是:" + locatorValue);

/**根据定位类型,返回定位方式*/

if (locatorType.toLowerCase().equals("id"))//toLowerCase()将大写字符转换为小写

return By.id(locatorValue);

else if (locatorType.toLowerCase().equals("name"))

return By.name(locatorValue);

else if (locatorType.toLowerCase().equals("classname"))

return By.className(locatorValue);

else if (locatorType.toLowerCase().equals("tagname"))

return By.tagName(locatorValue);

else if (locatorType.toLowerCase().equals("linktext"))

return By.linkText(locatorValue);

else if (locatorType.toLowerCase().equals("cssselector"))

return By.cssSelector(locatorValue);

else if (locatorType.toLowerCase().equals("xpath"))

return By.xpath(locatorValue);

else

try{

throw new Exception("输入的locatorType未在预设程序中被定义:" + locatorType + "请检查GetByLocatorTest这个类");

}catch (Exception e){

e.printStackTrace();

}

return null;

}

/**测试*/

public static void main(String agrs[]){

GetByLocatorTest test2 = new GetByLocatorTest();

System.out.println(test2.getLocator("LG_NAME_PHONE"));

}

}


文章题目:Java+Appium自动化测试框架(二)定位方式
文章地址:http://cdweb.net/article/pgoidj.html