SlideShare a Scribd company logo
1 of 31
Test Automation using Ruby
By Sveatoslav Cîrcel | Testing Consultant
1
What will be covered:
2
THE RUBY LANGUAGE
WHAT IS WATIR & WHAT USERS SAY
HOW TO GET STARTED WITH RUBY AND WATIR
THE DOM LOCATORS TREE OF LIFE
CODE EXAMPLES
DEBUGGIN WITH IRB
ANY GUI AUTOMATION – AUTOIT AND SIKULI
BEHAVIOUR DRIVEN DEVELOPMENT: CUCUMBER & RSPEC
CONTINUOUS INTEGRATION WITH JENKINS
INTEGRATION WITH SAUCE LABS
RAKE & RSPEC
FEW WORDS ABOUT THE CODE & STRUCTURE (JAVA VS RUBY)
TOOLS FOR ACCESSING DOM ELEMENTS
3
• Dynamic
• Easy to understand syntax
• Easy to use interpreter
• Object oriented
• Cross-platform
• Powerful class libraries
• Massive online support communities base
THE RUBY LANGUAGE
4
WHAT IS WATIR
Web Applications Testing in Ruby
• Free open-source tool
• Ruby library which runs almost any browse
• Results oriented
• Unlimited possibilities
• Cross-platform
• Massive online support communities base
Why use Watir?
• Free
• Powerful
• Simple
• Excellent Support
• It uses Ruby
• Broad usage.
• Multiple browser windows/tabs.
• JavaScript events.
• Frames / iframes / modal dialogs.
• Supports visible and invisible runs
• Headless / PhantomJS.
• Capturing of the screens
5
 “…WATIR is by far the most complete web testing framework out
here--that doesn't cost an arm and a leg.
 “Ruby is an awesome language and Watir
is just too cool. It does things that other
companies (ie. QTP, IBM/Rational, Mercury, Segue,
etc) charge thousands and thousands of dollars a seat for.
WHAT USERS SAY
HOW TO GET STARTED WITH RUBY AND WATIR
1. Download and install Ruby.
2. Install rubygems: gem update --system
3. Install DevKit
4. Download and install ChromeDriver.
5. Install Watir-Webdriver: gem install watir-webdriver
6. Open CMD, type: irb
7. Type: require 'watir-webdriver'
8. Type: browser = Watir::Browser.start 'endava.com'
6
7
READY FOR SOME CODE?
8
OPEN A WEB PAGE AND SHOW TITLE AND TEXT
•require 'watir-webdriver'
•b = Watir::Browser.new :chrome
•b.goto 'endava.com'
Returns current title of the page
•b.title
Returns current text elements of the page
•b.text
9
10
THE DOM
11
THE DOM LOCATORS TREE OF LIFE
12
TextBox browser.text_field(:name,
“name”).set “Value”
Button browser.button(:text,
/text/).click
DropDownList browser.select_list(:id,
“id”).set “Value”
CheckBox browser.checkbox(:class,
“class_id”).click
RadioButton browser.radio(:class,
“class_id”).click
HyperLink browser.link(:href,
“URL”).click
Form browser.form(:name, “name”).set
“Value”
Frame browser.frame(:id,
“frame1”).use
And many, many more (div, label, image, etc…)…
INTERACTION WITH DOM
Interaction with DOM
•b.link(:text, 'Careers').hover
•b.link(:text, 'Working at Endava').click
Small conditional validation test
•if b.text.include? 'Smart, Open, Thoughtful, Trusted, Agile'
• puts 'Test passed.'
• else
• puts 'Test failed.'
•end
13
14
COLLECTIONS OF ELEMENTS
Returns all text links of the page
•b.links.each {|x| unless x.text.empty? or x.text.nil?; puts x.text; end }
Returns all text of the page which is enclosed in <span> tags.
•b.spans.each {|x| unless x.text.empty? or x.text.nil?; puts x.text; end }
Returns all images url’s of the page.
•b.imgs.each {|x| puts x.src }
Writes all images’ url’s to a new array
•a = Array.new
•b.imgs.each {|x| a.push(x.src) }
•puts a
15
16
DEBUGGIN WITH IRB
IRB = Interactive Ruby Shell; Command line-like interface that allows immediate running of Ruby script. Great for debugging one line at
a time, rather then having to run through an entire script. Great for testing single lines
17
18
ANY GUI AUTOMATION – AUTOIT AND SIKULI
19
Simple AutoIT Example Simple Sikuli Example (on jRuby)
BEHAVIOUR DRIVEN DEVELOPMENT (BDD): CUCUMBER & RSPEC
Install the necessary gems by running:
• gem install 'cucumber'
• gem install 'watir-webdriver'
• gem install 'rspec-expectations‘
Setup Env.rb (next slide)
Create GoogleSearch.feature:
Feature:
"When I go to the Google search page, and search for an item, I expect to see some reference to that item in the
result summary.“
Scenario: 1. Search BDD in Google (Positive)
Given that I have gone to the Google page
When I add "BDD" to the search box
And click the Search Button
Then " behavior-driven development" should be mentioned in the results
20
CREATE CODE FOR YOUR FEATURES
Given /^that I have gone to the Google page$/ do
@browser.goto('www.google.com')
end
When /^I add "(.*)" to the search box$/ do |item|
@browser.text_field(:name, 'q').set(item)
end
And /^click the Search Button$/ do
@browser.button(:name, 'btnG').click
end
Then /"(.*)" should be mentioned in the results/ do |text|
@browser.text.should =~ /#{text}/
End
• Run using the following command: cucumber GoogleSearch.feature
21
22
CONTINUOUS INTEGRATION WITH JENKINS
23
INTEGRATION WITH SAUCE LABS
24
RAKE – RUNNING SCRIPTS GROUPED IN TASKS.
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |t|
t.pattern = FileList['spec/*_spec.rb']
t.rspec_opts = '--format html > ./results.html'
end
task :default => :spec
25
RSPEC AND EXTENSIVE LOGGING
26
FEW WORDS ABOUT THE CODE & STRUCTURE (JAVA VS RUBY)
27
28
JAVA
Java code: p1 - http://d.pr/i/de3Q; http://d.pr/i/RSND
p2 - http://prntscr.com/yqfzc
p3 - http://prntscr.com/yqg4t
Java Structure: http://prntscr.com/yqgsl
RUBY
http://prntscr.com/yqh25 (detailed rb http://prntscr.com/yqgxu)
Sublime
Notepad++
29
TOOLS FOR ACCESSING DOM ELEMENTS
USEFUL TOOLS/IDEs
FireBug
Xpath Checker
WATIR::SupportsSubElements
IE Developer Tool bar
QUESTIONS ?…
30
31

More Related Content

What's hot

Content-centric architectures - case study : Apache Sling
Content-centric architectures - case study : Apache SlingContent-centric architectures - case study : Apache Sling
Content-centric architectures - case study : Apache Sling
Fabrice Hong
 

What's hot (20)

Getting Started with Angular - Stormpath Webinar, January 2017
Getting Started with Angular - Stormpath Webinar, January 2017Getting Started with Angular - Stormpath Webinar, January 2017
Getting Started with Angular - Stormpath Webinar, January 2017
 
Play Framework on Google App Engine - Productivity Stack
Play Framework on Google App Engine - Productivity StackPlay Framework on Google App Engine - Productivity Stack
Play Framework on Google App Engine - Productivity Stack
 
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx UK 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx UK 2016Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx UK 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx UK 2016
 
Avoiding Common Pitfalls in Ember.js
Avoiding Common Pitfalls in Ember.jsAvoiding Common Pitfalls in Ember.js
Avoiding Common Pitfalls in Ember.js
 
Automated ui-testing
Automated ui-testingAutomated ui-testing
Automated ui-testing
 
Web App Security for Java Developers - UberConf 2021
Web App Security for Java Developers - UberConf 2021Web App Security for Java Developers - UberConf 2021
Web App Security for Java Developers - UberConf 2021
 
Microservices for the Masses with Spring Boot, JHipster, and JWT - Rich Web 2016
Microservices for the Masses with Spring Boot, JHipster, and JWT - Rich Web 2016Microservices for the Masses with Spring Boot, JHipster, and JWT - Rich Web 2016
Microservices for the Masses with Spring Boot, JHipster, and JWT - Rich Web 2016
 
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx France 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx France 2016Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx France 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx France 2016
 
Dockerizing BDD : Ruby-Cucumber Example
Dockerizing BDD : Ruby-Cucumber ExampleDockerizing BDD : Ruby-Cucumber Example
Dockerizing BDD : Ruby-Cucumber Example
 
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015
 
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx 2015
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx 2015Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx 2015
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx 2015
 
Sails.js Intro
Sails.js IntroSails.js Intro
Sails.js Intro
 
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Rich Web Experie...
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Rich Web Experie...Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Rich Web Experie...
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Rich Web Experie...
 
Case study: JBoss Developer Studio, an IDE for Web, Mobile and Cloud applicat...
Case study: JBoss Developer Studio, an IDE for Web, Mobile and Cloud applicat...Case study: JBoss Developer Studio, an IDE for Web, Mobile and Cloud applicat...
Case study: JBoss Developer Studio, an IDE for Web, Mobile and Cloud applicat...
 
Deploy Node.js application in Heroku using Eclipse
Deploy Node.js application in Heroku using EclipseDeploy Node.js application in Heroku using Eclipse
Deploy Node.js application in Heroku using Eclipse
 
RESTful Web Applications with Apache Sling
RESTful Web Applications with Apache SlingRESTful Web Applications with Apache Sling
RESTful Web Applications with Apache Sling
 
Webdriver.io
Webdriver.io Webdriver.io
Webdriver.io
 
Choosing a Javascript Framework
Choosing a Javascript FrameworkChoosing a Javascript Framework
Choosing a Javascript Framework
 
Content-centric architectures - case study : Apache Sling
Content-centric architectures - case study : Apache SlingContent-centric architectures - case study : Apache Sling
Content-centric architectures - case study : Apache Sling
 
Node.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash CourseNode.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash Course
 

Similar to Test Automation using Ruby

Deview 2013 mobile browser internals and trends_20131022
Deview 2013 mobile browser internals and trends_20131022Deview 2013 mobile browser internals and trends_20131022
Deview 2013 mobile browser internals and trends_20131022
NAVER D2
 
Single Page Application Development with backbone.js and Simple.Web
Single Page Application Development with backbone.js and Simple.WebSingle Page Application Development with backbone.js and Simple.Web
Single Page Application Development with backbone.js and Simple.Web
Chris Canal
 
Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5
Ganesh Kondal
 

Similar to Test Automation using Ruby (20)

Page object from the ground up.ppt
Page object from the ground up.pptPage object from the ground up.ppt
Page object from the ground up.ppt
 
Page object from the ground up by Joe Beale
Page object from the ground up by Joe BealePage object from the ground up by Joe Beale
Page object from the ground up by Joe Beale
 
Node.js for .NET Developers
Node.js for .NET DevelopersNode.js for .NET Developers
Node.js for .NET Developers
 
Node.js Development with Apache NetBeans
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeans
 
Java script nirvana in netbeans [con5679]
Java script nirvana in netbeans [con5679]Java script nirvana in netbeans [con5679]
Java script nirvana in netbeans [con5679]
 
Deview 2013 mobile browser internals and trends_20131022
Deview 2013 mobile browser internals and trends_20131022Deview 2013 mobile browser internals and trends_20131022
Deview 2013 mobile browser internals and trends_20131022
 
Acceptance Test-driven Development with Cucumber-jvm
Acceptance Test-driven Development with Cucumber-jvmAcceptance Test-driven Development with Cucumber-jvm
Acceptance Test-driven Development with Cucumber-jvm
 
Mobile Vue.js – From PWA to Native
Mobile Vue.js – From PWA to NativeMobile Vue.js – From PWA to Native
Mobile Vue.js – From PWA to Native
 
How to Contribute to Apache Usergrid
How to Contribute to Apache UsergridHow to Contribute to Apache Usergrid
How to Contribute to Apache Usergrid
 
Web based automation testing on Node.js environment
Web based automation testing on Node.js environmentWeb based automation testing on Node.js environment
Web based automation testing on Node.js environment
 
Single Page Application Development with backbone.js and Simple.Web
Single Page Application Development with backbone.js and Simple.WebSingle Page Application Development with backbone.js and Simple.Web
Single Page Application Development with backbone.js and Simple.Web
 
Nightwatch JS for End to End Tests
Nightwatch JS for End to End TestsNightwatch JS for End to End Tests
Nightwatch JS for End to End Tests
 
Creating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJSCreating Modular Test-Driven SPAs with Spring and AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJS
 
JavaScript Modules Done Right
JavaScript Modules Done RightJavaScript Modules Done Right
JavaScript Modules Done Right
 
Introduction to node.js by jiban
Introduction to node.js by jibanIntroduction to node.js by jiban
Introduction to node.js by jiban
 
Google App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGoogle App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and Gaelyk
 
Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5
 
Stanislaw potoczny kra_qa_21.01.20
Stanislaw potoczny kra_qa_21.01.20Stanislaw potoczny kra_qa_21.01.20
Stanislaw potoczny kra_qa_21.01.20
 
Bootstrapping angular js with bower grunt yeoman
Bootstrapping angular js with bower grunt yeomanBootstrapping angular js with bower grunt yeoman
Bootstrapping angular js with bower grunt yeoman
 
Let's run JavaScript Everywhere
Let's run JavaScript EverywhereLet's run JavaScript Everywhere
Let's run JavaScript Everywhere
 

Recently uploaded

Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Christo Ananth
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Christo Ananth
 

Recently uploaded (20)

Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 

Test Automation using Ruby

  • 1. Test Automation using Ruby By Sveatoslav Cîrcel | Testing Consultant 1
  • 2. What will be covered: 2 THE RUBY LANGUAGE WHAT IS WATIR & WHAT USERS SAY HOW TO GET STARTED WITH RUBY AND WATIR THE DOM LOCATORS TREE OF LIFE CODE EXAMPLES DEBUGGIN WITH IRB ANY GUI AUTOMATION – AUTOIT AND SIKULI BEHAVIOUR DRIVEN DEVELOPMENT: CUCUMBER & RSPEC CONTINUOUS INTEGRATION WITH JENKINS INTEGRATION WITH SAUCE LABS RAKE & RSPEC FEW WORDS ABOUT THE CODE & STRUCTURE (JAVA VS RUBY) TOOLS FOR ACCESSING DOM ELEMENTS
  • 3. 3 • Dynamic • Easy to understand syntax • Easy to use interpreter • Object oriented • Cross-platform • Powerful class libraries • Massive online support communities base THE RUBY LANGUAGE
  • 4. 4 WHAT IS WATIR Web Applications Testing in Ruby • Free open-source tool • Ruby library which runs almost any browse • Results oriented • Unlimited possibilities • Cross-platform • Massive online support communities base Why use Watir? • Free • Powerful • Simple • Excellent Support • It uses Ruby • Broad usage. • Multiple browser windows/tabs. • JavaScript events. • Frames / iframes / modal dialogs. • Supports visible and invisible runs • Headless / PhantomJS. • Capturing of the screens
  • 5. 5  “…WATIR is by far the most complete web testing framework out here--that doesn't cost an arm and a leg.  “Ruby is an awesome language and Watir is just too cool. It does things that other companies (ie. QTP, IBM/Rational, Mercury, Segue, etc) charge thousands and thousands of dollars a seat for. WHAT USERS SAY
  • 6. HOW TO GET STARTED WITH RUBY AND WATIR 1. Download and install Ruby. 2. Install rubygems: gem update --system 3. Install DevKit 4. Download and install ChromeDriver. 5. Install Watir-Webdriver: gem install watir-webdriver 6. Open CMD, type: irb 7. Type: require 'watir-webdriver' 8. Type: browser = Watir::Browser.start 'endava.com' 6
  • 7. 7
  • 8. READY FOR SOME CODE? 8
  • 9. OPEN A WEB PAGE AND SHOW TITLE AND TEXT •require 'watir-webdriver' •b = Watir::Browser.new :chrome •b.goto 'endava.com' Returns current title of the page •b.title Returns current text elements of the page •b.text 9
  • 10. 10
  • 12. THE DOM LOCATORS TREE OF LIFE 12 TextBox browser.text_field(:name, “name”).set “Value” Button browser.button(:text, /text/).click DropDownList browser.select_list(:id, “id”).set “Value” CheckBox browser.checkbox(:class, “class_id”).click RadioButton browser.radio(:class, “class_id”).click HyperLink browser.link(:href, “URL”).click Form browser.form(:name, “name”).set “Value” Frame browser.frame(:id, “frame1”).use And many, many more (div, label, image, etc…)…
  • 13. INTERACTION WITH DOM Interaction with DOM •b.link(:text, 'Careers').hover •b.link(:text, 'Working at Endava').click Small conditional validation test •if b.text.include? 'Smart, Open, Thoughtful, Trusted, Agile' • puts 'Test passed.' • else • puts 'Test failed.' •end 13
  • 14. 14
  • 15. COLLECTIONS OF ELEMENTS Returns all text links of the page •b.links.each {|x| unless x.text.empty? or x.text.nil?; puts x.text; end } Returns all text of the page which is enclosed in <span> tags. •b.spans.each {|x| unless x.text.empty? or x.text.nil?; puts x.text; end } Returns all images url’s of the page. •b.imgs.each {|x| puts x.src } Writes all images’ url’s to a new array •a = Array.new •b.imgs.each {|x| a.push(x.src) } •puts a 15
  • 16. 16
  • 17. DEBUGGIN WITH IRB IRB = Interactive Ruby Shell; Command line-like interface that allows immediate running of Ruby script. Great for debugging one line at a time, rather then having to run through an entire script. Great for testing single lines 17
  • 18. 18
  • 19. ANY GUI AUTOMATION – AUTOIT AND SIKULI 19 Simple AutoIT Example Simple Sikuli Example (on jRuby)
  • 20. BEHAVIOUR DRIVEN DEVELOPMENT (BDD): CUCUMBER & RSPEC Install the necessary gems by running: • gem install 'cucumber' • gem install 'watir-webdriver' • gem install 'rspec-expectations‘ Setup Env.rb (next slide) Create GoogleSearch.feature: Feature: "When I go to the Google search page, and search for an item, I expect to see some reference to that item in the result summary.“ Scenario: 1. Search BDD in Google (Positive) Given that I have gone to the Google page When I add "BDD" to the search box And click the Search Button Then " behavior-driven development" should be mentioned in the results 20
  • 21. CREATE CODE FOR YOUR FEATURES Given /^that I have gone to the Google page$/ do @browser.goto('www.google.com') end When /^I add "(.*)" to the search box$/ do |item| @browser.text_field(:name, 'q').set(item) end And /^click the Search Button$/ do @browser.button(:name, 'btnG').click end Then /"(.*)" should be mentioned in the results/ do |text| @browser.text.should =~ /#{text}/ End • Run using the following command: cucumber GoogleSearch.feature 21
  • 22. 22
  • 25. RAKE – RUNNING SCRIPTS GROUPED IN TASKS. require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) do |t| t.pattern = FileList['spec/*_spec.rb'] t.rspec_opts = '--format html > ./results.html' end task :default => :spec 25
  • 26. RSPEC AND EXTENSIVE LOGGING 26
  • 27. FEW WORDS ABOUT THE CODE & STRUCTURE (JAVA VS RUBY) 27
  • 28. 28 JAVA Java code: p1 - http://d.pr/i/de3Q; http://d.pr/i/RSND p2 - http://prntscr.com/yqfzc p3 - http://prntscr.com/yqg4t Java Structure: http://prntscr.com/yqgsl RUBY http://prntscr.com/yqh25 (detailed rb http://prntscr.com/yqgxu)
  • 29. Sublime Notepad++ 29 TOOLS FOR ACCESSING DOM ELEMENTS USEFUL TOOLS/IDEs FireBug Xpath Checker WATIR::SupportsSubElements IE Developer Tool bar
  • 31. 31

Editor's Notes

  1. Scope of this presentation is to make everyone familiar with Ruby language and right after start writing his/her first automated scripts not only for testing needs but also for day to day tasks. THE RUBY LANGUAGE WHAT IS WATIR WATIR-WEBDRIVER FEATURES WHAT USERS SAY HOW TO GET STARTED WITH RUBY AND WATIR READY FOR SOME CODE? OPEN A WEB PAGE AND SHOW TITLE AND TEXT COLLECTIONS OF ELEMENTS THE DOM FINDING <HTML> ELEMENTS IN DOM THE DOM LOCATORS TREE OF LIFE INTERACTION WITH DOM ANY GUI AUTOMATION BDD: RUBY AND CUCUMBER CREATE CODE FOR YOUR FEATURES RUNNING THE SCRIPTS DEBUGGIN WITH IRB TOOLS FOR ACCESSING DOM ELEMENTS USEFUL TOOLS/IDEs FEW WORDS ABOUT THE CODE AND STRUCTURE
  2. Five Ways That Ruby Is Better Than Java: http://jroller.com/rolsen/date/20060118 More info on ruby: http://www.youtube.com/watch?v=fYIEV_6xhck
  3. A free, open-source functional testing tool for web applications. It is a Ruby library which drives almost any browser the same way people do, clicks links, fills in forms, and presses buttons. Watir also checks results, such as whether expected text appears on the page or not. Because it’s build on Ruby, you have the power to connect to databases, read data files, save screenshots, manipulate the file system, export to CSV and XML, structure your code into reusable libraries Free;Powerful;Simple ;Excellent Support;It uses Ruby, a full-featured object oriented scripting language Broad usage in high level client base.
  4. -Watir forum boards are the most active and well supported that I have seen. You can post a question and is just a short period of time get someone (most of the time the architects of the framework!) who will steer you in the right direct, give you a work around to get over any roadblocks, or add it to the framework if it doesn't currently exist. That is the reason I switched and tell everyone interested that Ruby is the way to go! -Now that I'm gettin' the hang of Ruby and Watir, I'm starting to automate everything I do on the web. Even the simple things like logging in to web sites, searches, you name it. (source: www.watir.com)
  5. 1. Install ruby - use the www.rubyinstaller.org/downloads/ link, download and install latest version. 2. Update gems (http://rubygems.org/) with the following ruby command prompt (Start -> Programs -> Ruby 1.9.3 -> Start Command Prompt with Ruby): gem update --system 3. Download DevKit, that makes it easy to build and use native C/C++ extensions. We'd need that for Opera and Chrome support. Follow the install instructions in: https://github.com/oneclick/rubyinstaller/wiki/Development-Kit 4. For Google Chrome, additionally, we'd need to install the library. Go to http://code.google.com/p/chromedriver/downloads/list and download latest version. Unzip the file and put it in any folder that is in your PATH. (For example C:\Ruby1.9.3\Bin) 5. Install Watir-Webdriver gem in ruby command prompt (Start -> Programs -> Ruby 1.9.3 -> Start Command Prompt with Ruby): “gem install watir-webdriver”. Read the User's Guide (http://wtr.rubyforge.org/watir_user_guide.html), documentation, examples and tests for reference. (http://wiki.openqa.org/display/WTR/FAQ) 6. Ruby command prompt: cmd -> C:\Windows\System32\cmd.exe /E:ON /K C:\Ruby193\bin\setrbvars.bat -> Enter -> irb -> Enter
  6. Source: http://nnedbedb.wordpress.com/2013/02/26/%D1%80%D0%BE%D0%B4%D0%B8%D0%BD%D0%B0-%D0%BC%D0%B0%D1%82%D1%8C-%D0%B7%D0%BE%D0%B2%D1%91%D1%82/
  7. Document Object Model The Document Object Model (DOM) is a cross-platform and language-independent convention for representing and interacting with objects in HTML, XHTML and XML documents. Objects in the DOM tree may be addressed and manipulated by using methods on the objects. The public interface of a DOM is specified in its API.
  8. Flash, Silveright and/or any GUI Automation with Ruby and AutoIT or jRuby with Sikuli More examples in our svn @http://mdsvn.endava.net/svn/qa/testautomation/ruby
  9. There tends to be a strong ongoing association between Agile and Open-Source automation tools today. Many make good inroads on the attempt to connect the elaboration of requirements with automated tests, step for step. This way, the test is performing as closely as possible, what the client actually asked for, or agreed in the elaboration process. One such tool is Cucumber. It is designed to allow you to execute feature documentation written in plain text. Prerequisites: It is assumed that before using this example you have the following Installed: • Ruby • Watir gem for Ruby • Cucumber gem for Ruby I will use a simple example that uses the Google search engine in this case: Let’s say the user story is something like: ‘When I go to the Google search page, and search for an item, I expect to see some reference to that item in the result summary.’ Cucumber uses the keywords “Given”, “When”, “And” “Then” to build this into useable syntax. So I create for example, a file, called GoogleSearch.feature containing: Feature: ‘When I go to the Google search page, and search for an item, I expect to see some reference to that item in the result summary.’
  10. This gives us executable code for every Given, When and Then statement we have used. To run it we issue the following command line cucumber GoogleSearch.feature In order to run all pre-set in batch run: C:\Users\scircel\Desktop\scripting\qa\testautomation\ruby\cucumber>cucumber features –s
  11. An example of Ruby and Cucumber BDD framework can be found here: http://mdsvn.endava.net/svn/qa/testautomation/ruby/cucumber
  12. ::::Comparison of Sauce automation framework implemenation using Webdriver on Java and Maven VS Webdriver on Ruby ::: The code: Java: p1 - http://d.pr/i/de3Q; http://d.pr/i/RSND p2 - http://prntscr.com/yqfzc; p3 - http://prntscr.com/yqg4t Ruby: (on Slide29) The Structure: Java: http://prntscr.com/yqgsl Ruby: http://prntscr.com/yqh25 (detailed rb http://prntscr.com/yqgxu) The Setup: Java: 1. Install JDK 2. Install Maven 3. Configure Maven 4. Configure JDK 5. mvn archetype:generate .. 6. mvn package 7. java -cp target/endava_sauce_test-1.1-SNAPSHOT.jar com.endava.sauce.selenium.App http://prntscr.com/yqcak %) %) %) Java & Selenium setup and details http://www.wunderkraut.com/blog/creating-and-running-a-simple-selenium-webdriver-test/2011-09-15 Ruby: 1. Install Ruby 2. gem update --system 3. gem install selenium-webdriver 4. ruby script.rb The results: on RUBY: http://www.webpagescreenshot.info/img/528532-41201361959PM on Java: http://www.webpagescreenshot.info/img/478714-41201360705PM Next steps: running cucumber on Ruby within Sauce: git clone http://github.com/sgrove/cucumber_sauce.git gem install cucumber selenium-client parallel Add your Sauce Labs username and api-key to ondemand.yml Optionally edit one of the browser*.yml files to specify which browsers you want to run (C:\Ruby193\bin\setrbvars.bat) Run: rake cucumber_sauce
  13. Screens removed due to large size of file.
  14. Notepad++ (A good light-weight editor supporting Ruby code orthography and stylistics) IE Developer Toolbar: (Lets you explore the HTML elements behind the visible elements on a web page by clicking on the elements Xpath Checker: An interactive editor for XPath expressions. Choose 'View XPath' in the context menu and it will show the editor. You can edit the XPath expression and it incrementally updates the results. FireBug (Excellent FireFox extension for identifying HTML elements while writing scripts.) WATIR::SupportsSubElements (Watir API for accessing html elements)