Ruby + watir build an automated testing framework

Source: Internet
Author: User

After some comparisons and selections, we finally decided to use the popular Ruby as the first test script for my automated testing framework design, in addition, its test tool watir almost perfectly replaces the so-called charging tool qtp, and has never been inferior.

Next we will officially start to talk about the establishment of the automated testing framework. There are not a few such materials on the Internet, but I still want to summarize it. After all, I have barely established the automated testing framework after reading so many materials, therefore, we will not study things that are not very complex, but we are most afraid that the so-called simple things are not easy to use, so it is difficult to mix technology!

 

First, download the ruby installation package. The installation package under Windows is downloaded on the official website in the EXE format. I will not talk about it here. The version is 1.8.6. It seems that it has been developed by version 1.9, the installation procedure is simple. Here is a little bit; next is to install watir,

Visit the watir Official Website:

Http://wtr.rubyforge.org/install.html

Perform the following operations according to the description on the website:

1. Ruby installation must be completed first;

2. Open "run" And Enter cmd to enter the console;

Enter the following code;

Gem update -- System

Gem install watir

Gem install firewatir

 

In the above process, watir is installed through the network. Why is it easy to install watir on the network? You can also download the watir installation package. therefore, the network must be smooth. If you choose to download and install the package, you only need to ensure that the ruby/rubygems and watir packages are up to date, in most cases, the installation is unsuccessful because of version inconsistency in windows. Therefore, after installation, you can test it, here I recommend a relatively simple tool scite, which you know is great when you use it. It is embedded in the compiling and Running Environments of N multiple languages and is relatively small, it is worth using.

 

After installation, you can create a new helloworld. RB file under the scite tool. Enter puts "Hello world! ", And then save it. A very simple script can be used to test whether Ruby is successfully installed. However, the main Ruby script suffix must be RB. Therefore, the file must be suffixed with Rb. at this time, we can directly press F5 on the disk to run the ruby script and find that Hello world is displayed in the output bar on the right! In this way, it indicates that Ruby is successfully installed, but it does not prove that watir is successfully built. Therefore, you also need to verify waitr. The specific functions of waitr will be described in detail in the next section.

Next, we create a script named A. RB:

Require 'rubygems'

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
Ie. 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 ("Ruby ")
Puts "test passed. Found the test string: 'Programming Ruby '. Actual results match expected results ."
Else
Puts "test failed! Cocould not find: 'Ruby '"
End
# End of test: Google Search

The above script mainly describes how to use Google to search for the "Ruby" character. If the program runs successfully and jumps out of the IE browser's operation process, it indicates that the ruby + watir environment is successfully set up.

Note: On the Internet, I find that in most cases, I do not quite understand the libraries introduced at the beginning of this script, because I have added libraries that introduce require 'rubygems 'one by one, if this parameter is not added, the system fails to run and will prompt that the watir loading is unsuccessful ......

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.