Java+Appium自动化测试框架(二) 定位方式
admin
2023-03-14 23:01:18
0

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"));

}


}


相关内容

热门资讯

玩家分享攻略“樱花之盛牛牛.怎... 玩家分享攻略“樱花之盛牛牛.怎么开挂?”其实是有挂您好,樱花之盛牛牛这个游戏其实有挂的,确实是有挂的...
玩家攻略科普“红黑大战.到底有... 家人们!今天小编来为大家解答红黑大战透视挂怎么安装这个问题咨询软件客服徽9784099的挂在哪里买很...
今日重大消息“福建麻将.真的有... 有 亲,根据资深记者爆料福建麻将是可以开挂的,确实有挂(咨询软件无需打开...
我来教教您“微信拼三张.是不是... 我来教教您“微信拼三张.是不是有挂?”太坑了原来有挂您好,微信拼三张这个游戏其实有挂的,确实是有挂的...
今日重大消息“天府红桃3.辅助... 家人们!今天小编来为大家解答天府红桃3透视挂怎么安装这个问题咨询软件客服徽4282891的挂在哪里买...
玩家攻略科普“来来麻将.可以开... 玩家攻略科普“来来麻将.可以开挂吗?”详细开挂教程您好,来来麻将这个游戏其实有挂的,确实是有挂的,需...
我来教教您“新猴王牛牛.究竟有... 家人们!今天小编来为大家解答新猴王牛牛透视挂怎么安装这个问题咨询软件客服徽9784099的挂在哪里买...
玩家最新攻略“越乡游新昌麻将.... 玩家最新攻略“越乡游新昌麻将.怎么装挂?”太坑了果然有挂您好,越乡游新昌麻将这个游戏其实有挂的,确实...
修复征信这样的好事,竟然有那么... 撰文丨青柳12月22日,央行发布《关于实施一次性信用修复政策有关安排的通知》,支持信用受损但积极还款...
终于懂了“上海泸乐麻将.到底有... 终于懂了“上海泸乐麻将.到底有挂吗?”必胜开挂神器您好,上海泸乐麻将这个游戏其实有挂的,确实是有挂的...