Revision as of 17:50, 26 September 2006 editSunSw0rd (talk | contribs)Extended confirmed users796 edits Added Excel example← Previous edit | Latest revision as of 13:51, 8 November 2023 edit undoEmeraude (talk | contribs)Autopatrolled, Extended confirmed users, Pending changes reviewers82,429 editsNo edit summary | ||
(256 intermediate revisions by more than 100 users not shown) | |||
Line 1: | Line 1: | ||
{{More citations needed|date=October 2012}} | |||
''''WATIR'''', pronounced "Water", is an acronym standing for "Web Application Testing in Ruby". Watir is an automated test tool which uses the Ruby scripting language to drive the Internet Explorer web browser, and is available as a Ruby Gem. | |||
{{Infobox software | |||
| name = Watir | |||
| logo = Watir.png | |||
| screenshot = | |||
| caption = | |||
| developer = Bret Pettichord, Charley Baker, Angrez Singh, Jari Bakken, Jarmo Pertman, Hugh McGowan, Andreas Tolf Tolfsen, Paul Rogers, Dave Hoover, Sai Venkatakrishnan, Tom Copeland, Alex Rodionov, Titus Fortner | |||
| latest release version = 6.17 | |||
| latest release date = {{Start date and age|2020|08|28}} | |||
| latest preview version = | |||
| latest preview date = | |||
| programming language = ] | |||
| operating system = ] | |||
| platform = | |||
| genre = ] ] for ]s | |||
| license = ] | |||
| website = {{URL|http://watir.com/}} | |||
}} | |||
'''Watir''' ('''W'''eb '''A'''pplication '''T'''esting '''i'''n '''R'''uby, pronounced water), is an open-source family of ] libraries for automating web browsers.<ref>{{cite web |url=http://watir.com/ |publisher=Watir |accessdate=11 October 2012 |title=Watir is...}}<br>- {{cite web|title=A new member in the Watir-family |url=http://www.opera.com/developer/tools/operawatir/ |publisher=Opera Software |archiveurl=https://web.archive.org/web/20110213011440/http://www.opera.com/developer/tools/operawatir/ |archivedate=13 February 2011 |accessdate=8 November 2023}}<br>- {{cite web |title=Watir to WebDriver: Unit Test Frameworks |url=https://www.facebook.com/notes/facebook-engineering/watir-to-webdriver-unit-test-frameworks/10150314152278920 |website=Facebook |accessdate=11 October 2012 |url-access=subscription}}</ref><ref name="Agile Testing">{{cite book |first1=Lisa |last1=Crispin |first2=Janet |last2=Gregory |title=Agile Testing: A Practical Guide for Testers and Agile Teams|year=2008 |publisher=Addison-Wesley |isbn=9780321534460 |pages=172|url=https://books.google.com/books?id=68_lhPvoKS8C}}</ref> It drives ], ], ], ] and ], and is available as a ] gem.<ref name="Agile Testing" /><ref>{{cite book |last=Marick |first=Brian |title=Everyday Scripting with Ruby: For Teams, Testers, and You |year=2007 |publisher=Pragmatic Programmer |isbn=9780977616619 |page=2 |url=https://books.google.com/books?id=1vKBQgAACAAJ |via=Google Books}}</ref> Watir was primarily developed by Bret Pettichord and Paul Rogers. | |||
== Functionality == | |||
Ruby is an object oriented programming language started more than a decade ago in Japan (by Yukihiro Matsumoto). It is a very “pure” OO language. It is also an interpreted language, and has influences from multiple earlier OO languages. Ruby gems are packaged libraries. | |||
{{Update section|date=April 2021}} | |||
Watir project consists of several smaller projects. The most important ones are watir-classic, watir-webdriver and watirspec. | |||
=== Watir-Classic === | |||
WATIR makes use of the fact that Ruby has built in OLE capabilities. As such it is possible to drive the Microsoft Internet Explorer browser programmatically. Watir is a toolkit for automated tests to be developed and run against a web browser. | |||
Watir-Classic makes use of the fact that Ruby has built-in ] (OLE) capabilities. As such it is possible to drive ''Internet Explorer'' programmatically.<ref>{{cite web |title=Creating automated test scripts with Ruby and WATIR |url=http://www.thoughtworks.com/articles/automated-testing-using-ruby-and-watir |publisher=ThoughtWorks |first=Jeremy |last=Suarez |date=16 September 2010|accessdate=11 October 2012}}</ref> Watir-Classic operates differently to HTTP-based test tools, which operate by simulating a browser. Instead, Watir-classic directly drives the browser through the OLE protocol, which is implemented over the ] (COM) architecture. | |||
The COM permits interprocess communication (such as between Ruby and ''Internet Explorer'') and dynamic object creation and manipulation (which is what the Ruby program does to the ''Internet Explorer''). Microsoft calls this "OLE automation", and calls the manipulating program an "automation controller". Technically, the ''Internet Explorer'' process is the server and serves the automation objects, exposing their methods; while the Ruby program then becomes the client which manipulates the automation objects. | |||
==Examples== | |||
===The google example=== | |||
=== Watir-Webdriver === | |||
# Here we see a very simple WATIR script to drive to google and validate a page | |||
Watir-Webdriver is a modern version of the Watir API based on ]. Selenium 2.0 (Selenium-Webdriver) aims to be the reference implementation of the ] specification. In Ruby, Jari Bakken has implemented the Watir API as a wrapper around the Selenium 2.0 API. Not only is Watir-Webdriver derived from Selenium 2.0, it is also built from the ] specification, so Watir-Webdriver should always be compatible with existing ] specifications. | |||
require 'watir' # use watir gem | |||
test_site = 'http://www.google.com' # set a variable | |||
ie = Watir::IE.new # open the IE browser | |||
ie.goto(test_site) # load url, go to site | |||
ie.text_field(:name, "q").set("pickaxe") # load text "pickaxe" into search field named "q" | |||
ie.button(:name, "btnG").click # "btnG" is the name of the Search button, click it | |||
if ie.contains_text("Programming Ruby") | |||
puts "Test Passed. Found the test string: 'Programming Ruby'." | |||
else | |||
puts "Test Failed! Could not find: 'Programming Ruby'" | |||
end | |||
=== Watirspec === | |||
The previous commands can be executed in the ] (irb), or in a Ruby IDE such as FreeRIDE that is installed when Ruby is installed with the once click installer. | |||
Watirspec is executable specification of the Watir API, like ] is for Ruby. | |||
== |
== See also == | ||
{{Portal|Free and open-source software}} | |||
# To handle general popups, use WinClicker. | |||
* ] | |||
ie.button(:name, "btnG").click_no_wait # ensure popup won't block Watir | |||
* ] | |||
hwnd = ie.enabled_popup(5) # get a handle if one exists | |||
* ] | |||
if (hwnd) # yes there is a popup | |||
* ] | |||
w = WinClicker.new | |||
w.makeWindowActive(hwnd) | |||
w.clickWindowsButton_hwnd(hwnd, "Yes") # click the "Yes" button | |||
end | |||
== References == | |||
This example extends upon the google example by ensuring the google search button click will not wait for the popup. This approach will handle most annoying popups, however it may be necessary to download and install the current development Watir gem rather than using the standard Watir release. | |||
{{Reflist}} | |||
== External links == | |||
===View Browser Objects=== | |||
* | |||
Suppose you want to be able to see the various objects within the browser? The following are useful: | |||
* | |||
* '''' | |||
* '''', a testers' workshop book by Jeff Morgan | |||
] | |||
# To see objects within the browser | |||
] | |||
ie.frame("top_frame").text_fields.each { |t| puts t.to_s } | |||
] | |||
ie.frame("top_frame").spans.each { |s| puts s.to_s } | |||
] | |||
ie.frame("top_frame").tables.each { |t| puts t.to_s } | |||
] | |||
ie.frame("top_frame").links.each { |l| puts l.to_s } | |||
ie.frame("top_frame").select_lists.each { |s| puts s.to_s } | |||
ie.frame("top_frame").labels.each { |l| puts l.to_s } | |||
In the above example, this also shows you how you would access information from within a frame. If there were no frame involved, then drop the "frame("top_frame")." part of the commands. | |||
===Capture Timings=== | |||
Suppose you want to capture timing information, because you are running a performance test? | |||
# Performance test timing | |||
beginTime = 0 | |||
endTime = 0 | |||
beginTime = Time.now | |||
=begin | |||
***************************** | |||
* Body of script goes here | |||
***************************** | |||
=end | |||
endTime = Time.now | |||
p (endTime - beginTime).to_s | |||
Be aware that anything enclosed by an "=begin" and "=end" (on their own lines) is treated as a multi line comment. Typically you might wrap the final button click to submit a page in these commands, and the timing information will then just show you the time from submission to page response. | |||
===Write Output to Excel=== | |||
It may useful to be able to repeatedly record output to an Excel spreadsheet. Data written to a workbook can be displayed graphically in charts. (How to do this will not be provided here, but see the external link called "Ruby and Excel") | |||
Suppose you want to record a sequence of 4 screen to screen transition timings. You might then add the following to your script: | |||
#Read test data input file | |||
arr = IO.readlines("env.txt") | |||
executionEnvironment = arr | |||
acceptableScreen1 = arr.to_f | |||
acceptableScreen2 = arr.to_f | |||
acceptableScreen3 = arr.to_f | |||
acceptableScreen4 = arr.to_f | |||
#Result OK or not | |||
resultValue = "OK" | |||
#Strip line return from tested environment string | |||
executionEnvironment = executionEnvironment.chomp | |||
#open spreadsheet - new one each day this script is run | |||
timeSpreadsheet = File.new( "../PC/" + Time.now.strftime("%d-%b-%y") + ".csv", "a") | |||
=begin | |||
************************** | |||
* Add commands to load data to screen | |||
* Initialize timing variables as in "Capture Timings" example | |||
* Submit the "click" to submit from browser to web server | |||
* Update timing variable as in "Capture Timings" example | |||
************************** | |||
=end | |||
if acceptableScreen1 < actualTime | |||
resultValue = "NotOK" | |||
end | |||
#Log results | |||
timeSpreadsheet.puts executionEnvironment + ",Expected screen 1 time," + acceptableScreen1.to_s | |||
+ ",Actual screen 1 time," + (endTime - beginTime).to_s + "," + resultValue | |||
=begin | |||
************************** | |||
* Repeat this 3 times, once for each of the other 3 screens | |||
* Remember to reinitialize resultValue, endTime, and beginTime each time | |||
************************** | |||
=end | |||
#Close the browser | |||
ie.close if ie | |||
#Close the workbook | |||
timeSpreadsheet.close | |||
Some points about this example. First, the commented parts depend upon the previous examples above. | |||
Second, an input file is read to extract test case information. The information should be written on 5 separate lines. The first line contains a reference to the environment in which this test is run, e.g., "dev", "test", "int_test", etc. This first line is loaded into the variable executionEnvironment. The line feed must be chopped off the end of the string, otherwise when written to Excel this will be on its own line, and the other data would go to the next line -- we want everything in the same row in the worksheet. | |||
Third, the acceptableScreen# variables hold a number -- the expected maximum number of seconds for screen to screen response time. These numbers might all be the same, or different, depending on your test. The values are from lines 2 through 5 in the input file. | |||
Fourth and finally, the line above where the spreadsheet is written has a line break in it for formatting for this site, so if you copy the above you see that it is on two lines -- you would want to put it all on one line. | |||
==External Links== | |||
* | |||
* | |||
* | |||
* | |||
* | |||
==See also== | |||
*] | |||
*] | |||
*] | |||
] |
Latest revision as of 13:51, 8 November 2023
This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed. Find sources: "Watir" – news · newspapers · books · scholar · JSTOR (October 2012) (Learn how and when to remove this message) |
Developer(s) | Bret Pettichord, Charley Baker, Angrez Singh, Jari Bakken, Jarmo Pertman, Hugh McGowan, Andreas Tolf Tolfsen, Paul Rogers, Dave Hoover, Sai Venkatakrishnan, Tom Copeland, Alex Rodionov, Titus Fortner |
---|---|
Stable release | 6.17 / August 28, 2020; 4 years ago (2020-08-28) |
Written in | Ruby |
Operating system | Cross-platform |
Type | Software testing framework for web applications |
License | MIT license |
Website | watir |
Watir (Web Application Testing in Ruby, pronounced water), is an open-source family of Ruby libraries for automating web browsers. It drives Internet Explorer, Firefox, Chrome, Opera and Safari, and is available as a RubyGems gem. Watir was primarily developed by Bret Pettichord and Paul Rogers.
Functionality
This section needs to be updated. Please help update this article to reflect recent events or newly available information. (April 2021) |
Watir project consists of several smaller projects. The most important ones are watir-classic, watir-webdriver and watirspec.
Watir-Classic
Watir-Classic makes use of the fact that Ruby has built-in Object Linking and Embedding (OLE) capabilities. As such it is possible to drive Internet Explorer programmatically. Watir-Classic operates differently to HTTP-based test tools, which operate by simulating a browser. Instead, Watir-classic directly drives the browser through the OLE protocol, which is implemented over the Component Object Model (COM) architecture.
The COM permits interprocess communication (such as between Ruby and Internet Explorer) and dynamic object creation and manipulation (which is what the Ruby program does to the Internet Explorer). Microsoft calls this "OLE automation", and calls the manipulating program an "automation controller". Technically, the Internet Explorer process is the server and serves the automation objects, exposing their methods; while the Ruby program then becomes the client which manipulates the automation objects.
Watir-Webdriver
Watir-Webdriver is a modern version of the Watir API based on Selenium. Selenium 2.0 (Selenium-Webdriver) aims to be the reference implementation of the WebDriver specification. In Ruby, Jari Bakken has implemented the Watir API as a wrapper around the Selenium 2.0 API. Not only is Watir-Webdriver derived from Selenium 2.0, it is also built from the HTML specification, so Watir-Webdriver should always be compatible with existing W3C specifications.
Watirspec
Watirspec is executable specification of the Watir API, like RubySpec is for Ruby.
See also
References
- "Watir is..." Watir. Retrieved 11 October 2012.
- "A new member in the Watir-family". Opera Software. Archived from the original on 13 February 2011. Retrieved 8 November 2023.
- "Watir to WebDriver: Unit Test Frameworks". Facebook. Retrieved 11 October 2012. - ^ Crispin, Lisa; Gregory, Janet (2008). Agile Testing: A Practical Guide for Testers and Agile Teams. Addison-Wesley. p. 172. ISBN 9780321534460.
- Marick, Brian (2007). Everyday Scripting with Ruby: For Teams, Testers, and You. Pragmatic Programmer. p. 2. ISBN 9780977616619 – via Google Books.
- Suarez, Jeremy (16 September 2010). "Creating automated test scripts with Ruby and WATIR". ThoughtWorks. Retrieved 11 October 2012.
External links
- Watir home page
- Watir source code
- The Watir Podcast
- Cucumber & Cheese, a testers' workshop book by Jeff Morgan