Watir Tutorial
Selected Reading
- Watir - Discussion
- Watir - Useful Resources
- Watir - Quick Guide
- Watir - Browser Windows
- Watir - Downloads
- Watir - Alerts
- Watir - Proxies
- Watir - Cookies
- Watir - Page Performance
- Watir - Page Objects
- Watir - Capturing Screenshots
- Watir - Mobile Testing
- Watir - Headless Testing
- Watir - Automatic Waits
- Watir - Working with Iframes
- Watir - Locating Web Elements
- Watir - Web Elements
- Watir - Working with Browsers
- Watir - Installing Drivers for Browsers
- Watir - Environment Setup
- Watir - Introduction
- Watir - Overview
- Watir - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Watir - Page Objects
Watir - Page Objects
瓦杰里的目标页有助于我们以班级的形式重新使用该守则。 利用网页物体特征,我们可以自动进行,而不必重复任何代码,并使该代码能够管理。
在测试时,我们可以为将要测试的每页打上一页。 然后,我们将使用该页标语获取方法和财产。
使用页标的理由——
如果在改动时对该页作任何改动,则不必重写该代码。
避免法典重复。
我们将利用RSpec在瓦伊使用页面目标。 如果你不熟悉RSpec,这里是可供你学习的全套教学课程:
在这里,我们将进行测试。
textbox.html
<html> <head> <title>Testing UI using Watir</title> </head> <body> <script type = "text/javascript"> function wsentered() { console.log("inside wsentered"); var firstname = document.getElementById("firstname"); if (firstname.value != "") { document.getElementById("displayfirstname").innerHTML = "The name entered is : " + firstname.value; document.getElementById("displayfirstname").style.display = ""; } } </script> <span id = "spanfirstname"> Enter First Name : <input type = "text" id = "firstname" name = "firstname" onchange = "wsentered()" /> </span> <br/> <br/> <span style = "display:none;" id = "displayfirstname"></span> </body> </html>
Output
我们现在为上述网页制造一页物体,如下文所示:
pageobjecttest.rb
class InitiapzeBrowser def initiapze(browser) @browser = browser end end class TestPage lt; InitiapzeBrowser def textbox @textbox = TestTextbox.new(@browser) end def close @browser.screenshot.save usingpageobject.png @browser.close end end # TestPage class TestTextbox < InitiapzeBrowser URL = "http://localhost/uitesting/textbox.html" def open @browser.goto URL self end def enterdata_as(name) name_field.set name name_field.fire_event( onchange ) end private def name_field @browser.text_field(:id > "firstname") end end # TestTextbox
界定了三个班级:初始班轮、测试和试验箱。
一旦执行上述守则,你就可以看到产出如下:
Advertisements