温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-04-06 16:18:03 来源:网络 阅读:1878 作者:木子耳07 栏目:建站服务器

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

}


}


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI