selenium--关键字驱动
package com.dn.twohomework;
import java.util.ArrayList;
import java.util.Set;
import java.util.List;
// import org.apache.bcel.generic.Select;
//import org.openqa.selenium.support.ui.Select;
//import org.apache.bcel.generic.Select;
//import com.sun.org.apache.bcel.internal.generic.Select;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
import java.util.Iterator;
import com.gargoylesoftware.htmlunit.html.impl.SelectableTextInput;
//import com.gargoylesoftware.htmlunit.javascript.host.Iterator;
//import com.gargoylesoftware.htmlunit.javascript.host.Set;
//import com.sun.media.sound.FFT;
//import com.sun.xml.internal.bind.v2.schemagen.xmlschema.List;
import java.util.HashSet;;
public class keyWord1 {
private static WebDriver driver;
// 打开浏览�?
public void openBrowser(String b, String xpath) {
if ("cc".equals(b)) {
ChromeDriver chrome = new ChromeDriver("webdriver.chrome.driver", xpath);
driver = chrome.getdriver();
} else if ("ff".equals(xpath)) {
FFDriver ff = new FFDriver("webdriver.gecko.driver", xpath);
ff.getdriver();
} else if ("ie".equals(b)) {
IEDriver ie = new IEDriver("webdriver.ie.driver", xpath);
driver = ie.getdriver();
}
}
public static WebDriver getDriver() {
return driver;
}
public static void setDriver(WebDriver driver) {
keyWord1.driver = driver;
}
// 输入网址
public void geturl(String url) {
try {
driver.get(url);
//ChromeOptions options = new ChromeOptions();
//options.addArguments("--start-fullscreen");
//driver.manage().window().maximize();
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println("打开浏览器失�?");
e.printStackTrace();
}
}
// 等待时间
public void sleep(String time) throws NumberFormatException, InterruptedException {
Thread.sleep(Integer.parseInt(time));
}
// 输入内容
public void input(String xpath, String word) {
try {
driver.findElement(By.xpath(xpath)).clear();
driver.findElement(By.xpath(xpath)).sendKeys(word);
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println("输入字符串失�?");
e.printStackTrace();
}
}
// 点击
public void click(String xpath) {
try {
driver.findElement(By.xpath(xpath)).click();
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println("点击失败");
e.printStackTrace();
}
}
// 关闭旧浏览器,切换到新窗�?
public void closeOldWin() {
List<String> handle = new ArrayList<String>();
Set<String> s = driver.getWindowHandles();
// 循环获取数组里的句柄,保存到链表handle里面
for (Iterator<String> it = s.iterator(); it.hasNext();) {
handle.add(it.next().toString());
}
driver.close();
driver.switchTo().window(handle.get(1));
}
// 关闭新浏览器,切换到旧窗�?
public void closeNewWin() {
List<String> handle = new ArrayList<String>();
Set<String> s = driver.getWindowHandles();
// 循环获取数组里的句柄,保存到链表handle里面
for (Iterator<String> it = s.iterator(); it.hasNext();) {
handle.add(it.next().toString());
}
driver.switchTo().window(handle.get(1));
driver.close();
driver.switchTo().window(handle.get(0));
}
// 进入子页�?
public void intoIframe(String xpath) {
try {
driver.switchTo().frame(driver.findElement(By.xpath(xpath)));
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println("进入Iframe失败");
e.printStackTrace();
}
}
// 关闭子页�?
public void outIframe() {
driver.switchTo().defaultContent();
}
// 获取文字信息
public void getText(String xpath) {
System.out.println(driver.findElement(By.xpath(xpath)).getText());
}
// hover
public void hover(String xpath){
try {
Actions builder = new Actions(driver);
builder.moveToElement(driver.findElement(By.xpath(xpath))).build().perform();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("悬停失败");
}
}
//获取链接link
public String getLink(String xpath){
String link = "about:bliank";
try {
link = driver.findElement(By.xpath(xpath)).getAttribute("href");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("获取链接失败");
}
return link;
}
//提交表单
public void submit(String xpath){
try {
driver.findElement(By.xpath(xpath)).submit();
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println("提交失败");
e.printStackTrace();
}
}
//选择下拉框
public void select(int num,String xpath){
Select sel = new Select(driver.findElement(By.xpath(xpath)));
sel.selectByIndex(num);
}
//通过js操作
public void exejs(String text){
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(text);
}
//上传图片
public void uploadpiture(String name,String path){
try {
driver.findElement(By.name(name)).sendKeys(path);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("上传失败");
}
}
//获得元素属性的值
public String GetsTheValueOfTheElement(String xpath,String element){
try {
String getvalues = driver.findElement(By.xpath(xpath)).getAttribute(element);
return getvalues;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("获取元素属性的值失败");
return null;
}
}
//点击alert的确认按钮
public void clickAlert(){
driver.switchTo().alert().accept();;
}
}
selenium--关键字驱动的更多相关文章
- Selenium关键字驱动测试框架Demo(Java版)
Selenium关键字驱动测试框架Demo(Java版)http://www.docin.com/p-803493675.html
- UI自动化测试框架之Selenium关键字驱动
一.原理及特点 1. 关键字驱动测试是数据驱动测试的一种改进类型 2. 主要关键字包括三类:被操作对象(Item).操作(Operation)和值(value),用面向对象形式可将其表现为Item.O ...
- UI自动化测试框架之Selenium关键字驱动 (转)
摘要 自动化测试框架demo,用关键字的形式将测试逻辑封装在数据文件中,测试工具解释这些关键字即可对其应用自动化 一.原理及特点 1. 关键字驱动测试是数据驱动测试的一种改进类型 2. 主要 ...
- 【转】UI自动化测试框架之Selenium关键字驱动
原网址:https://my.oschina.net/hellotest/blog/531932#comment-list 摘要: 自动化测试框架demo,用关键字的形式将测试逻辑封装在数据文件中,测 ...
- Python&Selenium 关键字驱动测试框架之数据文件解析
摘要:在关键字驱动测试框架中,除了PO模式以及一些常规Action的封装外,一个很重要的内容就是读写EXCEL,在团队中如何让不会写代码的人也可以进行自动化测试? 我们可以将自动化测试用例按一定的规格 ...
- selenium 关键字驱动部分设计思路
1 说明: 1.以下的代码亲测直接可用, 2.设计思路来自博客园的 张飞_ :http://www.cnblogs.com/zhangfei/p/5330994.html / http://w ...
- 数据驱动 vs 关键字驱动:对搭建UI自动化测试框架的探索
UI自动化测试用例剖析 让我们先从分析一端自动化测试案例的代码开始我们的旅程.以下是我之前写的一个自动化测试的小Demo.这个Demo基于Selenium与Java.由于现在Selenium在自动化测 ...
- Appium 自动化测试框架:关键字驱动+数据驱动
1. 关键字驱动框架简介 2. 框架结构说明 3. 框架代码实现 action 包 page_action.py business_process 包 case_process.py data_so ...
- UI自动化测试框架:关键字驱动+数据驱动
1. 关键字驱动框架简介 2. 工程结构说明 3. 工程代码实现 action 包 page_action.py business_process 包 case_process.py data_so ...
- java自动化-关键字驱动在junit接口自动化的应用
本文是继承上文的基础上进行的讨论,建议读者先阅读http://www.cnblogs.com/xuezhezlr/p/9097137.html和https://www.cnblogs.com/xuez ...
随机推荐
- localStorage与location的用法
1.localStorage 是h5提供的客户端存储数据的新方法: 之前,这些都是由 cookie 完成的.但是 cookie 不适合大量数据的存储,因为它们由每个对服务器的请求来传递,这使得 coo ...
- usaco training 4.2.4 Cowcycles 题解
Cowcycles题解 Originally by Don Gillies [International readers should note that some words are puns on ...
- vijos1010题解
题目: 话说乾隆带着他的宰相刘罗锅和你出巡江南,被杭州城府邀请去听戏,至于什么戏,那就不知了.乾隆很高兴,撒酒与君臣共享.三更欲回住处,可是乾隆这人挺怪,他首先要到西湖边散散步,而且命令不准有人跟着他 ...
- 【hibernate 初探】之 关系映射,ORM
从整理上讲,一个ORM框架(以hibernate为例)所涉及内容无非就是,如何映射,如何检索,还有事务处理.所以从这三方面入手,基本上可以保证将hibernate可以用到自己的项目之中.所以我先说一下 ...
- JAVA 中数组的几种排序方法
1.数组的冒泡排序 public void bubbleSort(int a[]) { int n = a.length; for (int i = 0; i < n - ...
- nopCommerce 3.9 大波浪系列 之 汉化-Roxy Fileman
官网:http://www.roxyfileman.com/ 中文包:zh.json 1.将zh.json包拷贝到Nop.Admin项目中"Content\Roxy_Fileman\lang ...
- FreeRTOS——中断管理
1. 只有以“FromISR”或"FROM_ISR"结束的API函数或宏才可以在中断服务函数中使用. 2. 除互斥信号量外,所有类型的信号量都可以调用 xSemaphoreTake ...
- 安装 Docker Machine - 每天5分钟玩转 Docker 容器技术(45)
前面我们的实验环境中只有一个 docker host,所有的容器都是运行在这一个 host 上的.但在真正的环境中会有多个 host,容器在这些 host 中启动.运行.停止和销毁,相关容器会通过网络 ...
- 认识cpu、核与线程
作为一个后台开发人员,我想有必要了解这些基础知识.如果本文有不严谨或者疏忽的地方,请指正. cpu与核心 物理核 物理核数量=cpu数(机子上装的cpu的数量)*每个cpu的核心数 虚拟核 所谓的4核 ...
- 【firefox】关闭firefox缓存
在Firefox中关闭缓存 看看这里 在地址栏输入:about:config 然后在过滤器中输入:browser.cache.disk.enable 解释:When a page is loaded, ...