Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
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-Webdrive...
@sveat0slav #AutomationRuby
Few words about me
Husband, father, lover of God
and science, IT consultant & Scrum Master.
Se...
@sveat0slav #AutomationRuby
#ByTheCommunityForTheCommunity
#AutomationRuby
@sveat0slav @tabaradetestare
@sveat0slav
@sveat0slav #AutomationRuby
“Good software testing is a
challenging intellectual
process.”
“Continuous
learning
required”
...
@sveat0slav #AutomationRuby
@sveat0slav
@sveat0slav #AutomationRuby
•Dynamic
•Simple syntax
•IRB
•Object oriented
•Cross-platform
•Powerful
•Massive support
THE R...
@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 Ru...
@sveat0slav #AutomationRuby
HOW WATIR WORKS?
@sveat0slav #AutomationRuby
HOW TO GET STARTED WINDOWS
MAC
1. Download and install Ruby.
2. Install rubygems: gem update -...
@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 :...
@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...
@sveat0slav #AutomationRuby
INTERACTION WITH DOM
Interaction with DOM
• b.link(:text, 'Sponsors').click
Small conditional ...
@sveat0slav #AutomationRuby
@sveat0slav #AutomationRuby
COLLECTIONS OF ELEMENTS
Returns all text links of the page
•b.links.each {|x| unless x.text.em...
@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 immedi...
@sveat0slav #AutomationRuby
@sveat0slav #AutomationRuby
2. ANY GUI AUTOMATION –
AUTOIT AND SIKULI
Simple AutoIT Example Simple Sikuli Example (on jRub...
@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 us...
@sveat0slav #AutomationRuby
3.2 SOAP
•First you will have to install a SOAP client
gem:
gem install savon
•Then use it lik...
@sveat0slav #AutomationRuby
client.operations # => [:find_user, :list_users]
# call the 'findUser' operation
response = cl...
@sveat0slav #AutomationRuby
4. DATABASES
@sveat0slav #AutomationRuby
Connecting Ruby to Mysql db
•First you will have to install a db client (If
needed):
gem insta...
@sveat0slav #AutomationRuby
Executing the query
•client = Mysql::Client.new(:host =>
db_host, :username => db_user,
:passw...
@sveat0slav #AutomationRuby
5. BDD: CUCUMBER & RSPEC
Install the necessary gems by running:
• gem install 'cucumber'
• gem...
@sveat0slav #AutomationRuby
CREATE CODE FOR YOUR FEATURES
Given /^that I have gone to the
Google page$/ do
@browser.goto('...
@sveat0slav #AutomationRuby
@sveat0slav #AutomationRuby
RAKE – RUNNING SCRIPTS GROUPED IN TASKS.
require 'rspec/core/rake_task'
RSpec::Core::RakeTask....
@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...
@sveat0slav #AutomationRuby
QUESTIONS ?…
Test Automation using Ruby
Twitter: sveat0slav (follow me on twitter will post the slides there) ;-)
Web: medbedb.github.i...
Upcoming SlideShare
Loading in …5
×

Test Automation In Ruby v2

470 views

Published on

Code Camp Iasi, April 2016 - presentation by Sveatoslav Circel
medbedb.github.io
nnedbedb.wordpress.com
@sveat0slav

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Test Automation In Ruby v2

  1. 1. Test Automation using Sveatoslav Cîrcel (@sveat0slav) Web: medbedb.github.io 23 April 2016, Iasi
  2. 2. @sveat0slav #AutomationRuby Sponsors @sveat0slav
  3. 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. 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
  5. 5. @sveat0slav #AutomationRuby #ByTheCommunityForTheCommunity #AutomationRuby @sveat0slav @tabaradetestare @sveat0slav
  6. 6. @sveat0slav #AutomationRuby “Good software testing is a challenging intellectual process.” “Continuous learning required” By Alexandru Rotaru @altomalex, altom.ro
  7. 7. @sveat0slav #AutomationRuby @sveat0slav
  8. 8. @sveat0slav #AutomationRuby •Dynamic •Simple syntax •IRB •Object oriented •Cross-platform •Powerful •Massive support THE RUBY LANGUAGE
  9. 9. @sveat0slav #AutomationRuby 1. WATIR – Web Application Testing in Ruby
  10. 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 
  11. 11. @sveat0slav #AutomationRuby HOW WATIR WORKS?
  12. 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'
  13. 13. @sveat0slav #AutomationRuby
  14. 14. @sveat0slav #AutomationRuby READY FOR SOME CODE?
  15. 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
  16. 16. @sveat0slav #AutomationRuby
  17. 17. @sveat0slav #AutomationRuby THE DOM LOCATORS TREE OF LIFE
  18. 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. 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
  20. 20. @sveat0slav #AutomationRuby
  21. 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. 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
  23. 23. @sveat0slav #AutomationRuby @sveat0slav
  24. 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
  25. 25. @sveat0slav #AutomationRuby
  26. 26. @sveat0slav #AutomationRuby 2. ANY GUI AUTOMATION – AUTOIT AND SIKULI Simple AutoIT Example Simple Sikuli Example (on jRuby)
  27. 27. @sveat0slav #AutomationRuby 3. WEB SERVICES AUTOMATION USING RUBY
  28. 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. 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. 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
  31. 31. @sveat0slav #AutomationRuby 4. DATABASES
  32. 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. 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. 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. 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
  36. 36. @sveat0slav #AutomationRuby
  37. 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
  38. 38. @sveat0slav #AutomationRuby RSPEC AND EXTENSIVE LOGGING
  39. 39. @sveat0slav #AutomationRuby 6. CONTINUOUS INTEGRATION WITH JENKINS
  40. 40. @sveat0slav #AutomationRuby 7. INTEGRATION WITH SAUCE LABS
  41. 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
  42. 42. @sveat0slav #AutomationRuby QUESTIONS ?…
  43. 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

×