Watir (based on Ruby) and watirruby
Web automation testing has always been an urgent issue.
Figure 1-1 tools to be installed
Http://railsinstaller.org/
Because installing Ruby also requires some other development toolsets, it is recommended to http://railsinstaller.org from the website/Download, and use the installation package, it will help you set the environment variables, I use the version is: railsinstaller-2.2.4.exe, it is recommended to download the latest version.
Start installing the RailsInstaller toolkit and install it to the default location.
This check box is recommended. It will help you configure git and ssh. During the installation process, ruby and other environment variables are also configured as OK ~
Figure 1-2 test Ruby Installation
After railsinstaller-2.2.4.exe is installed, open the cmd command line and enter the command: ruby-v
If the ruby version shown in Figure 1-2 is displayed, it indicates that ruby has been installed. You can also run the following command to test the gem version: gem-v.
As shown in figure 1-2, gem is installed successfully.
Run the command: gem list. Check that after railsinstaller is installed, the Watir automated testing tool is not included by default. Therefore, we need to install watir now.
First, let's take a look at how to use gem, as shown in,
Run the gem install watir command to install watir. If the installation is successful, many successfully and other texts will appear below. However, in China, you generally cannot see successfully and other texts, becauseHttps://rubygems.org/already goes through the wall. Now we need to modify the source of gemto achieve the purpose of installing watir.
First use the command: gem sources-l, view 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/
For more information, see.
Check whether the source of the gem is correct: gem sources-l. if the source is only: https://ruby.taobao.org/, configure the sources.
Then run the command to install Watir: gem install watir. This installation will be successful.
We can use the command gem list again. We can see that the list contains many watir-related content. Here we mainly care about two tools, as shown in commonwatir and watir, here we need to downgrade commonwatir and watir to version 3.0.0. If you do not downgrade, The NameError will occur. The command is as follows:
> Gem uninstall watir-v 5.0.0> gem install watir-v 3.0.0
Next:> gem uninstall commonwatir-v 4.0.0> gem install commonwatir-v 3.0.0
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 the text editor and enter the above Code. It is strongly recommended that you manually enter the file. If you accidentally enter a space, the operation may fail.
Pay attention to encoding,
After saving test. rb, run the following command on the cmd command line: ruby test. rb. If the ruby Code does not report an error, the program will automatically open IE and enter
http://www.baidu.com/
To open the Baidu page.
So far, Watir (Ruby-based), a Web automation testing framework, has been set up in Windows.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.