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);elsetry{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”));}
}

相关推荐: 老男孩教育每日一题-第80天-如何实现 Nginx 代理的节点访问日志记录客户的 IP 而不是代理的 IP?

参考答案使用proxy反向代理模块中的proxy_set_header参数今天是每日一题陪伴大家的第80天,期待你的开发云主机域名进步。对于题目和答案的任何疑问,请在博客评论区留言。往期题目索引http://lidao.blog.51cto.com/33880…

免责声明:本站发布的图片视频文字,以转载和分享为主,文章观点不代表本站立场,本站不承担相关法律责任;如果涉及侵权请联系邮箱:360163164@qq.com举报,并提供相关证据,经查实将立刻删除涉嫌侵权内容。

(0)
打赏 微信扫一扫 微信扫一扫
上一篇 03/31 16:16
下一篇 03/31 16:17