Translate

miércoles, 17 de abril de 2013

Watir install on Windows



Hello guy, first of all, excuse me for my english which is not my mother language.


The first step we need to do when installing Watir is install Ruby. We need to do this because Watir uses Ruby to do his magic.

Installing Ruby


Download the ruby installer  from here. For this tutorial we will use Ruby 1.9.3-p392



Lets install ruby. 



Find the rubyinstaller-1.9.3-p392.exe we just downloaded and double click it.

Select your language and accept the conditions

Set your installation path, in my case, P:\Ruby\Ruby193 and check all the options.



Its useful to check at least the second and third options:

Add Ruby executables to your PATH: allow us to run ruby scripts at the command promp just typing something like this:
ruby hello.rb
Associate .rb and .rb with this Ruby installation: make the ruby files (.rb) look like this

 and not like this 

Click Install


Click Finish



Testing Ruby


If we want to check our ruby installation, we could open a console: Start > run > cmd and type 
ruby --version
You should see something like this



Installing the Developer Kit


Next thing we need to do is install the ruby developer kit. You can get it here. This toolkit makes easy to build and use native C/C++ extensions such as RDiscount and RedCloth for Ruby on Windows.

The question is...which Development Kit?


There are several and different versions of Development Kits (DevKit). Download the right one for your version of Ruby:
  • Ruby 1.8.6 to 1.9.3: tdm-32-4.5.2
  • Ruby 2.0.0: mingw64-32-4.7.2
  • Ruby 2.0.0 x64 (64bits): mingw64-64-4.7.2




To install the development kit follow this steps:

While installation is (in general) simple, please ensure you carefully follow each step below.

1. Preparation


  • If you previously installed the legacy DevKit devkit-3.4.5r3-20091110.7z, its artifacts were extracted into each Ruby installation and need to be manually removed. Remove the gcc.bat, make.bat, and sh.bat stub batch files in \bin and the\devkit subdirectory for each Ruby installation using the legacy DevKit.
  • If you previously installed one of the legacy self-extracting DevKit’s, follow the SFX DevKit upgrade instructions.


2. Download Files (If you haven't done this one )

3. Create a directory for the DevKit installation

  • The one i have choosen is P:\Ruby_Development_Kit

4. Extract Files

  • Left double-click the self-extracting executable (SFX) downloaded from Step 2 and choose a directory (without spaces) to install the DevKit artifacts into. For example,P:\Ruby_Development_KitNOTE: the SFX is really a 7-Zip archive with a bit of embedded magic. If you already have 7-Zip installed, you can simply right-click it and extract its contents as you would a normal 7z archive.

4. Run Installation Scripts

  • Open a console Start > run > cmd
  • cd P:\Ruby_Development_Kit from Step 3 above.
Note that because our DevKit installation was made in a different drive than C: which is the default drive went we start the command prompt, we need to change the drive we are working with. Just type P: and hit Enter


Now we can "move" to the DevKit installation directory. Type cd P:\Ruby_Development_Kit and Enter

  • Run the the command ruby dk.rb init to generate the config.yml file to be used later in this Step. Your installed Rubies will be listed there (only those installed by a RubyInstaller package are detected at present).

We should now have a config.yml file in P:\Ruby_Development_Kit



You could open it using Notepad or you favorite text editor


You should see something like this

# This configuration file contains the absolute path locations of all
# installed Rubies to be enhanced to work with the DevKit. This config
# file is generated by the 'ruby dk.rb init' step and may be modified
# before running the 'ruby dk.rb install' step. To include any installed
# Rubies that were not automagically discovered, simply add a line below
# the triple hyphens with the absolute path to the Ruby root directory.
#
# Example:
#
# ---
# - C:/ruby19trunk
# - C:/ruby192dev
#
---
- P:/Ruby/Ruby193 
  • Edit the generated config.yml file to include installed Rubies not automagically discovered or remove Rubies you do not want to use the DevKit with.
  • [optional] ruby dk.rb review to review the list of Rubies to be enhanced to use the DevKit and verify the changes you made to it are correct.
  • Finally, ruby dk.rb install to DevKit enhance your installed Rubies. This step installs (or updates) an operating_system.rb file into the relevant directory needed to implement a RubyGems pre_install hook and a devkit.rb helper library file into\lib\ruby\site_ruby.
NOTE: you may need to use the --force option to update (with backup of the originals) the above mentioned files as discussed at the SFX DevKit upgrade FAQ entry.

And we get this


Testing Developer Kit

  • Confirm your Ruby environment is correctly using the DevKit by running gem install json --platform=rubyJSON should install correctly and you should see with native extensions in the screen messages. 
  • Next run ruby -rubygems -e "require 'json'; puts JSON.load('[42]').inspect" to confirm that the json gem is working.


Installing Watir


The last thing to do installing Watir, is execute the following commands. Lest do it !!
gem update --system
gem install watir

To acelerate download, you could use the following command, but you will not install RDoc and ri.
gem install watir --no-rdoc --no-ri
gem update --system --no-rdoc --no-ri


Testing Watir


Open a the command prompt  (Start > run > cmd) and type irb, which stands for Interactive Ruby Shell

Next, say to ruby you want to use watir (supposedly pronounced "water"). Type require 'watir'



Now we can create an "instance" of our browser (IE by default). Watir::Browser.start("http://www.google.com")




An Internet Explorer window should appear white the google page.


Congratulation !!! you did it !!!


References:




Luxant

About Luxant

Author Description here.. Nulla sagittis convallis. Curabitur consequat. Quisque metus enim, venenatis fermentum, mollis in, porta et, nibh. Duis vulputate elit in elit. Mauris dictum libero id justo.

3 comentarios

Write comentarios
Unknown
AUTHOR
13 de abril de 2015, 11:57 a.m. delete

me sale este error en la parte final de la instalcion ya busque como arreglarlo pero no encuentro nada me puede ayudar?

irb(main):002:0> Watir::Browser.start("http://www.google.com")
LoadError: cannot load such file -- watir-classic
from C:/Ruby22-x64/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54
:in `require'
from C:/Ruby22-x64/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54
:in `require'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/watir-5.0.0/lib/watir/loader
.rb:41:in `load_driver'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/watir-5.0.0/lib/watir/loader
.rb:33:in `load_driver_for'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/watir-5.0.0/lib/watir/loader
.rb:14:in `start'
from (irb):2
from C:/Ruby22-x64/bin/irb:11:in `'
irb(main):003:0>

Reply
avatar
Luxant
AUTHOR
13 de abril de 2015, 9:36 p.m. delete

Hola Ivan, me puedes indicar en version de windows estas haciando la prueba y si es de 32 o 64 bits. Gracias

Reply
avatar
Tejuteju
AUTHOR
22 de junio de 2018, 2:11 a.m. delete


It is nice blog Thank you provide important information and i am searching for same information to save my time Ruby on Rails Online Training India

Reply
avatar