1 selenium IDE--录制脚本

准备工作:firefox 浏览器安装了selenium IDE 插件

实例:打开百度搜索“软件测试”

  1. firefox浏览器打开网址:https://www.baidu.com/
  2. 点击浏览器插件【selenium】图标,弹出selenium IDE 录入界面,Base URL设置为:https://www.baidu.com/(默认为录制状态)
  3. 在步骤1中,直接输入“软件测试”关键字,点击【百度一下】进行搜索
  4. selenium IDE 点击【停止录制】红点,如下图:table中记录了我们刚才的操作

2 selenium IDE--回放脚本

  1. 回放脚本时需要先开启selenium服务,进入jar包目录,输入cmd命令:java -jar selenium-server-standalone-2.40.0.jar
  2. selenium IDE 点击【回放用例】按钮,如下图1:
  3. 保存为baidu_search.py脚本(附录脚本),如下图2:

# -*- coding: utf-8 -*-

'''
时间:2015.04.16
作者:chenfenping
功能:百度搜索软件测试实例演示selenium IDE的使用
'''

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re class baidu_search(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "https://www.baidu.com/"
self.verificationErrors = []
self.accept_next_alert = True def test_11(self):
driver = self.driver
# open | / |
driver.get(self.base_url + "/")
# click | id=kw |
driver.find_element_by_id("kw").click()
# type | id=kw | 软件测试
driver.find_element_by_id("kw").clear()
driver.find_element_by_id("kw").send_keys(u"软件测试")
# click | id=su |
driver.find_element_by_id("su").click() def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException, e: return False
return True def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors) if __name__ == "__main__":
unittest.main()

selenium IDE--录制和回放脚本的更多相关文章

  1. Selenium----Selenium简单介绍以及Selenium IDE环境搭建,脚本录制

    1.selenium简单介绍 心得:作为一个新手开始了解这个工具,打算从录制脚本开始学习,“录制,看,学习,写”,总结网友说得打算先使用Selenium IDE录制学习,再使用Selenium RC开 ...

  2. Android自动化测试之MonkeyRunner录制和回放脚本

    Android自动化测试之MonkeyRunner录制和回放脚本(十一) 分类: 自动化测试 Android自动化 2013-02-22 10:57 7346人阅读 评论(2) 收藏 举报 andro ...

  3. 1.2 selenium IDE录制脚本

    1.打开Firefox浏览器中 selenium IDE

  4. selenium IDE录制脚本和自定义脚本-->Katalon Recorder(二)

    selenium IDE提供了两种生成脚本的方式:录制脚本和自定义脚本 录制脚本:1.打开firefox空白标签,在标签上输入需要录制脚本的网址:2.打开selenium IDE界面中的录制按钮(圆形 ...

  5. Selenium IDE录制脚本时弹出窗口的完美处理

    很多朋友录制脚本时新打开弹出窗口后无法定位元素,我也遇到同样的问题,国内没有什么好的资料,于是就阅读英文,不断尝试,感觉那个selectWindow(title)什么就是个坑,我用这种方法成功处理后得 ...

  6. Selenium IDE录制脚本

    一.当Selenium IDE中Format没有转换格式时,操作:Options—Options...—勾选Enable experimental features

  7. selenium IDE录制

    一.        安装 可以用Firefox打开https://addons.mozilla.org/en-US/firefox/addon/selenium-ide/,在这里边找到和当前firef ...

  8. selenium ide 录制回放link链接报错

    回放是出现以下错误: 也就是回放点击打开新的链接时出现这个错误, 这个问题说的是 点击此链接会新打开一个窗口 selenium1是不支持多窗口切换的 因此会卡在这里,也就录制不支持这个操作,但是很多书 ...

  9. 1.3 selenium IDE录制脚本转换为其他代码格式

    1.在seleniumIDE录制框中点击Options->options... 在Enable experimental features前打对勾,点击确定.

随机推荐

  1. POJ C程序设计进阶 编程题#3:运算符判定

    编程题#3:运算符判定 来源: POJ (Coursera声明:在POJ上完成的习题将不会计入Coursera的最后成绩.) 注意: 总时间限制: 1000ms 内存限制: 65536kB 描述 两个 ...

  2. Show Users Assigned to a Specific Role

    In a previous post I showed you how to know what Roles are assigned to a specific user. But here is ...

  3. sql批量修改插入数据

    1.批量修改 select 'update 读者库 set 单位代码='''+新单位代码+''' where 单位代码='''+单位代码+'''' from 读者单位 ,)<'L' and is ...

  4. HTML 5 Canvas

    HTML 5 Canvas   HTML5 的 canvas 元素使用 JavaScript 在网页上绘制图像. <canvas id="myCanvas" width=&q ...

  5. shell字符串操作详解

    shell字符串操作详解的相关资料. 1.shell变量声明的判断  表达式 含义 ${var} 变量var的值, 与$var相同 ${var-DEFAULT} 如果var没有被声明, 那么就以$DE ...

  6. 关于js一般对象与标配对象

    当一个js函数对象被创建时,Function 构造器产生的函数对象会运行类似这样的一些代码 this.prototype={constructor:this} 新函数被赋予了一个prototype属性 ...

  7. 状态可以通过动画切换的按钮--第三方开源--TickPlusDrawable

    Android tickplusdrawable(TickPlusDrawable)在github上的项目主页是:https://github.com/flavienlaurent/tickplusd ...

  8. Pull解析xml

    没有写抛出的异常,例子是含有多个Person对象persons.xml(此片内容未写写入的代码),包含id,name,email,address标签,Person对象含有id,name,email,a ...

  9. 一个自定义的C#数据库操作基础类 SqlHelper

    SqlHelper其实是我们自己编写的一个类,使用这个类目的就是让使用者更方便.更安全的对数据库的操作,既是除了在SqlHelper类以外的所有类将不用引用对数据库操作的任何类与语句,无须担心数据库的 ...

  10. 使用WIF实现单点登录Part IV —— 常见问题

    InvalidOperationException: ID1073: 尝试使用 ProtectedData API 解密 Cookie 时出现 CryptographicException (有关详细 ...