模拟浏览器,人工测试 http://hlee.iteye.com/blog/768459
1. 文本框填充:
直接填充 :
通过节点赋值 :
2. 点击操作超链接
点击元素: 通过Id 找到名为tab_user 的元素点击
直接点击 'edit' 的超链接
3. 点击按钮
4. test confirm dialog 确认对话框
5. 判断确认对话框返回值
it "更新用户密码--成功" do
6. 判断内容
判断当前路径:
7.
8.
9.上传文件输入
10. cannot fill in, no text field, text area or password field with id, name, or label
11. 判断该元素是否存在通过xpath
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}"