SlideShare a Scribd company logo
1 of 43
Test Automation
using
Sveatoslav Cîrcel (@sveat0slav)
Web: medbedb.github.io
23 April 2016, Iasi
@sveat0slav #AutomationRuby
Sponsors
@sveat0slav
@sveat0slav #AutomationRuby
What will be covered:
Introduction
How to get started in Automation?
Web and Watir-Webdriver
DOM elements and code examples
Automated testing for any GUI using Ruby
Automated testing for Web Services using Ruby
Querying Databases using Ruby
Few words about BDD
Few words about Rake and Rspec
Continuous Integration
Integration with Sauce Labs (Cloud)
@sveat0slav
@sveat0slav #AutomationRuby
Few words about me
Husband, father, lover of God
and science, IT consultant & Scrum Master.
Senior Developer at Endava. Few of my
interests are: #Agile #Coding
#Scripting #QA #Ruby #Java #Bible #Guitar
Feel free to follow me on Twitter:
twitter.com/sveat0slav
Or read my blog: nnedbedb.wordpress.com
@sveat0slav #AutomationRuby
#ByTheCommunityForTheCommunity
#AutomationRuby
@sveat0slav @tabaradetestare
@sveat0slav
@sveat0slav #AutomationRuby
“Good software testing is a
challenging intellectual
process.”
“Continuous
learning
required”
By Alexandru Rotaru
@altomalex, altom.ro
@sveat0slav #AutomationRuby
@sveat0slav
@sveat0slav #AutomationRuby
•Dynamic
•Simple syntax
•IRB
•Object oriented
•Cross-platform
•Powerful
•Massive support
THE RUBY LANGUAGE
@sveat0slav #AutomationRuby
1. WATIR – Web Application Testing in
Ruby
@sveat0slav #AutomationRuby
What is Watir and why should we use it?
•Free
•Powerful
•Simple
•Excellent Support
•It uses Ruby
•Broad usage
• Multiple browsers
• Windows/tabs.
• JavaScript
• Frames
• Modal dialogs.
• Invisible runs
• Screen Capture
• … anything you can think of 
@sveat0slav #AutomationRuby
HOW WATIR WORKS?
@sveat0slav #AutomationRuby
HOW TO GET STARTED WINDOWS
MAC
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
'iasi.codecamp.ro'
1. Download and install Ruby.
2. Install Watir-Webdriver: gem install
watir-webdriver
3. Open CMD, type: irb
4. Type: require 'watir-webdriver'
5. Type: browser = Watir::Browser
.start 'iasi.codecamp.ro'
@sveat0slav #AutomationRuby
@sveat0slav #AutomationRuby
READY FOR SOME CODE?
@sveat0slav #AutomationRuby
OPEN A WEB PAGE AND SHOW TITLE AND TEXT
• require 'watir-webdriver'
• b = Watir::Browser.new :chrome
• b.goto 'iasi.codecamp.ro'
Returns current title of the page
• b.title
Returns current text elements of the
page
• b.text
@sveat0slav #AutomationRuby
@sveat0slav #AutomationRuby
THE DOM LOCATORS TREE OF LIFE
@sveat0slav #AutomationRuby
TextBox b.text_field(:name,’n’).set ’a’
Button b.button(:text, /text/).click
DropDown b.select_list(:id, ’id’).set
CheckBox b.checkbox(:class, ’cl’).click
Radio b.radio(:class, ’cl’).click
Link b.link(:href, ’URL’).click
Form b.form(:name, ’n’).set ’Value’
Frame b.frame(:id, ’frame1’).use
And many more (div, label, image, etc)…
@sveat0slav #AutomationRuby
INTERACTION WITH DOM
Interaction with DOM
• b.link(:text, 'Sponsors').click
Small conditional validation test
if b.text.include? 'Probably the largest IT conference in
Romania!'
puts 'Test passed.'
else
puts 'Test failed.'
end
@sveat0slav #AutomationRuby
@sveat0slav #AutomationRuby
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.lis.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 }
@sveat0slav #AutomationRuby
Writes all images’ url’s to a new array
a = Array.new
b.imgs.each {|x| a.push(x.src) }
puts a
@sveat0slav #AutomationRuby
@sveat0slav
@sveat0slav #AutomationRuby
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
@sveat0slav
@sveat0slav #AutomationRuby
@sveat0slav #AutomationRuby
2. ANY GUI AUTOMATION –
AUTOIT AND SIKULI
Simple AutoIT Example Simple Sikuli Example (on jRuby)
@sveat0slav #AutomationRuby
3. WEB SERVICES AUTOMATION USING
RUBY
@sveat0slav #AutomationRuby
3.1 REST
• First you will have to install a REST client gem:
gem install rest-client
• Then use it like this:
require 'rest-client'
RestClient.get 'http://services.groupkt.com/country/get/all’
RestClient.post 'http://example.com/resource', :param1 =>
'one', :nested => { :param2 => 'two' }
RestClient.delete 'http://example.com/resource’
For more details: http://www.rubydoc.info/gems/rest-
client/1.8.0
@sveat0slav #AutomationRuby
3.2 SOAP
•First you will have to install a SOAP client
gem:
gem install savon
•Then use it like this:
require ’savon'
client =
Savon.client(wsdl:'http://service.example.com?wsdl')
@sveat0slav #AutomationRuby
client.operations # => [:find_user, :list_users]
# call the 'findUser' operation
response = client.call(:find_user, message: { id: 42 })
response.body
# => { find_user_response: { id: 42, name: 'Hoff' } }
For more details:
http://www.rubydoc.info/gems/savon/2.11.1
@sveat0slav
SOAP Operations
@sveat0slav #AutomationRuby
4. DATABASES
@sveat0slav #AutomationRuby
Connecting Ruby to Mysql db
•First you will have to install a db client (If
needed):
gem install mysql
•Then use it like this:
db_host = "localhost"
db_user = "root"
db_pass = "root"
db_name = "your_db_name"
• client = Mysql::Client.new(:host => db_host,
:username => db_user, :password => db_pass,
:database => db_name)
@sveat0slav #AutomationRuby
Executing the query
•client = Mysql::Client.new(:host =>
db_host, :username => db_user,
:password => db_pass, :database =>
db_name)
•cdr_result = client.query(
'SELECT * from your_db_table_name')
Other DB adapters for ruby: https://www.ruby-
toolbox.com/categories/SQL_Database_Adapters
@sveat0slav #AutomationRuby
5. 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
@sveat0slav #AutomationRuby
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
@sveat0slav #AutomationRuby
@sveat0slav #AutomationRuby
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
@sveat0slav #AutomationRuby
RSPEC AND EXTENSIVE LOGGING
@sveat0slav #AutomationRuby
6. CONTINUOUS INTEGRATION WITH JENKINS
@sveat0slav #AutomationRuby
7. INTEGRATION WITH SAUCE LABS
@sveat0slav #AutomationRuby
Sublime
Notepad++
TOOLS FOR ACCESSING DOM ELEMENTS USEFUL TOOLS/IDEs
FireBug
Xpath Checker
WATIR::SupportsSubElements
IE Developer Tool bar
Further Reading and Automation ideas
1 MAC OS X Automation
http://www.rubydoc.info/gems/AXElements
https://www.youtube.com/watch?v=G9O5wzb7oTY
2 Windows OS Automation
http://itreallymatters.net/post/2352350743/automating-windows-and-their-controls-with-ruby
http://www.gearheadforhire.com/articles/ruby/win32-autogui/using-ruby-to-drive-windows-applications
http://phrogz.net/programmingruby/win32.html
3 Home Automation using Ruby and Raspberry Pi
https://steve.dynedge.co.uk/2013/03/29/remote-controlled-home-automation-using-sinatra-ruby-and-the-
lightwaverf-wifi-box/
http://harmdelaat.com/home-automation-with-x10-raspberry-pi-linux-and-ruby-on-rails/
https://www.youtube.com/watch?v=u1guHGWD1TU&feature=em-uploademail
@sveat0slav #AutomationRuby
QUESTIONS ?…
Test Automation using Ruby
Twitter: sveat0slav (follow me on twitter will post the slides there) ;-)
Web: medbedb.github.io
23 April 2016, Iasi
Please fill the online evaluation form after event

More Related Content

Recently uploaded

Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfFIDO Alliance
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceSamy Fodil
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Julian Hyde
 
THE BEST IPTV in GERMANY for 2024: IPTVreel
THE BEST IPTV in  GERMANY for 2024: IPTVreelTHE BEST IPTV in  GERMANY for 2024: IPTVreel
THE BEST IPTV in GERMANY for 2024: IPTVreelreely ones
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераMark Opanasiuk
 
Connecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAKConnecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAKUXDXConf
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIES VE
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...CzechDreamin
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsStefano
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...marcuskenyatta275
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfFIDO Alliance
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...FIDO Alliance
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyUXDXConf
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?Mark Billinghurst
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101vincent683379
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfSrushith Repakula
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftshyamraj55
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfFIDO Alliance
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaCzechDreamin
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlPeter Udo Diehl
 

Recently uploaded (20)

Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
THE BEST IPTV in GERMANY for 2024: IPTVreel
THE BEST IPTV in  GERMANY for 2024: IPTVreelTHE BEST IPTV in  GERMANY for 2024: IPTVreel
THE BEST IPTV in GERMANY for 2024: IPTVreel
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
Connecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAKConnecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAK
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System Strategy
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 

Featured

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Featured (20)

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 

Test Automation In Ruby v2

  • 1. Test Automation using Sveatoslav Cîrcel (@sveat0slav) Web: medbedb.github.io 23 April 2016, Iasi
  • 3. @sveat0slav #AutomationRuby What will be covered: Introduction How to get started in Automation? Web and Watir-Webdriver DOM elements and code examples Automated testing for any GUI using Ruby Automated testing for Web Services using Ruby Querying Databases using Ruby Few words about BDD Few words about Rake and Rspec Continuous Integration Integration with Sauce Labs (Cloud) @sveat0slav
  • 4. @sveat0slav #AutomationRuby Few words about me Husband, father, lover of God and science, IT consultant & Scrum Master. Senior Developer at Endava. Few of my interests are: #Agile #Coding #Scripting #QA #Ruby #Java #Bible #Guitar Feel free to follow me on Twitter: twitter.com/sveat0slav Or read my blog: nnedbedb.wordpress.com
  • 6. @sveat0slav #AutomationRuby “Good software testing is a challenging intellectual process.” “Continuous learning required” By Alexandru Rotaru @altomalex, altom.ro
  • 8. @sveat0slav #AutomationRuby •Dynamic •Simple syntax •IRB •Object oriented •Cross-platform •Powerful •Massive support THE RUBY LANGUAGE
  • 9. @sveat0slav #AutomationRuby 1. WATIR – Web Application Testing in Ruby
  • 10. @sveat0slav #AutomationRuby What is Watir and why should we use it? •Free •Powerful •Simple •Excellent Support •It uses Ruby •Broad usage • Multiple browsers • Windows/tabs. • JavaScript • Frames • Modal dialogs. • Invisible runs • Screen Capture • … anything you can think of 
  • 12. @sveat0slav #AutomationRuby HOW TO GET STARTED WINDOWS MAC 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 'iasi.codecamp.ro' 1. Download and install Ruby. 2. Install Watir-Webdriver: gem install watir-webdriver 3. Open CMD, type: irb 4. Type: require 'watir-webdriver' 5. Type: browser = Watir::Browser .start 'iasi.codecamp.ro'
  • 15. @sveat0slav #AutomationRuby OPEN A WEB PAGE AND SHOW TITLE AND TEXT • require 'watir-webdriver' • b = Watir::Browser.new :chrome • b.goto 'iasi.codecamp.ro' Returns current title of the page • b.title Returns current text elements of the page • b.text
  • 17. @sveat0slav #AutomationRuby THE DOM LOCATORS TREE OF LIFE
  • 18. @sveat0slav #AutomationRuby TextBox b.text_field(:name,’n’).set ’a’ Button b.button(:text, /text/).click DropDown b.select_list(:id, ’id’).set CheckBox b.checkbox(:class, ’cl’).click Radio b.radio(:class, ’cl’).click Link b.link(:href, ’URL’).click Form b.form(:name, ’n’).set ’Value’ Frame b.frame(:id, ’frame1’).use And many more (div, label, image, etc)…
  • 19. @sveat0slav #AutomationRuby INTERACTION WITH DOM Interaction with DOM • b.link(:text, 'Sponsors').click Small conditional validation test if b.text.include? 'Probably the largest IT conference in Romania!' puts 'Test passed.' else puts 'Test failed.' end
  • 21. @sveat0slav #AutomationRuby 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.lis.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 }
  • 22. @sveat0slav #AutomationRuby Writes all images’ url’s to a new array a = Array.new b.imgs.each {|x| a.push(x.src) } puts a
  • 24. @sveat0slav #AutomationRuby 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 @sveat0slav
  • 26. @sveat0slav #AutomationRuby 2. ANY GUI AUTOMATION – AUTOIT AND SIKULI Simple AutoIT Example Simple Sikuli Example (on jRuby)
  • 27. @sveat0slav #AutomationRuby 3. WEB SERVICES AUTOMATION USING RUBY
  • 28. @sveat0slav #AutomationRuby 3.1 REST • First you will have to install a REST client gem: gem install rest-client • Then use it like this: require 'rest-client' RestClient.get 'http://services.groupkt.com/country/get/all’ RestClient.post 'http://example.com/resource', :param1 => 'one', :nested => { :param2 => 'two' } RestClient.delete 'http://example.com/resource’ For more details: http://www.rubydoc.info/gems/rest- client/1.8.0
  • 29. @sveat0slav #AutomationRuby 3.2 SOAP •First you will have to install a SOAP client gem: gem install savon •Then use it like this: require ’savon' client = Savon.client(wsdl:'http://service.example.com?wsdl')
  • 30. @sveat0slav #AutomationRuby client.operations # => [:find_user, :list_users] # call the 'findUser' operation response = client.call(:find_user, message: { id: 42 }) response.body # => { find_user_response: { id: 42, name: 'Hoff' } } For more details: http://www.rubydoc.info/gems/savon/2.11.1 @sveat0slav SOAP Operations
  • 32. @sveat0slav #AutomationRuby Connecting Ruby to Mysql db •First you will have to install a db client (If needed): gem install mysql •Then use it like this: db_host = "localhost" db_user = "root" db_pass = "root" db_name = "your_db_name" • client = Mysql::Client.new(:host => db_host, :username => db_user, :password => db_pass, :database => db_name)
  • 33. @sveat0slav #AutomationRuby Executing the query •client = Mysql::Client.new(:host => db_host, :username => db_user, :password => db_pass, :database => db_name) •cdr_result = client.query( 'SELECT * from your_db_table_name') Other DB adapters for ruby: https://www.ruby- toolbox.com/categories/SQL_Database_Adapters
  • 34. @sveat0slav #AutomationRuby 5. 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
  • 35. @sveat0slav #AutomationRuby 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
  • 37. @sveat0slav #AutomationRuby 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
  • 39. @sveat0slav #AutomationRuby 6. CONTINUOUS INTEGRATION WITH JENKINS
  • 41. @sveat0slav #AutomationRuby Sublime Notepad++ TOOLS FOR ACCESSING DOM ELEMENTS USEFUL TOOLS/IDEs FireBug Xpath Checker WATIR::SupportsSubElements IE Developer Tool bar Further Reading and Automation ideas 1 MAC OS X Automation http://www.rubydoc.info/gems/AXElements https://www.youtube.com/watch?v=G9O5wzb7oTY 2 Windows OS Automation http://itreallymatters.net/post/2352350743/automating-windows-and-their-controls-with-ruby http://www.gearheadforhire.com/articles/ruby/win32-autogui/using-ruby-to-drive-windows-applications http://phrogz.net/programmingruby/win32.html 3 Home Automation using Ruby and Raspberry Pi https://steve.dynedge.co.uk/2013/03/29/remote-controlled-home-automation-using-sinatra-ruby-and-the- lightwaverf-wifi-box/ http://harmdelaat.com/home-automation-with-x10-raspberry-pi-linux-and-ruby-on-rails/ https://www.youtube.com/watch?v=u1guHGWD1TU&feature=em-uploademail
  • 43. Test Automation using Ruby Twitter: sveat0slav (follow me on twitter will post the slides there) ;-) Web: medbedb.github.io 23 April 2016, Iasi Please fill the online evaluation form after event

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 & 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
  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 consists of three gems (or projects): Watir - This gem is just a loader. Based on the browser that you want to run and your operating system, the Watir gem will load either Watir-Classic or Watir-Webdriver. Watir-Classic - This is the original Watir gem that drives Internet Explorer. Watir-Webdriver - This gem allows the driving of additional browsers - eg Chrome and Firefox. It is an API wrapper around the Selenium-Webdriver gem (ie translates the Watir commands to Selenium-Webdriver commands).
  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. Other examples: RestClient.get 'http://example.com/resource', {:params => {:id => 50, 'foo' => 'bar'}} RestClient.get 'https://user:password@example.com/private/resource', {:accept => :json} RestClient.post 'http://example.com/resource', :param1 => 'one', :nested => { :param2 => 'two' } RestClient.post "http://example.com/resource", { 'x' => 1 }.to_json, :content_type => :json, :accept => :json RestClient.delete 'http://example.com/resource' More details: http://www.rubydoc.info/gems/rest-client/1.8.0
  10. Soap Client: https://rubygems.org/gems/savon More details: http://www.rubydoc.info/gems/savon/2.11.1 Other clients: https://www.ruby-toolbox.com/categories/soap
  11. Other DB adapters for ruby: https://www.ruby-toolbox.com/categories/SQL_Database_Adapters
  12. Other DB adapters for ruby: https://www.ruby-toolbox.com/categories/SQL_Database_Adapters
  13. 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.’
  14. 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
  15. An example of Ruby and Cucumber BDD framework can be found here: http://mdsvn.endava.net/svn/qa/testautomation/ruby/cucumber
  16. 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)