精简版 Selenium PageFactory, Annotation 实例
先是类: HomePage
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
public class HomePage {
@FindBy(id="kw")
public WebElement SearchTextField;
@FindBy(id="su")
public WebElement SearchButton;
public void clearSearchTextField() {
SearchTextField.clear();
}
public void inputSearchTextFeild(String str) {
SearchTextField.sendKeys(str);
}
public void clickSearchButton(){
SearchButton.click();
}
}
再是定义的 Annotation 类,起名叫:AnnotationFactory。(其中的 RetentionPolicy.RUNTIME 很重要)
import java.lang.annotation.Documented;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface AnnotationFactory {
String batchName();
int testOrder() default 0;
String author() default "allen";
}
具体的 Test Case, 用 PageFactory 实例化 HomePage 类,同时也添加了 annotation
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.PageFactory;
@AnnotationFactory(batchName="Smoketest1", testOrder = 2, author = "Mike")
public class SearchBD {
private WebDriver driver = new FirefoxDriver();
private String baseUrl = "https://www.baidu.com/";
HomePage homePage = PageFactory.initElements(driver, HomePage.class);
@Test
public void testHelloWorld() throws Exception {
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get(baseUrl);
//Use page factory and its methods
homePage.clearSearchTextField();
homePage.inputSearchTextFeild("Hello world");
homePage.clickSearchButton();
driver.quit();
}
}
那么我们如何解析那些 annotation, 然后进一步根据 batchname, testOrder 分类执行呢?
这个类就是解析 annotation 的:
import java.lang.annotation.Annotation;
public class GetAnnotations {
public static void main(String[] args) throws ClassNotFoundException {
getAnnotationData("com.test.SearchBD");
}
private static void getAnnotationData(String caseName) throws ClassNotFoundException {
System.out.println("---start----");
Annotation[] annotations = Class.forName(caseName).getAnnotations();
for(Annotation annotation : annotations)
{
if(annotation instanceof AnnotationFactory)
{
AnnotationFactory af = (AnnotationFactory) annotation;
String batchName = af.batchName();
int testOrder = af.testOrder();
String author = af.author();
System.out.println(batchName + " " + testOrder + " " + author);
}
}
}
}
精简版 Selenium PageFactory, Annotation 实例的更多相关文章
- Vue精简版风格指南
前面的话 Vue官网的风格指南按照优先级(依次为必要.强烈推荐.推荐.谨慎使用)分类,且代码间隔较大,不易查询.本文按照类型分类,并对部分示例或解释进行缩减,是Vue风格指南的精简版 组件名称 [组件 ...
- NETCore Bootstrap Admin 通用后台管理权限 [3]: 精简版任务调度模块
前言 NETCore 里说到任务调度,大家首先想到的应该是大名鼎鼎的 QuartzNET 与 Hangfire,然而本篇介绍的却都不是,而是 Bootstrap Admin(以下简称 BA)通用后台权 ...
- Linux上oracle精简版客户端快速部署
RHEL6 + Oracle 11g客户端快速部署 需求:只是用到客户端的sqlplus, sqlldr功能. 方案:用精简版实现客户端的快速部署 1.上传oracle精简版客户端到服务器/tmp目录 ...
- ArcGIS10.2.1精简版、ArcGIS_Desktop10_Tutorial、破解文件等下载地址
原版ArcGIS for Desktop的ISO文件一般都在4.5G以上,一般人用不上里面很多工具,下载回来又浪费时间,现推出ArcGIS10.2.1精简版(里面只包含主程序.Data Interop ...
- TeamViewer12.0.71503(远程控制软件)精简版 单文件企业版介绍
TeamViewer 是一款能在任何防火墙和 NAT 代理的后台用于远程控制,桌面共享和文件传输的简单且快速的解决方案.为了连接到另一台计算机,只需要在两台计算机上同时运行 TeamViewer 即可 ...
- Log4j快速使用精简版
Log4j快速使用精简版 1.导入log4j-1.2.17.jar包 2.在src根目录下创建log4j.properties文件 log4j.rootLogger=INFO, CONSOLE, FI ...
- VMware10.06精简版安装后台运行
VMware10.06精简版安装时会出现一个安装功能选择菜单,里面有一条后台运行必选功能,一般人会跳过条.当你打算在服务器上用vmware时,一定要安装后台运行服务,否则你无法换出正在运行的后台虚拟机 ...
- [异常解决] ubuntu上安装虚拟机遇到的问题(vmware坑了,virtual-box简单安装,在virtual-box中安装精简版win7)
利用周末时间将整个电脑格式化,换成了ubuntu系统- 所谓:扫清屋子再请客! 但是有些软件只在win上有,于是还是考虑装个虚拟机来个——逐步过度策略,一点点地从win上转移到linux上 我的系统是 ...
- 电脑公司最新GHOST WIN7系统32,64位优化精简版下载
系统来自系统妈:http://www.xitongma.com 电脑公司最新GHOST win7系统32位优化精简版V2016年3月 系统概述 电脑公司ghost win7 x86(32位)万能装机版 ...
随机推荐
- 从命令行运行postman脚本
为什么要在命令行中运行 可以在无UI界面的服务器上运行 可以在持续集成系统上运行 运行准备 导出collection 安装nodejs和npm(或cnpm) 安装Newman 运行及生成测试报告支持4 ...
- Spring Boot整合actuator实现监控管理
Spring Boot使用actuator监控管理 1.在pom文件中导入相关的依赖 <dependency> <groupId>org.springframework.boo ...
- CDH5.16.1的Yarn提交任务默认资源分配
1 同时运行5个Spark任务的资源分配截图 2 每个任务占用3个Container 3个core以及4.5GB内存 也就是说一个Container需要 1个core 以及 512MB的内存 如果资源 ...
- windows文本操作字符命令含义
r 打开只读文件,该文件必须存在. r+ 打开可读写的文件,该文件必须存在. rb+ 读写打开一个二进制文件,只允许读写数据. rt+ 读写打开一个文本文件,允许读和写. w 打开只写文件,若文件存在 ...
- debug --- 使用Eclipse
debug必知(快捷键若无效,有可能是与其它软件的快捷键发生冲突的原因) 1.F6 —— 单步执行代码,即顺序一行行地执行源码 2.F5 —— 跳入当前调用的函数的内部,即进入函数内部执行源码 ...
- string::data
const char* data() const noexcept;注:同c_str #include <iostream>#include <string>#include ...
- JS 深拷贝/合并
var mix = function(r, s, ov) { if (!s || !r) return r; if (ov === undefined) ov = true; for (var p i ...
- [uboot] (第三章)uboot流程——uboot-spl代码流程 后续2018版本分析
board_init_f在/u-boot-2018.07-fmxx/arch/arm/mach-fmxx/spl.c中定义 board_init_f之后,和转载的部分有出入: u-boot-2018. ...
- Spring相关概念
DIP: Dependency Inversion Principle.翻译过来是依赖反转原则,也叫依赖倒置原则. 依赖倒置原则是设计模式几个重要原则之一.具体定义就是,底层模块依赖高层模块定义的接口 ...
- Matlab复习
Matlab是刚好两年前(大三)接触的,那时一些课程(遥感图像处理.计量地理学......)要涉及简单的数学建模的问题.Matlab在那些资深的开发者看来可能是一门有点边缘化的东西,虽然也能做开发,能 ...