Rspec Test

模拟浏览器,人工测试 http://hlee.iteye.com/blog/768459

1. 文本框填充:

直接填充 :
 fill_in("#{@user.id}_name",:with=>"jdo")  


通过节点赋值 :
find(:xpath,"//html/body/div[2]/div[2]/div/div/div[3]").set("123456")

2. 点击操作超链接

点击元素: 通过Id 找到名为tab_user 的元素点击
find(:id,"tab_user").click


直接点击 'edit' 的超链接
 find_link("edit").click 


3. 点击按钮

 find_button('Submit').click

click_button('submit')


4. test confirm dialog 确认对话框

page.evaluate_script('window.confirm = function() { return true; }')
page.click('Remove')

5. 判断确认对话框返回值
 When /^I (accept|dismiss) the "([^"]*)" alert$/ do |action, text|
alert = page.driver.browser.switch_to.alert
alert.text.should eq(text)
alert.send(action)
end

it "更新用户密码--成功" do
visit "/orgunits"
find(:id,"tab_user").click
find_link("chgpwd").click
page.should have_content("为用户“#{@user.login}”设置新的密码")
find(:xpath,"//html/body/div[2]/div[2]/div/div/div[2]/input").set("123456")
find(:xpath,"//html/body/div[2]/div[2]/div/div/div[3]/input").set("123456")
find(:xpath, '//html/body/div[2]/div[2]/div[2]/div/a').click
sleep Capybara.default_wait_time 异步休眠, 等待返回结果
alert =page.driver.browser.switch_to.alert
assert alert.text.should == "更新密码成功"
end

6. 判断内容
判断当前路径:
page.current_path.should==url
page.should have_content("表单显示名")
page.should_not have_xpath('link')
page.should_not have_content("Show")

7.
 page.select 'entos', :from => 'flex_table_orgunit_id'
page.choose("flex_table_for_workflow_1")

8.
page.evaluate_script('window.confirm = function() { return true; }')

9.上传文件输入
 Dir["/home/jidong/Downloads/财务部/2.xsn"].each { |f|
page.attach_file 'file' , f
page.click_button "Upload"
page.should have_content("表单名")
page.click_button "Submit"
page.should have_content("视图")
}

10. cannot fill in, no text field, text area or password field with id, name, or label
11. 判断该元素是否存在通过xpath
 page.should  have_no_xpath("//html/body/div/div[4]/div/table/tbody/tr/td[2]/div/div/div/div[2]/div[4]/div/div/div[2]/div[2]/div/div")
page.find(:xpath,"//html/body/div/div[4]/div/table/tbody/tr/td[2]/div/div/div/div[2]/div/div/div/div/div[2]/div/div").text.should_not=="#{@orgunit.name}"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值