ruby+watir-webdriver自动化测试入门

百度搜索(python):

from selenium import webdriver

driver=webdriver.Chrome()
driver.get("http://www.baidu.com")
driver.find_element_by_id("kw").send_keys("cz9025")
driver.find_element_by_id("su").click()
driver.quit()

百度搜索(ruby):

require 'rubygems'
require "watir-webdriver"

b = Watir::Browser.new :chrome
b.goto "http://www.baidu.com"
b.text_field(:id => 'kw').set "cz9025"
b.button(:id => "su").click
sleep 3
b.quit

两者对比,使用方式大同小异。

ruby定位元素:

标签说明
buttoninput tags with type=button, submit, image or reset
radioinput tags with the type=radio; known as radio buttons
check_boxinput tags with type=checkbox
text_fieldinput tags with the type=text (single-line), type=textarea (multi-line), and type=password
hiddeninput tags with type=hidden
selectselect tags, known as drop-downs or drop-down lists
labellabel tags (including “for” attribute)
spanspan tags
divdiv tags
pp (paragraph) tags
linka (anchor) tags
tabletable tags, including row and cell methods for accessing nested elements.
imageimg tags
formform tags
frameframes, including both the frame elements and the corresponding pages.
mapmap tags
areaarea tags
lili tags

部分使用示例:

element

b.element(:id => "su").click

button

b.button(:id => "su").click

text_field

set是设置值,value是取值

b.text_field(:id => 'kw').set "cz9025"

select

b.select(:name => "NR").select "每页显示20条"

ruby+watir-webdriver,支持的浏览器有Firefox、Chrome 、IE等大部分浏览器。

定位:支持所有的HTML元素

定位方式:支持id、name、class、xpath等常用的方式

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值