Windows environment Building Web Automation test framework Watir (based on Ruby) 1th Chapter

Source: Internet
Author: User
I. Introduction
Web automation testing has always been a more urgent issue. For the current agile development of web development, there is no corresponding agile test. Therefore, this topic is opened, while researching, web automation testing is applied to the work, and it can form an independent chapter Blog post, I hope to make a small contribution to the development of domestic web automation testing, laugh ~
Second, Watir construction process

Figure 1-1 Tools to be installed
Because installing Ruby also requires some other development toolsets, it is recommended to download it from the website, and if you use this installation package, it will help you set the environment variables. I use the version: railsinstaller-2.2.4. exe, it is recommended to download the latest version.

Figure 1-2 RailsInstaller toolkit installation interface
Start to install RailsInstaller toolkit, install it to the default location.

Figure 1-3 Installation interface
 This checkmark is suggested, it will help you configure git and ssh, and a series of environment variables such as ruby during the installation process are also configured OK, very good ~

Figure 1-4 Test Ruby installation
After installing railsinstaller-2.2.4.exe, open the cmd command line and enter the command: ruby -v. If the version of ruby shown in Figure 1-4 appears, then Ruby has been installed, we can also enter the command to test The gem version: gem -v, as shown in Figure 1-4, the gem is also successfully installed.

Figure 1-5 gem installation
Using the command: gem list, take a look, as shown in Figure 1-5, you will find that after the railsinstaller is installed, the default Watir automation test tool is not included, so we will now start installing watir.

Figure 1-6 gem command
First take a brief look at how gems are used, as shown in Figure 1-6 above.

Figure 1-7 Install watir command
Use the command: gem install watir to install watir. If successful, there will be a lot of texts such as successfully; however, in China, you generally cannot see texts such as successfully because https://rubygems.org/ has been Wall, now we need to modify the source of the gem to achieve the purpose of installing watir.

Figure 1-8 RubyGems mirror URL
First use the command: gem sources -l to see the current source of the gem, generally: https://rubygems.org/
Then we use the command: gem sources --remove https://rubygems.org/
Then enter the command: gem sources -a https://ruby.taobao.org/
Refer to the figure above.

Figure 1-9 View the source of the gem
Let's see if the source of the gem is correct: gem sources -l, if there is only one source: https://ruby.taobao.org/, one source, the configuration is correct. Then use the command to install Watir: gem install watir, this time you should be able to install successfully.

Figure 1-10 commonwatir and watir versions
We can use the command again: gem list, you can see that there are a lot of watir-related content in the list. Here we mainly focus on two tools, as shown in the figure above, commonwatir and watir. Here we need to downgrade commonwatir and watir to 3.0. 0, if not downgraded, a NameError will occur, the command is as follows:

Figure 1-11 Watir downgraded to 3.0.0
Enter the command: gem uninstall watir -v 5.0.0
Enter the command: gem install watir -v 3.0.0

Figure 1-12 Commonwatir downgraded to 3.0.0
Enter the command: gem uninstall commonwatir -v 4.0.0
Enter the command: gem install commonwatir -v 3.0.0

Figure 1-13 Ruby test code
Require "watir"
Puts "Open IE ..."
Ie = Watir :: IE.new
Ie.goto (http://www.baidu.com/)
Puts "IE is opened-enjoy it :)"
 Create a new test.rb file in a text editor and enter the above code. It is strongly recommended to enter it manually. Inadvertent spaces will also cause the operation to fail.

Figure 1-14 Ruby file encoding
Encoding should also pay attention to using UTF-8 encoding.

Figure 1-15 Test results
After saving test.rb, enter the command on the cmd command line: ruby test.rb If there is no error in the ruby code, the program will automatically open Internet Explorer, and automatically enter http://www.baidu.com/ to open the Baidu page . At this point, Chapter 1 of "Building a Web Automation Testing Framework for Windows Environment (Watir (based on Ruby)" has been completed.
Chapter III Summary
We deploy ruby and watir to the windows platform through a series of configurations. Next, we can write a variety of test scripts to perform different tests for different web applications.
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.