Test Automation using Ruby

Sla Va
Sla VaConsultant um Endava
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
1 von 31

Recomendados

Test Automation using Ruby, Watir, Rspec and AutoIT for GAMESCALE products te... von
Test Automation using Ruby, Watir, Rspec and AutoIT for GAMESCALE products te...Test Automation using Ruby, Watir, Rspec and AutoIT for GAMESCALE products te...
Test Automation using Ruby, Watir, Rspec and AutoIT for GAMESCALE products te...Sla Va
4.4K views24 Folien
Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin... von
Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...
Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...Matt Raible
68.4K views170 Folien
Making Watir and Cucumber an efficient tool for Web UI Automation von
Making Watir and Cucumber an efficient tool for Web UI AutomationMaking Watir and Cucumber an efficient tool for Web UI Automation
Making Watir and Cucumber an efficient tool for Web UI AutomationRuslan Strazhnyk
2.8K views38 Folien
Play! Framework for JavaEE Developers von
Play! Framework for JavaEE DevelopersPlay! Framework for JavaEE Developers
Play! Framework for JavaEE DevelopersTeng Shiu Huang
14.3K views61 Folien
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Angular Summit 2015 von
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Angular Summit 2015Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Angular Summit 2015
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Angular Summit 2015Matt Raible
38.7K views40 Folien
Serverless 프레임워크로 Nuxt 앱 배포하기 von
Serverless 프레임워크로 Nuxt 앱 배포하기Serverless 프레임워크로 Nuxt 앱 배포하기
Serverless 프레임워크로 Nuxt 앱 배포하기Changwan Jun
934 views99 Folien

Más contenido relacionado

Was ist angesagt?

Getting Started with Angular - Stormpath Webinar, January 2017 von
Getting Started with Angular - Stormpath Webinar, January 2017Getting Started with Angular - Stormpath Webinar, January 2017
Getting Started with Angular - Stormpath Webinar, January 2017Matt Raible
718 views42 Folien
Play Framework on Google App Engine - Productivity Stack von
Play Framework on Google App Engine - Productivity StackPlay Framework on Google App Engine - Productivity Stack
Play Framework on Google App Engine - Productivity StackMarcin Stepien
3.9K views35 Folien
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx UK 2016 von
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 2016Matt Raible
3.7K views38 Folien
Avoiding Common Pitfalls in Ember.js von
Avoiding Common Pitfalls in Ember.jsAvoiding Common Pitfalls in Ember.js
Avoiding Common Pitfalls in Ember.jsAlex Speller
22.9K views42 Folien
Automated ui-testing von
Automated ui-testingAutomated ui-testing
Automated ui-testingSlobodan Lohja
266 views25 Folien
Web App Security for Java Developers - UberConf 2021 von
Web App Security for Java Developers - UberConf 2021Web App Security for Java Developers - UberConf 2021
Web App Security for Java Developers - UberConf 2021Matt Raible
152 views48 Folien

Was ist angesagt?(20)

Getting Started with Angular - Stormpath Webinar, January 2017 von Matt Raible
Getting Started with Angular - Stormpath Webinar, January 2017Getting Started with Angular - Stormpath Webinar, January 2017
Getting Started with Angular - Stormpath Webinar, January 2017
Matt Raible718 views
Play Framework on Google App Engine - Productivity Stack von Marcin Stepien
Play Framework on Google App Engine - Productivity StackPlay Framework on Google App Engine - Productivity Stack
Play Framework on Google App Engine - Productivity Stack
Marcin Stepien3.9K views
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx UK 2016 von Matt Raible
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
Matt Raible3.7K views
Avoiding Common Pitfalls in Ember.js von Alex Speller
Avoiding Common Pitfalls in Ember.jsAvoiding Common Pitfalls in Ember.js
Avoiding Common Pitfalls in Ember.js
Alex Speller22.9K views
Web App Security for Java Developers - UberConf 2021 von Matt Raible
Web App Security for Java Developers - UberConf 2021Web App Security for Java Developers - UberConf 2021
Web App Security for Java Developers - UberConf 2021
Matt Raible152 views
Microservices for the Masses with Spring Boot, JHipster, and JWT - Rich Web 2016 von Matt Raible
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
Matt Raible4.2K views
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx France 2016 von Matt Raible
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
Matt Raible5.5K views
Dockerizing BDD : Ruby-Cucumber Example von Shashikant Jagtap
Dockerizing BDD : Ruby-Cucumber ExampleDockerizing BDD : Ruby-Cucumber Example
Dockerizing BDD : Ruby-Cucumber Example
Shashikant Jagtap2.8K views
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015 von Matt Raible
#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
Matt Raible37.4K views
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx 2015 von Matt Raible
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
Matt Raible6.7K views
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Rich Web Experie... von Matt Raible
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...
Matt Raible3.4K views
Case study: JBoss Developer Studio, an IDE for Web, Mobile and Cloud applicat... von Max Andersen
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...
Max Andersen926 views
Deploy Node.js application in Heroku using Eclipse von Jitendra Zaa
Deploy Node.js application in Heroku using EclipseDeploy Node.js application in Heroku using Eclipse
Deploy Node.js application in Heroku using Eclipse
Jitendra Zaa2.9K views
Content-centric architectures - case study : Apache Sling von Fabrice Hong
Content-centric architectures - case study : Apache SlingContent-centric architectures - case study : Apache Sling
Content-centric architectures - case study : Apache Sling
Fabrice Hong1.2K views
Node.js & Twitter Bootstrap Crash Course von Aaron Silverman
Node.js & Twitter Bootstrap Crash CourseNode.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash Course
Aaron Silverman28.7K views

Similar a Test Automation using Ruby

Page object from the ground up by Joe Beale von
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 BealeQA or the Highway
479 views55 Folien
Page object from the ground up.ppt von
Page object from the ground up.pptPage object from the ground up.ppt
Page object from the ground up.pptJoseph Beale
46 views55 Folien
Node.js for .NET Developers von
Node.js for .NET DevelopersNode.js for .NET Developers
Node.js for .NET DevelopersDavid Neal
2.3K views42 Folien
Node.js Development with Apache NetBeans von
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeansRyan Cuprak
5.5K views44 Folien
Java script nirvana in netbeans [con5679] von
Java script nirvana in netbeans [con5679]Java script nirvana in netbeans [con5679]
Java script nirvana in netbeans [con5679]Ryan Cuprak
1.1K views76 Folien
Deview 2013 mobile browser internals and trends_20131022 von
Deview 2013 mobile browser internals and trends_20131022Deview 2013 mobile browser internals and trends_20131022
Deview 2013 mobile browser internals and trends_20131022NAVER D2
7.7K views48 Folien

Similar a Test Automation using Ruby (20)

Page object from the ground up by Joe Beale von QA or the Highway
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
QA or the Highway479 views
Page object from the ground up.ppt von Joseph Beale
Page object from the ground up.pptPage object from the ground up.ppt
Page object from the ground up.ppt
Joseph Beale46 views
Node.js for .NET Developers von David Neal
Node.js for .NET DevelopersNode.js for .NET Developers
Node.js for .NET Developers
David Neal2.3K views
Node.js Development with Apache NetBeans von Ryan Cuprak
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeans
Ryan Cuprak5.5K views
Java script nirvana in netbeans [con5679] von Ryan Cuprak
Java script nirvana in netbeans [con5679]Java script nirvana in netbeans [con5679]
Java script nirvana in netbeans [con5679]
Ryan Cuprak1.1K views
Deview 2013 mobile browser internals and trends_20131022 von NAVER D2
Deview 2013 mobile browser internals and trends_20131022Deview 2013 mobile browser internals and trends_20131022
Deview 2013 mobile browser internals and trends_20131022
NAVER D27.7K views
Acceptance Test-driven Development with Cucumber-jvm von Christopher Bartling
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 von MartinSotirov
Mobile Vue.js – From PWA to NativeMobile Vue.js – From PWA to Native
Mobile Vue.js – From PWA to Native
MartinSotirov1.9K views
How to Contribute to Apache Usergrid von David M. Johnson
How to Contribute to Apache UsergridHow to Contribute to Apache Usergrid
How to Contribute to Apache Usergrid
David M. Johnson9.8K views
Web based automation testing on Node.js environment von Yu-Lin Huang
Web based automation testing on Node.js environmentWeb based automation testing on Node.js environment
Web based automation testing on Node.js environment
Yu-Lin Huang353 views
Single Page Application Development with backbone.js and Simple.Web von Chris Canal
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 Canal5.3K views
Nightwatch JS for End to End Tests von Sriram Angajala
Nightwatch JS for End to End TestsNightwatch JS for End to End Tests
Nightwatch JS for End to End Tests
Sriram Angajala691 views
Creating Modular Test-Driven SPAs with Spring and AngularJS von Gunnar Hillert
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
Gunnar Hillert10K views
JavaScript Modules Done Right von Mariusz Nowak
JavaScript Modules Done RightJavaScript Modules Done Right
JavaScript Modules Done Right
Mariusz Nowak5.4K views
Google App Engine Java, Groovy and Gaelyk von Guillaume Laforge
Google App Engine Java, Groovy and GaelykGoogle App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and Gaelyk
Guillaume Laforge45.8K views
Tech io spa_angularjs_20130814_v0.9.5 von Ganesh Kondal
Tech io spa_angularjs_20130814_v0.9.5Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5
Ganesh Kondal1.5K views
Stanislaw potoczny kra_qa_21.01.20 von kraqa
Stanislaw potoczny kra_qa_21.01.20Stanislaw potoczny kra_qa_21.01.20
Stanislaw potoczny kra_qa_21.01.20
kraqa174 views
Let's run JavaScript Everywhere von Tom Croucher
Let's run JavaScript EverywhereLet's run JavaScript Everywhere
Let's run JavaScript Everywhere
Tom Croucher3.5K views

Último

Effect of deep chemical mixing columns on properties of surrounding soft clay... von
Effect of deep chemical mixing columns on properties of surrounding soft clay...Effect of deep chemical mixing columns on properties of surrounding soft clay...
Effect of deep chemical mixing columns on properties of surrounding soft clay...AltinKaradagli
6 views10 Folien
Plumbing von
PlumbingPlumbing
PlumbingIwiss Tools Co.,Ltd
15 views14 Folien
Codes and Conventions.pptx von
Codes and Conventions.pptxCodes and Conventions.pptx
Codes and Conventions.pptxIsabellaGraceAnkers
7 views5 Folien
LFA-NPG-Paper.pdf von
LFA-NPG-Paper.pdfLFA-NPG-Paper.pdf
LFA-NPG-Paper.pdfharinsrikanth
40 views13 Folien
Design and analysis of a new undergraduate Computer Engineering degree – a me... von
Design and analysis of a new undergraduate Computer Engineering degree – a me...Design and analysis of a new undergraduate Computer Engineering degree – a me...
Design and analysis of a new undergraduate Computer Engineering degree – a me...WaelBadawy6
53 views4 Folien
Dynamics of Hard-Magnetic Soft Materials von
Dynamics of Hard-Magnetic Soft MaterialsDynamics of Hard-Magnetic Soft Materials
Dynamics of Hard-Magnetic Soft MaterialsShivendra Nandan
13 views32 Folien

Último(20)

Effect of deep chemical mixing columns on properties of surrounding soft clay... von AltinKaradagli
Effect of deep chemical mixing columns on properties of surrounding soft clay...Effect of deep chemical mixing columns on properties of surrounding soft clay...
Effect of deep chemical mixing columns on properties of surrounding soft clay...
AltinKaradagli6 views
Design and analysis of a new undergraduate Computer Engineering degree – a me... von WaelBadawy6
Design and analysis of a new undergraduate Computer Engineering degree – a me...Design and analysis of a new undergraduate Computer Engineering degree – a me...
Design and analysis of a new undergraduate Computer Engineering degree – a me...
WaelBadawy653 views
Machine Element II Course outline.pdf von odatadese1
Machine Element II Course outline.pdfMachine Element II Course outline.pdf
Machine Element II Course outline.pdf
odatadese17 views
Multi-objective distributed generation integration in radial distribution sy... von IJECEIAES
Multi-objective distributed generation integration in radial  distribution sy...Multi-objective distributed generation integration in radial  distribution sy...
Multi-objective distributed generation integration in radial distribution sy...
IJECEIAES15 views
NEW SUPPLIERS SUPPLIES (copie).pdf von georgesradjou
NEW SUPPLIERS SUPPLIES (copie).pdfNEW SUPPLIERS SUPPLIES (copie).pdf
NEW SUPPLIERS SUPPLIES (copie).pdf
georgesradjou14 views
DevOps to DevSecOps: Enhancing Software Security Throughout The Development L... von Anowar Hossain
DevOps to DevSecOps: Enhancing Software Security Throughout The Development L...DevOps to DevSecOps: Enhancing Software Security Throughout The Development L...
DevOps to DevSecOps: Enhancing Software Security Throughout The Development L...
Anowar Hossain12 views
A multi-microcontroller-based hardware for deploying Tiny machine learning mo... von IJECEIAES
A multi-microcontroller-based hardware for deploying Tiny machine learning mo...A multi-microcontroller-based hardware for deploying Tiny machine learning mo...
A multi-microcontroller-based hardware for deploying Tiny machine learning mo...
IJECEIAES12 views
Update 42 models(Diode/General ) in SPICE PARK(DEC2023) von Tsuyoshi Horigome
Update 42 models(Diode/General ) in SPICE PARK(DEC2023)Update 42 models(Diode/General ) in SPICE PARK(DEC2023)
Update 42 models(Diode/General ) in SPICE PARK(DEC2023)

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

Hinweis der Redaktion

  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)