Auto Complete · Slider · Testing · watir · watir-webdriver

Automate JQuery Slider using Watir-WebDriver

Automate JQuery Slider using Watir-WebDriver:

Example Code:

require ‘rubygems’
require ‘watir-webdriver’

ie=Watir::Browser.new :ie
ie.goto(“http://jqueryui.com/demos/slider/”)
ie.link(:class,’ui-slider-handle ui-state-default ui-corner-all’).focus
ie.send_keys(:arrow_down)
ie.send_keys(:page_down)
ie.send_keys(:arrow_up)
ie.send_keys(:page_up)

 

Demo Output Video  —  http://bit.ly/j_slider

Advertisements
decryption · encryption · Ruby · Testing

Ruby — Encryption and Decryption using OpenSSL

Code:

require 'rubygems'
require 'openssl'

$key = "A75435F0B240012A9489000C2952E41F"

class String

def encrypt(key=$key)
e = OpenSSL::Cipher::Cipher.new 'DES-EDE3-CBC'
e.encrypt key
s = e.update self
s << e.final
s = s.unpack('H*')[0].upcase
s
end

def decrypt(key=$key)
e = OpenSSL::Cipher::Cipher.new 'DES-EDE3-CBC'
e.decrypt key
s = self.to_a.pack("H*").unpack("C*").pack("c*")
s = e.update s
s << e.final
end
end
puts "raveendran".encrypt("password")
puts "509067DC2076497134DBF9A7DE5992B2".decrypt("password")

Output

509067DC2076497134DBF9A7DE5992B2

raveendran

Note:

You can chnage the $key vlaue.

You can encrypt the string with password. The password should match when trying to decrypt the encrypted string.

cucumber · QA · rspec · Testing · watir

RSpec + Watir WebDriver

Installation:

1. Install Ruby

2. CMD>gem install watir-webdriver

3. CMD>gem install rspec

Code:

google_search.rb

require 'rubygems'
require 'watir-webdriver'

class Google
def search(browser,term,result)

if browser.downcase=="ie"
br= :ie
elsif browser.downcase=="ff"
br= :ff
elsif browser.downcase=="chrome"
br= :chrome
else
br= :ie
end

$ie=Watir::Browser.new br
$ie.goto("http://google.com")
$ie.text_field(:name,'q').set(term)
sleep 3
$ie.button(:name,'btnG').click
sleep 3
$result=$ie.text.downcase.include?(result)

$ie.close
end

end

googleSearch_spec.rb

require 'rubygems'
require 'rspec'
require 'google_search'

describe Google, "#Searchresult" do
it "returns the expected result in search result page" do
bowling = Google.new
bowling.search("chrome","Raveendran","ruby")
$result.should eq(true)
end
end

describe Google, "#Searchresult" do
it "returns the expected result in search result page" do
bowling = Google.new
bowling.search("chrome","Raveendran","wordpress")
$result.should eq(true)
end
end

describe Google, "#Searchresult" do
it "returns the expected result in search result page" do
bowling = Google.new
bowling.search("chrome","Watir, Selenium,Cucumber highline","raveendran")
$result.should eq(true)
end
end

describe Google, "#Searchresult" do
it "returns the expected result in search result page" do
bowling = Google.new
bowling.search("chrome","Ruby highline","raveendran")
$result.should eq(true)
end
end

RUN THE RSPEC code:

1. Navigate to the folder where files available

>rspec googleSearch_spec.rb

 

OUTPUT:

It will launch Chrome browser and will execute the test cases. Finally You will get the output like,

Started ChromeDriver
port=4113
version=14.0.836.0
.Started ChromeDriver
port=4164
version=14.0.836.0
.Started ChromeDriver
port=4218
version=14.0.836.0
.Started ChromeDriver
port=4260
version=14.0.836.0
.

Finished in 77.28 seconds
4 examples, 0 failures

 

fitnesse · QA · Ruby · Testing · watir

Watir — Integration with Fitnesse

Fitnesse –Open source Test managment and acceptance testing tool

Watir –Open source Functional testing tool

 

1. Download the JAR file from http://fitnesse.org/FrontPage.FitNesseDevelopment.DownLoad

2. Save it in d:\fitnesse\fitnesse.jar

3. Install Ruby

4. Install the gem fit with the help of command

>gem install fit

>gem install watir

5. Open Command Prompt and navigate to

D:\fitness>java -jar fitnesse.jar

FitNesse (v20100103) Started…
port:              80
root page:         fitnesse.wiki.FileSystemPage at ./FitNesseRoot
logger:            none
authenticator:     fitnesse.authentication.PromiscuousAuthenticator
html page factory: fitnesse.html.HtmlPageFactory
page version expiration set to 14 days.

6. Open Browser and Navigate to “http://localhost/&#8221;

7. Click Properties or Navigate to “http://localhost/FrontPage?properties&#8221;

Change as per the snapshot and click Save Properties


8. Click “Edit”

Paste this code

!define COMMAND_PATTERN {ruby -I %p C:/ruby/lib/ruby/gems/1.8/gems/fit-1.2/bin/FitServer.rb}
!path D:/fit
!|mytest.Division|
|term|result_term|search?|
|Raveendran |music |true|
|Ruby |program |true|

9. In D:\ create folder named as “fit”
“Fit” folder should contain another one forlder named as “mytest”
“mytest” folder should contain “division.rb”

10.

Open division.rb file

paste the code

require ‘fit/column_fixture’
require ‘rubygems’
require ‘watir’

module Mytest

class Division < Fit::ColumnFixture
attr_accessor :term, :result_term
def search
@ie=Watir::IE.new
@ie.goto(“google.com”)
puts “Entering Term”
@ie.text_field(:name,’q’).set(@term)
@ie.button(:name,’btnG’).click
@output = @ie.text.include?(@result_term)
@ie.close
return @output

end
end

end

11. Click “Test” in “http://localhost&#8221;

12. Fitnesse will provide the test result for your definitions. For ex, see the snapshot

priority · QA · Ruby · Testing · watir

Watir — Priority for using attributes

Source:

<input id=”query1″ type=”text” autocomplete=”off” value=”” name=”query”/>

Code:

require ‘rubygems’
require ‘watir’
$ie=Watir::IE.new
$ie.maximize
$ie.goto(“http://search.aol.in/aol/webhome&#8221;)
$ie.text_field(:id,’query1′).value=”Raveendran”

Issue:

Change the last line of the code like this

$ie.text_field(:name,’query’).value=”Raveendran”

It is not working :). Rit ?

Solution:

So the first priority goes to the “ID” attirbute  to access the input fields.