Watir-Ruby open-source Web automation testing framework

Source: Internet
Author: User

Watir is an open-source Web automation testing framework implemented using Ruby. Compared with those large commercial tools, watir is small, flexible, and provides sufficient functions. Recently, I took the time to try it out. I feel pretty good. I plan to use it in the company for further promotion. The user manual, sample code, and FAQ on watir are well maintained, so I will not repeat the existing items. Here, I will briefly introduce them. If you are interested, you can study it together.


  1. Script example

First, I will drop a script to show you how convenient it is to use watir to write the script. The following example shows a script that is provided by watir to test the Google search function. However, I only keep the most important part to make it look more concise: require 'watir' # The watir controller # Open the IE Browser IE = watir: IE. new # Step 1: Go to the test site: http://www.google.com IE. goto (http://www.google.com) # Step 2: Enter 'pickaxe' in the search text field IE. text_field (: name, "Q "). set ("Pickaxe") # Q is the name of the search field # Step 3: Click the 'Google search' button I E. button (: name, "btng "). click # "btng" is the name of the Search button # actual result: Check that the 'programming Ruby 'link appears on the results page if IE. contains_text ("programming ruby") puts "test passed. found the test string: 'Programming Ruby '. actual results match expected results. "else puts" test failed! Cocould not find: 'Programming Ruby '"end # end of test: Google search the script is to open Google's homepage, enter the "Pickaxe" string in the only Google text box, press the "Google Search" button, and then verify that the search result page contains the "programming ruby" string, use the puts function to print different information on the screen based on the results. The green part after "#" in the script is the content of the annotation. Simple? To be honest, it is simpler and simpler than the scripts recorded by commercial tools. 


2. Required Environment

RUBY: Because Ruby is used for implementation, the script is also a ruby script, so you need to install Ruby on the local machine. You can click here to download. According to the document, it is best to select Ruby 1.8.2-14 or later. I installed Ruby 1.8.2-15 stable release. Watir: you can click here to download. I downloaded watir 1.4, which is a. ZIP file. After decompression, run install. RB. For details about the installation and configuration, see the watir user manual. Don't be afraid. Although it is in English, it is very simple. Windows 2000 or XP + IE 5.5 or later: according to the description on the watir website, This is the environment they currently support. 


3. Background

After all, we need to write code. Therefore, development experience is essential and can be used in any language. Although Ruby is an object-oriented scripting language, however, you can ignore it for the time being (do not be intimidated by words such as object-oriented and scripting languages). If you have written VBSCRIPT or other code, watir is very simple. However, you need to understand web development, such as the basic syntax of HTML, because you need to identify web objects based on the source code of web pages when developing scripts-of course, you can also use other tools, such as the DOM viewer provided by Mozilla Firefox (you can find it under the Mozilla Firefox tool menu. For details about how to use it, see the Mozilla Firefox help ). In addition, basic knowledge about testing and automated testing is required.


  4. Script generation

Don't think about the recording function. watir does not provide this function. If you are not using recording, choose another one. However, in my own usage, watir scripts are easier and faster to write than recording with qtp or rational tools. 


5. Object identification, operations, and automatic verification

Watir supports the identification and operation of a variety of common web objects, for example, hyperlinks click, checkboxes select and clear, radio buttons select and clear, drop-down box and list box selection, text box input, button click, frame access, pop-up window control. Of course, since these objects can be identified and operated, they can also be accessed to automate the verification of test results. For more information, see watir user manual. 


6. Other features

If you are familiar with Ruby and other tools, you can expand many features based on the watir framework. For example, reading external files or databases, modular development, reusable function libraries, data drivers, keyword drivers, Version Control of scripts, and management of test results.

  7. Related Links

Watir homepage: As mentioned above, the watir user manual and FAQ are well maintained, after reading the sample test and user's guide on the watir homepage, you can use watir to test the web application. If you are interested in further research, you can refer to the Technical Doc or read several examples of watir. Of course, you can also leave a message or email here for discussion.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.