Saturday, August 30, 2014

Selenium Ruby Installation

In this post, we'll guide you how to install Selenium Ruby work well on both platform Win7-32b and Win7-64b

1. Ruby installation

Download Ruby and Devkit from here: http://rubyinstaller.org/downloads/    
Install Ruby with RubyInstaller (user should select Ruby version 1.9.3, this version is stable and work well on both Win7-32b and Win7-64b)

2.Devkit installation

Step 1: Extract Files
Left double-click the self-extracting executable (SFX) downloaded and choose a directory (without spaces) to install the DevKit artefacts into. For example, C:\DevKit. NOTE: the SFX is really a 7-Zip archive with a bit of embedded magic. If you already have7-Zip installed, you can simply right-click it and extract its contents as you would a normal 7z archive. In the instructions that follow, the directory that you selected is identified as <DEVKIT_INSTALL_DIR>. NOTE: Do not rename this directory because once you install the path is hardcoded into the Ruby installation.
Step 2: Run Installation Scripts
Open cmd window
       cd <DEVKIT_INSTALL_DIR>
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).
edit the generated config.yml file to include installed Rubies not automatically 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<RUBY_INSTALL_DIR>\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.
Refer Devkit installation here: https://github.com/oneclick/rubyinstaller/wiki/Development-Kit 
1.3    GEM INSTALLATION
We will install gem from Command Line window. Below is necessary gem list:

gem install activesupport
gem install selenium-client
gem install selenium-webdriver
gem install rspec
gem install spreadsheet
gem install capybara
gem install ruby-debug-ide


Notes: View the list of installed gems: gem query --local
1.4    IE WEB-DRIVER INSTALLATION
-    Download IEDriverServer_Win32_2.35.3.zip (select the latest one) at here:
http://selenium-release.storage.googleapis.com/index.html
-    Extract file and drop it in C:\Windows\System32


Thursday, August 28, 2014

An example of Cucumber - Ruby - Capybara


In this post, we won't talk too much about theory: What is cucumber? since you can research this information from internet. With this post, we just want to give you an example of Cucumber test with Selenium Ruby using Capybara (a library written in Ruby which makes it easy to simulate how a user interacts with your application)


1. Install Ruby, ruby devkit and some rubygem for your test, such as: selenium-client, selenium-webdriver, rspec, capybara, cucumber.


2. Using JetBrain RubyMine editor to write test script. User can use evaluation version of RubyMine for 30 days.


3. Open RubyMine, go to menu File > Settings > Ruby SDK and Gems, click (+) button on the right hand side to browse to ruby.exe (the location you had installed Ruby), press OK to complete the setting.


Now, write the first project with Cucumber and Ruby - Capybara.

 A cucumber project have structure like this:



 Create a new project named "FirstProject" with structure as above.

1. Create env.rb in feature\support:


           
2.Create Common_Lib.rb in feature\support:

3. Create first.feature in feature with below scenario:

Right-click on this scenario and select "Run..."
Because this is the first run, so that editor will generate step definition inside for this scenario



4. Next, we create step definition first_steps.rb in \step_definitions\

Tester copy the generated steps from section 3 from above and correct them as below code:

5. Run the first.feature again, you will get the report like this:
 

Hope this help.