Selenium ide及webDriver使用
官方网站:http://seleniumhq.org/
Selenium-IDE于firefox上脚本测试。并可以通过该插件生成对应Java webDriver适用的Junit测试代码。 下面是根据Firefox上录制产生的Junit代码,部分找HTML的ELEMENT时候代码需要自己手动更改。
1 package com.example.tests; 2 3 import java.util.concurrent.TimeUnit; 4 import org.junit.*; 5 import static org.junit.Assert.*; 6 import org.openqa.selenium.*; 7 import org.openqa.selenium.firefox.FirefoxDriver; 8 import org.openqa.selenium.support.ui.Select; 9 10 public class TestDemo { 11 private WebDriver driver; 12 private String baseUrl; 13 private StringBuffer verificationErrors = new StringBuffer(); 14 @Before 15 public void setUp() throws Exception { 16 // driver = new HtmlUnitDriver(); 17 driver = new FirefoxDriver(); 18 baseUrl = "http://localhost:8080/"; 19 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 20 } 21 22 @Test 23 public void test() throws Exception { 24 driver.get(baseUrl + "/pcloud-web/serve/login.do"); 25 driver.findElement(By.id("userId")).clear(); 26 driver.findElement(By.id("userId")).sendKeys("hello@163.com"); 27 driver.findElement(By.id("fullName")).clear(); 28 driver.findElement(By.id("fullName")).sendKeys("hello@163.com"); 29 driver.findElement(By.id("mobile")).clear(); 30 driver.findElement(By.id("mobile")).sendKeys("13932132121"); 31 driver.findElement(By.id("submit")).click(); 32 driver.findElement(By.id("phone")).clear(); 33 driver.findElement(By.id("phone")).sendKeys("13932132121"); 34 driver.findElement(By.id("phone-check")).click(); 35 driver.findElement(By.id("phone-check")).clear(); 36 driver.findElement(By.id("phone-check")).sendKeys("13932132121"); 37 new Select(driver.findElement(By.id("face-select"))).selectByVisibleText("10元"); 38 Thread.sleep(1000); 39 //开始直接购买 40 driver.findElement(By.id("direct-charge")).click(); 41 Thread.sleep(5000); 42 for (String handle : driver.getWindowHandles()) { 43 driver.switchTo().window(handle); 44 } 45 driver.findElement(By.xpath("(//a[contains(text(),'我的订单')])[2]")).click(); 46 Thread.sleep(1000); 47 try { 48 assertTrue(driver.findElement(By.cssSelector("td[class='status']")).getText().equals("成功")); 49 } catch (Error e) { 50 verificationErrors.append(e.toString()); 51 } 52 } 53 54 @After 55 public void tearDown() throws Exception { 56 driver.quit(); 57 String verificationErrorString = verificationErrors.toString(); 58 if (!"".equals(verificationErrorString)) { 59 fail(verificationErrorString); 60 } 61 } 62 63 private boolean isElementPresent(By by) { 64 try { 65 driver.findElement(by); 66 return true; 67 } catch (NoSuchElementException e) { 68 return false; 69 } 70 } 71 }
转载于:https://www.cnblogs.com/hzcxy/archive/2012/12/19/2824694.html
Selenium ide及webDriver使用相关推荐
- Selenium大家族介绍(selenium RC,selenium IDE, selenium Grid, selenium Webdriver)
Selenium selenium 是当下非常流行的自动化测试框架,selenium是开源项目. selenium是一个大家族,这个家族中的主要成员有如下所示: selenium RC: seleni ...
- Selenium IDE工具界面剖析
资源推荐: 视频资源: 软件测试相关系列视频 社区资源: 自动化测试交流群 Selenium IDE简介 Selenium IDE(Integrated Development Environment ...
- 功能测试——房屋租赁系统(Selenium IDE)
源代码:https://gitee.com/shentuzhigang/mini-project/tree/master/test-house-rental 测试需求 打开浏览器(请用 Google ...
- python selenium ide使用_第 2 章 Selenium IDE 的使用 Selenium 3+Python 3 自动化测试
第 2 章 Selenium IDE 的使用 Selenium IDE,官方给出的一个总结是:「针对 Web 自动化的一种录制回放型的解决方案.」它提供了很简洁的录制流程,初学者非常容易上手. 最新的 ...
- 使用Selenium IDE进行自动化测试
1. 综述 Selenium IDE是火狐浏览器的一个插件,它会记录你在网页中进行的操作,如登陆.点击等.更为强大的是它还能将记录导出,例如导出成junit测试用例,非常强大,接下里将会看见. 在火狐 ...
- Selenium IDE安装与运行
Selenium IDE 是什么? Selenium IDE:是一个Firefox插件,用于记录和播放用户与浏览器的交互. (录制Web操作脚本) 为什么要学习Selenium IDE? 1. 使用S ...
- 基于网页自动化Selenium IDE的安装与部署 图书馆选座、网站防休眠、自动点击等
基于网页自动化Selenium IDE的安装与部署 一. Selenium IDE的简介.安装与使用 1. 什么是Selenium IDE? 2. Selenium IDE的安装和使用 3. 导出内容 ...
- Selenium IDE使用指南二(命令行运行器)
现在,您可以在任何浏览器上,并行和在Grid上运行所有Selenium IDE测试,而无需编写任何代码. 只需安装Selenium IDE命令行运行程序,获取必要的浏览器驱动程序(如果在本地运行测试) ...
- Selenium IDE使用指南四(代码导出)
入门 您可以通过右键单击测试或套件,选择Export,选择目标语言,然后单击,将测试或套件的测试导出到WebDriver代码Export. 这会将包含导出的目标语言代码的文件保存到浏览器的下载目录中. ...
最新文章
- 从源码学习Transformer!
- python主要是干什么用的-Python到底可以干什么?主要应用领域
- Logistic Regression--逻辑回归算法汇总
- Android 向服务器发送XML数据及调用webservice
- 使用 systemd 定时器调度任务
- 【iCore4 双核心板_ARM】例程二十九:SD_IAP_FPGA实验——更新升级FPGA
- Java编程思想笔记(内部类)
- poj 3071 Football 概率dp
- EKF_SLAM一般过程
- scrapy 保存html页面,28.用配合scrapy的方式爬取本地保存的html
- 网易云音乐推荐系统特训_笔记
- HTC手机手动解锁教程
- SQL 查询分析器操作(修改、添加、删除)表及字段等
- SDHC或SD2.0卡的驱动程序的注意事项
- 基于PHP服装购物网站的设计与实现
- PDF工具Adobe Arcrobat Pro DC下载安装教程
- week4——实验题解(csp模拟1)
- 计算机的集成显卡是什么意思,IGD、PEG、PCI的含义,我的电脑是集成显卡该选哪一项...
- 2019春招前端面试: 闯关记(精排精校)
- 1000亩盐碱地试验田 国稻种芯-田国庆:拓荒精神荒滩变良田
热门文章
- abaqus生成adams柔性体_Abaqus和STAR-CCM+流固耦合
- 数据挖掘、数据分析、人工智能及机器学习课程资源
- ARM、DSP、FPGA的技术特点和区别
- W Zong / A Robust Open-source Algorithm to Detect Onset and Duration of QRS Complexes
- “21天好习惯”第一期-9
- 比较 Cache 和虚拟存储器,说明它们的相似点和不同。
- php开发我的收藏,我的收藏列表 · 老猫带你玩转ThinkPHP5 API开发 · 看云
- rdd分组聚合算子xxByKey,xxBy
- ubtunu开机黑屏无桌面解决方法
- 《一切皆是映射:代码的本质》哈希算法 (Hash)