- 浏览: 538684 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
小灯笼:
Selenium自动化测试实战网盘地址:https://pan ...
selenium对flex程序的自动化测试 -
noizz:
linux下也有效碰到一个snv update无法识 ...
解决jenkins控制台中文乱码问题 -
liuweihug:
图说浏览器的缓存原理及缓存方式说明(1) http://www ...
终于弄清楚浏览器的缓存机制了 -
dayudodo:
或者再简单一上些,直接在Gemfile中添加gem 'thin ...
运行thin start报错的解决方法 -
tiroc:
试一下这样:
group :development do
...
运行thin start报错的解决方法
Introduction
The Ruby bindings for Selenium/WebDriver are available as the selenium-webdriver gem. There are many other Selenium gems out there, but this is the only official, maintained gem. If you're looking for a slightly higher level API built on the same technology, you may want to check out watir-webdriver.
The bindings support Ruby 1.8.7 through 1.9.2, JRuby and Rubinius.
The gem also includes the older selenium-client gem for use with Selenium RC. When reading the docs, keep in mind that these two namespaces refer to different APIs:
- Selenium::WebDriver - the WebDriver API
- Selenium::Client - Selenium RC API (previously released as the selenium-client gem)
For people who are new to Selenium, we recommend starting directly with Selenium::WebDriver, and focusing on the two main classes,Selenium::WebDriver::Driver and Selenium::WebDriver::Element. This is the entry point to the whole WebDriver API.
The rest of this document deals with Selenium::WebDriver exclusively.
API Example
The bindings provide a slightly rubified version of the WebDriver API:
require "selenium-webdriver" driver = Selenium::WebDriver.for :firefox driver.navigate.to "http://google.com" element = driver.find_element(:name, 'q') element.send_keys "Hello WebDriver!" element.submit puts driver.title driver.quit
Driver examples:
# execute arbitrary javascript puts driver.execute_script("return window.location.pathname") # wait for a specific element to show up wait = Selenium::WebDriver::Wait.new(:timeout => 10) # seconds wait.until { driver.find_element(:id => "foo") }
Element examples:
# get an attribute class_name = element.attribute("class") # is the element visible on the page? element.displayed? # click the element element.click # get the element location element.location # scroll the element into view, then return its location element.location_once_scrolled_into_view # get the width and height of an element element.size # press space on an element - see Selenium::WebDriver::Keys for possible values element.send_keys :space # get the text of an element element.text
Advanced user interactions (see ActionBuilder):
driver.action.key_down(:shift). click(element). double_click(second_element). key_up(:shift). drag_and_drop(element, third_element). perform
IE
Make sure that Internet Options → Security has the same Protected Mode setting (on or off, it doesn't matter as long as it is the same value) for all zones.
Chrome
Command line switches
For a list of switches, see chrome_switches.cc:
driver = Selenium::WebDriver.for :chrome, :switches => %w[--ignore-certificate-errors --disable-popup-blocking --disable-translate]
Tweaking profile preferences
For a list of prefs, see pref_names.cc.
profile = Selenium::WebDriver::Chrome::Profile.new profile['download.prompt_for_download'] = false profile['download.default_directory'] = "/path/to/dir" driver = Selenium::WebDriver.for :chrome, :profile => profile
See also ChromeDriver. The RemoteWebDriver makes it easy to control a browser running on another machine. Download the jar (from Downloads) and launch the server: java -jar selenium-server-standalone.jar Then connect to it from Ruby By default, this connects to the server running on localhost:4444 and opens Firefox. To connect to another machine, use the :url option: To launch another browser, use the :desired_capabilities option: You can also pass an instance of Selenium::WebDriver::Remote::Capabilities, e.g.: You may want to set the proxy settings of the remote browser (this currently only works for Firefox): Or if you have a proxy in front of the remote server: See `Selenium::WebDriver::Proxy` for more options. For the remote Firefox driver you can configure the profile, see the section Tweaking Firefox preferences. The FirefoxDriver lets you configure the profile used. It's often useful to have Firebug available in the Firefox instance launched by WebDriver: You can use an existing profile as a template for the WebDriver profile by passing the profile name (see firefox -ProfileManager to set up custom profiles.) If you want to use your default profile, pass :profile => "default" You can also get a Profile instance for an existing profile and tweak its preferences. This does not modify the existing profile, only the one used by WebDriver. Use a proxy: Automatically download files to a given folder: If you are using the remote driver you can still configure the Firefox profile: For a list of possible preferences, see this page. If your Firefox executable is in a non-standard location: Native events are enabled by default on Windows. To turn them off: Experimental support for native events is available on Linux. Set profile.native_events = true to turn this on. The OperaDriver is always run as a RemoteWebDriver server which the Ruby bindings connect to. To get started, first download the selenium-server-standalone jar and set the SELENIUM_SERVER_JAR environmental variable to point to its location: export SELENIUM_SERVER_JAR=/path/to/server-standalone.jar Then you can simply create a new instance of Selenium::WebDriver with the :opera option: WebDriver lets you configure implicit waits, so that a call to #find_element will wait for a specified amount of time before raising aNoSuchElementError: Use the Wait class to explicitly wait for some condition: Internally, WebDriver uses HTTP to communicate with a lot of the drivers (the JsonWireProtocol). By default, Net::HTTP from Ruby's standard library is used, which has a default timeout of 60 seconds. If you call Driver#get on a page that takes more than 60 seconds to load, you'll see a TimeoutError raised from Net::HTTP. You can configure this timeout (before launching a browser) by doing: You can use webdriver to handle Javascript alert(), prompt() and confirm() dialogs. The API for all three is the same. Note: At this time alert handling is only available in Firefox and IE (or in those browsers through the remote server), and only alerts that are generated post onload can be captured. For internal HTTP communication, Net::HTTP is used by default. If you e.g. have the Curb gem installed, you can switch to it by doing: If you have the net-http-persistent gem installed, you can (as of 0.1.3) similarly use "selenium/webdriver/remote/http/persistent" to get keep-alive connections. This will significantly reduce the ephemeral ports usage of WebDriver, which is useful in some contexts. Note that this currently only works with the remote Java server (the other servers doesn't yet support keep-alive).
Remote
driver = Selenium::WebDriver.for(:remote)
driver = Selenium::WebDriver.for(:remote, :url => "http://myserver:4444/wd/hub")
driver = Selenium::WebDriver.for(:remote, :desired_capabilities => :chrome)
include Selenium
caps = WebDriver::Remote::Capabilities.htmlunit(:javascript_enabled => true)
driver = WebDriver.for(:remote, :desired_capabilities => caps)
include Selenium
caps = WebDriver::Remote::Capabilities.firefox(:proxy => WebDriver::Proxy.new(:http => "myproxyaddress:8080"))
driver = WebDriver.for(:remote, :desired_capabilities => caps)
include Selenium
client = WebDriver::Remote::Http::Default.new
client.proxy = Proxy.new(:http => "proxy.org:8080")
driver = WebDriver.for(:remote, :http_client => client)
Firefox
Adding an extension
include Selenium
profile = WebDriver::Firefox::Profile.new
profile.add_extension("/path/to/firebug.xpi")
driver = WebDriver.for :firefox, :profile => profile
Using an existing profile
driver = Selenium::WebDriver.for(:firefox, :profile => "my-existing-profile")
default_profile = Selenium::WebDriver::Firefox::Profile.from_name "default"
default_profile.native_events = true
driver = Selenium::WebDriver.for(:firefox, :profile => default_profile)
Tweaking Firefox preferences
profile = Selenium::WebDriver::Firefox::Profile.new
proxy = Selenium::WebDriver::Proxy.new(:http => "proxy.org:8080")
profile.proxy = proxy
driver = Selenium::WebDriver.for :firefox, :profile => profile
profile = Selenium::WebDriver::Firefox::Profile.new
profile['browser.download.dir'] = "/tmp/webdriver-downloads"
profile['browser.download.folderList'] = 2
profile['browser.helperApps.neverAsk.saveToDisk'] = "application/pdf"
driver = Selenium::WebDriver.for :firefox, :profile => profile
profile = Selenium::WebDriver::Firefox::Profile.new
profile['foo.bar'] = true
capabilities = Selenium::WebDriver::Remote::Capabilities.firefox(:firefox_profile => profile)
driver = Selenium::WebDriver.for :remote, :desired_capabilities => capabilities
Custom Firefox path
Selenium::WebDriver::Firefox.path = "/path/to/firefox"
driver = Selenium::WebDriver.for :firefox
Native events
profile = Selenium::WebDriver::Firefox::Profile.new
profile.native_events = false
driver = Selenium::WebDriver.for(:firefox, :profile => profile)
Opera
driver = Selenium::WebDriver.for :opera
driver.navigate.to 'http://opera.com/'
Timeouts
Implicit waits
driver = Selenium::WebDriver.for :firefox
driver.manage.timeouts.implicit_wait = 3 # seconds
Explicit waits
wait = Selenium::WebDriver::Wait.new(:timeout => 3)
wait.until { driver.find_element(:id => "cheese").displayed? }
Internal timeouts
client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 120 # seconds
driver = Selenium::WebDriver.for(:remote, :http_client => client)
JavaScript dialogs
require "selenium-webdriver"
driver = Selenium::WebDriver.for :firefox
driver.navigate.to "http://mysite.com/page_with_alert.html"
driver.find_element(:name, 'element_with_alert_javascript').click
a = driver.switch_to.alert
if a.text == 'A value you are looking for'
a.dismiss
else
a.accept
end
Using Curb or your own HTTP client
require 'selenium/webdriver/remote/http/curb'
include Selenium
client = WebDriver::Remote::Http::Curb.new
driver = WebDriver.for(:firefox, :http_client => client)
发表评论
-
测试用例优先级和BUG优先级关系
2014-08-26 17:17 29851 测试用例优先级定义 优先级 描述 ... -
缺陷管理工具Bug定义的规范
2014-08-26 16:52 21421 BUG严重程度 严重程度 ... -
功能测试:三轮测试的定义
2014-08-26 16:44 20961 前提 对系统的功能性验证已建立测试用例库,测试用 ... -
android自动化测试
2014-07-23 11:02 790见附件 -
selenium-webdriver ruby 最大化浏览器窗口
2012-10-10 14:46 5354selenium-webdriver没有提供非IE浏览器的ma ... -
selenium webdriver杂记
2012-06-26 14:03 35891 简述 通过研究selenium-webdriver ... -
vbscript自定义import函数
2012-04-11 11:57 1145vbscript本身不提供impot功能,需要自定义 ... -
Watir文档大全
2012-03-16 11:31 15121 watir-webdriver class API ht ... -
Watir get started
2012-03-16 11:31 1139Getting Started Load t ... -
测试用例review
2012-01-29 14:56 1697原文来自: http://hi.baidu.com/%C9%C ... -
Watir关闭所有IE窗口的3种方法
2012-01-09 16:04 16641. 循环 def close_all_windows ... -
VBScript计算一个月有多少天
2011-11-22 17:16 1041Function DaysOfMonth(aYear,a ... -
VBScript格式化时间
2011-11-22 17:14 1144Function Format_DateWithoutT ... -
VBScript获取给定Timezone的Date
2011-11-22 17:13 1090Function Get_TimeZone_Specif ... -
selenium对flex程序的自动化测试
2011-10-28 12:13 4826原文来自: http://seleniumc ... -
用Selenium实现对Flex应用的支持
2011-10-28 11:29 1750原文来自: http://seleniumcn.cn/simp ... -
VBScript格式化函数(FormatCurrency FormatDateTime FormatNumber FormatPercent)
2011-10-25 11:26 1635FormatCurrency 函数 返回表达式,此表达式 ... -
Selenium 2.0 and WebDriver
2011-09-09 10:33 4260NOTE: We’re curre ... -
Selenium - Test Design Considerations
2011-09-09 10:27 10011Introducing Tes ... -
RubyDevelopment on selenium
2011-09-09 10:23 745Introduction This page deta ...
相关推荐
Over 90 recipes to help you build and run automated tests for your web applications with Selenium WebDriver About This Book Learn to leverage the power of Selenium WebDriver with simple examples that...
This guide will provide you with all the skills you need to successfully create a functional Selenium test suite. Starting from the very beginning of the Selenium IDE, this book will show you how to ...
### Selenium Testing with Python #### 一、Selenium简介与应用 **Selenium** 是一个用于 Web 应用程序测试的工具。它支持多种浏览器(如 Firefox、Chrome 和 Safari)以及多种编程语言(如 Java、C#、Ruby 和 ...
- **书籍**: 《The RSpec Book: Behaviour Driven Development with RSpec, Cucumber, and Friends》虽然主要聚焦于RSpec,但也涵盖了Watir和自动化测试的最佳实践。 #### Ruby开源项目推荐 1. **forem**: - 一个...
此外,还可以使用如Selenium这样的库进行更高级的浏览器控制,以处理JavaScript渲染的页面。 至于提供的"mechanize-master"压缩包,这很可能是Mechanize库的源代码仓库。如果你希望深入了解Mechanize的内部实现或对...
它支持多种编程语言,包括 Java、Python、C#、Ruby 等,而 "Selenium Deno 端口" 则意味着 Selenium 已经被扩展到支持 Deno 这个 JavaScript 和 TypeScript 的运行时环境中。Deno 是由 Ryan Dahl(Node.js 的创建者...
3. **Selenium-with-Junit** 和 **Selenium-with-Python** - 通过 JUnit 或 Python 实现的测试框架示例。 **持续集成和自动化** 1. **Jenkins** - 广泛使用的 CI/CD 工具,支持集成 Selenium 自动化测试。 2. **...
#BDD 与 PageObject 使用 Selenium-Webdriver、Cucumber 和 Ruby 从头开始的分步示例 您将看到我们如何使用页面对象从头开始一步一步地按照 BDD 构建自动化测试框架。
人流 :people_with_bunny_ears: :male_sign_selector: 神奇的宝石的自然伴侣,该宝石可控制大量的Chrome窗口和选项卡,并通过任何Ruby脚本模拟真实用户与Web应用程序的交互。 可与您的系统Chrome或Chromium自然配合...
Appium基于WebDriver协议,这意味着它可以与Selenium WebDriver接口无缝对接,从而支持多种编程语言,如Java、Python、Ruby等。Appium通过模拟用户的行为,如点击、滑动、输入文本等,来验证应用程序的功能和性能。 ...
This book is intended for software quality assurance/testing professionals, software project managers, or software developers with prior experience in using Selenium and Java to test web-based ...
具有RSpec和Capybara的Dockerized Selenium网格我构建该项目的目的是快速提供一个针对dockerized应用程序运行UI测试的dockerized环境。 它使用泊坞窗化的 ,与购买和维护专用计算机相比,它提供了更具成本效益的CI...
在本示例中,"web-scrapping-mechanize-firstmeetup" 是一个项目,由阿方索·曼西拉(Alfonso Mancilla)在一次 Ruby 聚会上介绍,展示了如何利用 Ruby 的机械化(Mechanize)库来实现这一过程。机械化是一个强大的...
确保您已安装 Ruby on Rails、Cucumber 和 Capybara -目前仅支持 Ruby 1.9.3 for Windows下面是关于安装 Cucumber for windows 的一些优秀说明 如果您收到 SSL 认证错误,请参阅此博客, 确保安装了 Selenium ...
用于使用RSpec,Capybara,Selenium和SitePrism构建用于无头和浏览器测试的测试自动化框架的原型。 设置 Clone this project bundle 运行规格 rspec # to run all specs, with default driver and env rspec -t ...
capybara-chromedriver-logger 该gem为在Chromedriver下运行的Ruby功能规范提供console.log调试输出。... # This wraps Selenium::WebDriver::Remote::Capabilities.chrome() with the # correct sett
1. **Python**:Python 是一个非常适合进行网页抓取和图片下载的语言,有许多库可以帮助我们实现这个功能,如BeautifulSoup、Scrapy、Selenium等。可以编写脚本来解析HTML,找到图片链接,然后使用requests库下载...
:waving_hand: 嘿,很高兴见到你。 欢迎来到我的网站! 软件质量分析师-质量检查/... :closed_mailbox_with_raised_flag: 向我介绍自动化, Ruby , Go ,Cucumber,机器人框架 语言,框架和工具: 语言和工具: