精简版 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位)万能装机版 ...
随机推荐
- 使用Ant打包工具
由于使用java,javac,jar等工具进行编译打包,即繁琐低效又容易出错,因此Ant出现了.Ant的出现就是专门为了打包编译java代码的,使用之前得稍微学一下.Ant的运行起来主要是依靠配置文件 ...
- centos7搭建activemq服务
一.下载安装jdk 下载 jdk-8u211-linux-x64.rpm安装: yum -y install jdk-8u211-linux-x64.rpm 二.官网下载 activemq 软件包 官 ...
- height 自适应问题
何为高度自适应? 高度自适应就是高度能跟随浏览器窗口的大小改变而改变,典型的运用在一些后台界面中上面一栏高度固定用作菜单栏或导航栏,下面一栏高度自适应用于显示内容.高度自适应不像宽度自适应那样简单,在 ...
- Tree HDU - 6547 (树链剖分,线段树)
wls 有三棵树,树上每个节点都有一个值 ai,现在有 2 种操作: 将一条链上的所有节点的值开根号向下取整: 求一条链上值的和: 链的定义是两点之间的最短路. Input 第一行两个数 n, q 分 ...
- java代码中的坑
1.Integer 类型数值比较: public static void main(String[] args) { // TODO Auto-generated method stu ...
- 关于maven的repositories
在maven repositories视图中,有local repositories和global repositories两种. local repositories是本地的库,默认目录在C:\Us ...
- 浅析Java web程序之客户端和服务器端交互原理
原文链接: https://www.iteye.com/topic/470019 1. 协议 a. TCP/IP整体构架概述 TCP/IP协议并不完全符合OSI的七层参考模型.传统的开放式系统互连参考 ...
- K8S集群组件
master节点主要由apiserver.controller-manager和scheduler三个组件,以及一个用于集群状态存储的etcd存储服务组成,而每个node节点则主要包含kubelet. ...
- 【转载】awk入门
作者: 阮一峰 http://www.ruanyifeng.com/blog/2018/11/awk.html awk是处理文本文件的一个应用程序,几乎所有 Linux 系统都自带这个程序. 它依次处 ...
- Atcoder Regular Contest 066 F genocide【JZOJ5451】
题目 分析 \(s[i]\)表示a前缀和. 设\(f[i]\)表示做完了1~i的友谊颗粒的最优值(不一定选i),那么转移方程为 \[f[i]=max\{f[i-1],max\{f[j]-s[i]+s[ ...