SlideShare a Scribd company logo
Meet Selenium
Automated application testing
Application Testing

Automated
Browser

Running
Website
Application Testing
Type text here
Application Testing
Click here
Application Testing
Check text is ...
Application Testing
• Don’t need to change source code	

• Can test (almost) anything	

• Less focused than unit testing
Testing Tools
• Selenium server	

• Web driver client	

• Browsers
Testing Tools
Selenium Driver

Selenium Server
Supported Languages
• Official:	

• Java, C#, Ruby, Python, JavaScript	

• Community:	

• perl, php, Haskell, Objective-C
Sample Driver Code
require 'selenium-webdriver'
!
driver = Selenium::WebDriver.for :firefox
driver.navigate.to "https://duckduckgo.com/"
!
!
driver.find_element(:id, 'search_form_input_homepage')
.send_keys("webdriver")
!
driver.find_element(:id, 'search_button_homepage')
.click
!
puts "Search page title = #{driver.title}"
!
driver.quit
Online Resources
• Ruby Selenium Wiki:


https://code.google.com/p/selenium/wiki/
RubyBindings	


• Selenium Ruby API:


http://selenium.googlecode.com/git/docs/
api/rb/index.html
Selenium API
Agenda

WebDriver

WebElement
Main Classes
# Create a driver for Firefox
driver = Selenium::WebDriver.for :firefox
!
# Create a driver for Safari
driver = Selenium::WebDriver.for :safari
!
# If your FF is installed in a non-default location
# Use this before creating the driver
Selenium::WebDriver::Firefox.path = "/path/to/firefox"
WebDriver Functions
# Load a web page
driver.navigate.to "http://www.google.com"
!
# Returns page title
driver.title
!
# Returns HTML page source
driver.page_source
!
# Call a JS function
driver.execute_script("alert('hello world');")
!
# Quit the browser
driver.quit
Web Element
• Query and interact with elements on the
page	


• Both visual and functional	

• Get using a locator
Locating Web Elements
# Get an element on the page
# By name
el = driver.find_element(:name, 'btnK')
!
# By css selector
el = driver.find_element(:css, '.menu-item')
!
# By id
el = driver.find_element(:id, 'login-form')
!
# By xpath
el = driver.find_element(:xpath, "//h2[@class='title']")
Web Element
• Visual Methods:
el = driver.find_element(:css, '.menu-item')
!
# Get the location of the element
# (top-left corner)
el.location
!
# Get size of an element
el.size
!
# Bool: is element visible
el.displayed?
Web Element
• Functional Methods
# Get attribute value
el.attribute('id')
!
# Get inner text value
el.text
!
# Mouse click on the element
el.click
!
# Focus and send keyboard presses
el.send_keys('hello')
Testing with Ruby,
RSpec and Selenium
RSpec
• Ruby’s testing framework	

• Looks like jasmine / mocha
RSpec
1
2
3
4
5
6
7
8
9
10
11
12

require 'person'!
!
describe 'Person' do!
describe '#grow_up' do!
it "should increase a persons's age" do!
p = Person.new(10)!
p.grow_up!
!
expect(p.age).to eq(11)!
end!
end!
end!
Running RSpec
• Save your code in lib/	

• Save your spec in spec/	

• Just type rspec

1
2
3
5
6
7
8

" Press ? for help!
!
.. (up a dir)!
▾ lib/!
Person.rb!
▾ spec/!
person_spec.rb!
Running Cloud RSpec
• Sign up and use a cloud based selenium
testing provider
Sauce Cloud Demo

•

Use ruby-sauce
gem	


•

Specify all
browsers in
Config

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

require 'sauce'!
!
Sauce.config do |c|!
c[:browsers] = [!
["Windows 7","Firefox","18"],!
]!
end!
!
# s / selenium are automatically available!
# inside the test!
describe 'Testing Google', :sauce => :true do!
it 'should be Google' do!
s.navigate.to('http://www.google.com')!
expect(s.title).to eq('Google')!
end!
end!
Demos
• Let’s test duckduckgo’s title for the input
search string (http://duckduckgo.com/)	


• Let’s test designmodo’s siedbar disappears
on small screen (http://designmodo.com/)
RSpec Hooks

•
•

Use hooks for
setup/teardown
code	

before(:each),
before(:all),
after(:each) and
after(:all)

describe Thing do!
before(:each) do!
@thing = Thing.new!
end!

!

!

!

describe "initialized in before(:each)" do!
it "has 0 widgets" do!
expect(@thing.widgets.count).to eq(0)!
end!
it "can get accept new widgets" do!
@thing.widgets << Object.new!
end!
it "does not share state across examples" do!
expect(@thing.widgets.count).to eq(0)!
end!
end
Advanced Selenium
APIs
Target Locator
• Selenium driver is “focused” on a single
frame or modal dialog	


• Change active frame using switch_to
Target Locator
1
2
3
4
5
6
7
8
9

frame = driver.find_elements(:css, 'iframe').first!
!
driver.switch_to.frame(frame['id'])!
element = driver.find_element(:css, 'button')!
element.click!
!
alert = driver.switch_to.alert!
puts alert.text!
alert.accept!

Demo URL: http://jsfiddle.net/Wchm5/embedded/result/
Explicit Waits
• When async JS is involved, you may need to
wait for state change	


• Selenium has a Wait object
Explicit Wait
# Create a wait object with 30 seconds timeout
wait = Selenium::WebDriver::Wait.new( :timeout => 30 )
!
driver.find_element(:name, 'q').send_keys('webdriver')
driver.find_element(:name, 'btnK').click
!
# Page title is not yet changed
# so this just prints google
puts driver.title
!
# So we wait...
wait.until { driver.title != 'Google' }
!
# And now get the right value
puts driver.title
Selenium
Actions
Simulating mouse interactions
and complex ui gestures
Selenium Actions
# Use method chaining to describe the sequence,
# and perform to execute
!
# Move mouse to el1 center and click
driver.action.move_to(el1).click.perform
!
# Press and hold shift, move mouse to el1 and click
# then move mouse to second_element and click again
# release shift key, and drag element to third_element
driver.action.key_down(:shift).
click(el1).
click(second_element).
key_up(:shift).
drag_and_drop(element, third_element).
perform
Live Demo #1
• Enter AccuWeather	

• Check weather for Tel Aviv	

• Make sure (F) and (C) match	

• Use SaucaLabs to run on multiple browsers
Takeaways
• Wrap website access in your own ruby
class (which uses Selenium)	


• Aim for short test specs
System Testing
• Be selective about what you test	

• Run tests nightly	

• Use a remote test server
Ad

More Related Content

What's hot (20)

Javascript Test Automation Workshop (21.08.2014)
Javascript Test Automation Workshop (21.08.2014)Javascript Test Automation Workshop (21.08.2014)
Javascript Test Automation Workshop (21.08.2014)
Deutsche Post
 
jQuery Proven Performance Tips & Tricks
jQuery Proven Performance Tips & TricksjQuery Proven Performance Tips & Tricks
jQuery Proven Performance Tips & Tricks
Addy Osmani
 
Write Selenide in Python 15 min
Write Selenide in Python 15 minWrite Selenide in Python 15 min
Write Selenide in Python 15 min
Iakiv Kramarenko
 
Test automation & Seleniun by oren rubin
Test automation & Seleniun by oren rubinTest automation & Seleniun by oren rubin
Test automation & Seleniun by oren rubin
Oren Rubin
 
Selenium
SeleniumSelenium
Selenium
husnara mohammad
 
Angular UI Testing with Protractor
Angular UI Testing with ProtractorAngular UI Testing with Protractor
Angular UI Testing with Protractor
Andrew Eisenberg
 
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...
Iakiv Kramarenko
 
Nightwatch at Tilt
Nightwatch at TiltNightwatch at Tilt
Nightwatch at Tilt
Dave King
 
Testing in AngularJS
Testing in AngularJSTesting in AngularJS
Testing in AngularJS
Peter Drinnan
 
Selenium Overview
Selenium OverviewSelenium Overview
Selenium Overview
Abhijeet Vaikar
 
Testing Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha Touch
Mats Bryntse
 
Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015
Andrew Eisenberg
 
APIs: A Better Alternative to Page Objects
APIs: A Better Alternative to Page ObjectsAPIs: A Better Alternative to Page Objects
APIs: A Better Alternative to Page Objects
Sauce Labs
 
An Introduction to AngularJS End to End Testing using Protractor
An Introduction to AngularJS End to End Testing using ProtractorAn Introduction to AngularJS End to End Testing using Protractor
An Introduction to AngularJS End to End Testing using Protractor
Cubet Techno Labs
 
UI Testing Best Practices - An Expected Journey
UI Testing Best Practices - An Expected JourneyUI Testing Best Practices - An Expected Journey
UI Testing Best Practices - An Expected Journey
Oren Farhi
 
Automation Testing using Selenium Webdriver
Automation Testing using Selenium WebdriverAutomation Testing using Selenium Webdriver
Automation Testing using Selenium Webdriver
Pankaj Biswas
 
Webdriver cheatsheets summary
Webdriver cheatsheets summaryWebdriver cheatsheets summary
Webdriver cheatsheets summary
Alan Richardson
 
Selenide
SelenideSelenide
Selenide
DataArt
 
Scraping recalcitrant web sites with Python & Selenium
Scraping recalcitrant web sites with Python & SeleniumScraping recalcitrant web sites with Python & Selenium
Scraping recalcitrant web sites with Python & Selenium
Roger Barnes
 
Selenide
SelenideSelenide
Selenide
GlobalLogic Ukraine
 
Javascript Test Automation Workshop (21.08.2014)
Javascript Test Automation Workshop (21.08.2014)Javascript Test Automation Workshop (21.08.2014)
Javascript Test Automation Workshop (21.08.2014)
Deutsche Post
 
jQuery Proven Performance Tips & Tricks
jQuery Proven Performance Tips & TricksjQuery Proven Performance Tips & Tricks
jQuery Proven Performance Tips & Tricks
Addy Osmani
 
Write Selenide in Python 15 min
Write Selenide in Python 15 minWrite Selenide in Python 15 min
Write Selenide in Python 15 min
Iakiv Kramarenko
 
Test automation & Seleniun by oren rubin
Test automation & Seleniun by oren rubinTest automation & Seleniun by oren rubin
Test automation & Seleniun by oren rubin
Oren Rubin
 
Angular UI Testing with Protractor
Angular UI Testing with ProtractorAngular UI Testing with Protractor
Angular UI Testing with Protractor
Andrew Eisenberg
 
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...
Iakiv Kramarenko
 
Nightwatch at Tilt
Nightwatch at TiltNightwatch at Tilt
Nightwatch at Tilt
Dave King
 
Testing in AngularJS
Testing in AngularJSTesting in AngularJS
Testing in AngularJS
Peter Drinnan
 
Testing Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha Touch
Mats Bryntse
 
Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015
Andrew Eisenberg
 
APIs: A Better Alternative to Page Objects
APIs: A Better Alternative to Page ObjectsAPIs: A Better Alternative to Page Objects
APIs: A Better Alternative to Page Objects
Sauce Labs
 
An Introduction to AngularJS End to End Testing using Protractor
An Introduction to AngularJS End to End Testing using ProtractorAn Introduction to AngularJS End to End Testing using Protractor
An Introduction to AngularJS End to End Testing using Protractor
Cubet Techno Labs
 
UI Testing Best Practices - An Expected Journey
UI Testing Best Practices - An Expected JourneyUI Testing Best Practices - An Expected Journey
UI Testing Best Practices - An Expected Journey
Oren Farhi
 
Automation Testing using Selenium Webdriver
Automation Testing using Selenium WebdriverAutomation Testing using Selenium Webdriver
Automation Testing using Selenium Webdriver
Pankaj Biswas
 
Webdriver cheatsheets summary
Webdriver cheatsheets summaryWebdriver cheatsheets summary
Webdriver cheatsheets summary
Alan Richardson
 
Selenide
SelenideSelenide
Selenide
DataArt
 
Scraping recalcitrant web sites with Python & Selenium
Scraping recalcitrant web sites with Python & SeleniumScraping recalcitrant web sites with Python & Selenium
Scraping recalcitrant web sites with Python & Selenium
Roger Barnes
 

Similar to Introduction to Selenium and Ruby (20)

Automating Django Functional Tests Using Selenium on Cloud
Automating Django Functional Tests Using Selenium on CloudAutomating Django Functional Tests Using Selenium on Cloud
Automating Django Functional Tests Using Selenium on Cloud
Jonghyun Park
 
Build a game with javascript (may 21 atlanta)
Build a game with javascript (may 21 atlanta)Build a game with javascript (may 21 atlanta)
Build a game with javascript (may 21 atlanta)
Thinkful
 
Selenium testing - Handle Elements in WebDriver
Selenium testing - Handle Elements in WebDriver Selenium testing - Handle Elements in WebDriver
Selenium testing - Handle Elements in WebDriver
Vibrant Technologies & Computers
 
Real World Selenium Testing
Real World Selenium TestingReal World Selenium Testing
Real World Selenium Testing
Mary Jo Sminkey
 
full-stack-webapp-testing-with-selenium-and-rails.pdf
full-stack-webapp-testing-with-selenium-and-rails.pdffull-stack-webapp-testing-with-selenium-and-rails.pdf
full-stack-webapp-testing-with-selenium-and-rails.pdf
Brian Takita
 
Testing mit Codeception: Full-stack testing PHP framework
Testing mit Codeception: Full-stack testing PHP frameworkTesting mit Codeception: Full-stack testing PHP framework
Testing mit Codeception: Full-stack testing PHP framework
SusannSgorzaly
 
Galenframework
GalenframeworkGalenframework
Galenframework
Deepshikha Singh
 
Galenframework
GalenframeworkGalenframework
Galenframework
Deepshikha Singh
 
Galen Framework - Responsive Design Automation
Galen Framework - Responsive Design AutomationGalen Framework - Responsive Design Automation
Galen Framework - Responsive Design Automation
Venkat Ramana Reddy Parine
 
Session on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh GundechaSession on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh Gundecha
Agile Testing Alliance
 
Automated ui-testing
Automated ui-testingAutomated ui-testing
Automated ui-testing
Slobodan Lohja
 
Selenium Introduction by Sandeep Sharda
Selenium Introduction by Sandeep ShardaSelenium Introduction by Sandeep Sharda
Selenium Introduction by Sandeep Sharda
Er. Sndp Srda
 
Selenium Tips & Tricks - StarWest 2015
Selenium Tips & Tricks - StarWest 2015Selenium Tips & Tricks - StarWest 2015
Selenium Tips & Tricks - StarWest 2015
Andrew Krug
 
Selenium testing
Selenium testingSelenium testing
Selenium testing
Jason Myers
 
Getting started with jQuery
Getting started with jQueryGetting started with jQuery
Getting started with jQuery
Gill Cleeren
 
The Peanut Butter Cup of Web-dev: Plack and single page web apps
The Peanut Butter Cup of Web-dev: Plack and single page web appsThe Peanut Butter Cup of Web-dev: Plack and single page web apps
The Peanut Butter Cup of Web-dev: Plack and single page web apps
John Anderson
 
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Roy de Kleijn
 
Selenium再入門
Selenium再入門Selenium再入門
Selenium再入門
Norio Suzuki
 
Titanium Alloy Tutorial
Titanium Alloy TutorialTitanium Alloy Tutorial
Titanium Alloy Tutorial
Fokke Zandbergen
 
Stackup New Languages Talk: Ember is for Everybody
Stackup New Languages Talk: Ember is for EverybodyStackup New Languages Talk: Ember is for Everybody
Stackup New Languages Talk: Ember is for Everybody
Cory Forsyth
 
Automating Django Functional Tests Using Selenium on Cloud
Automating Django Functional Tests Using Selenium on CloudAutomating Django Functional Tests Using Selenium on Cloud
Automating Django Functional Tests Using Selenium on Cloud
Jonghyun Park
 
Build a game with javascript (may 21 atlanta)
Build a game with javascript (may 21 atlanta)Build a game with javascript (may 21 atlanta)
Build a game with javascript (may 21 atlanta)
Thinkful
 
Real World Selenium Testing
Real World Selenium TestingReal World Selenium Testing
Real World Selenium Testing
Mary Jo Sminkey
 
full-stack-webapp-testing-with-selenium-and-rails.pdf
full-stack-webapp-testing-with-selenium-and-rails.pdffull-stack-webapp-testing-with-selenium-and-rails.pdf
full-stack-webapp-testing-with-selenium-and-rails.pdf
Brian Takita
 
Testing mit Codeception: Full-stack testing PHP framework
Testing mit Codeception: Full-stack testing PHP frameworkTesting mit Codeception: Full-stack testing PHP framework
Testing mit Codeception: Full-stack testing PHP framework
SusannSgorzaly
 
Galen Framework - Responsive Design Automation
Galen Framework - Responsive Design AutomationGalen Framework - Responsive Design Automation
Galen Framework - Responsive Design Automation
Venkat Ramana Reddy Parine
 
Session on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh GundechaSession on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh Gundecha
Agile Testing Alliance
 
Selenium Introduction by Sandeep Sharda
Selenium Introduction by Sandeep ShardaSelenium Introduction by Sandeep Sharda
Selenium Introduction by Sandeep Sharda
Er. Sndp Srda
 
Selenium Tips & Tricks - StarWest 2015
Selenium Tips & Tricks - StarWest 2015Selenium Tips & Tricks - StarWest 2015
Selenium Tips & Tricks - StarWest 2015
Andrew Krug
 
Selenium testing
Selenium testingSelenium testing
Selenium testing
Jason Myers
 
Getting started with jQuery
Getting started with jQueryGetting started with jQuery
Getting started with jQuery
Gill Cleeren
 
The Peanut Butter Cup of Web-dev: Plack and single page web apps
The Peanut Butter Cup of Web-dev: Plack and single page web appsThe Peanut Butter Cup of Web-dev: Plack and single page web apps
The Peanut Butter Cup of Web-dev: Plack and single page web apps
John Anderson
 
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Roy de Kleijn
 
Stackup New Languages Talk: Ember is for Everybody
Stackup New Languages Talk: Ember is for EverybodyStackup New Languages Talk: Ember is for Everybody
Stackup New Languages Talk: Ember is for Everybody
Cory Forsyth
 
Ad

More from Ynon Perek (20)

Regexp
RegexpRegexp
Regexp
Ynon Perek
 
Html5 intro
Html5 introHtml5 intro
Html5 intro
Ynon Perek
 
09 performance
09 performance09 performance
09 performance
Ynon Perek
 
Mobile Web Intro
Mobile Web IntroMobile Web Intro
Mobile Web Intro
Ynon Perek
 
Qt multi threads
Qt multi threadsQt multi threads
Qt multi threads
Ynon Perek
 
Vimperl
VimperlVimperl
Vimperl
Ynon Perek
 
Syllabus
SyllabusSyllabus
Syllabus
Ynon Perek
 
Mobile Devices
Mobile DevicesMobile Devices
Mobile Devices
Ynon Perek
 
Network
NetworkNetwork
Network
Ynon Perek
 
Architecture app
Architecture appArchitecture app
Architecture app
Ynon Perek
 
Cryptography
CryptographyCryptography
Cryptography
Ynon Perek
 
Unit Testing JavaScript Applications
Unit Testing JavaScript ApplicationsUnit Testing JavaScript Applications
Unit Testing JavaScript Applications
Ynon Perek
 
How to write easy-to-test JavaScript
How to write easy-to-test JavaScriptHow to write easy-to-test JavaScript
How to write easy-to-test JavaScript
Ynon Perek
 
Introduction To Web Application Testing
Introduction To Web Application TestingIntroduction To Web Application Testing
Introduction To Web Application Testing
Ynon Perek
 
Accessibility
AccessibilityAccessibility
Accessibility
Ynon Perek
 
Angularjs
AngularjsAngularjs
Angularjs
Ynon Perek
 
Js memory
Js memoryJs memory
Js memory
Ynon Perek
 
Qt Design Patterns
Qt Design PatternsQt Design Patterns
Qt Design Patterns
Ynon Perek
 
Web Application Security
Web Application SecurityWeb Application Security
Web Application Security
Ynon Perek
 
JavaScript DOM Manipulations
JavaScript DOM ManipulationsJavaScript DOM Manipulations
JavaScript DOM Manipulations
Ynon Perek
 
09 performance
09 performance09 performance
09 performance
Ynon Perek
 
Mobile Web Intro
Mobile Web IntroMobile Web Intro
Mobile Web Intro
Ynon Perek
 
Qt multi threads
Qt multi threadsQt multi threads
Qt multi threads
Ynon Perek
 
Mobile Devices
Mobile DevicesMobile Devices
Mobile Devices
Ynon Perek
 
Architecture app
Architecture appArchitecture app
Architecture app
Ynon Perek
 
Unit Testing JavaScript Applications
Unit Testing JavaScript ApplicationsUnit Testing JavaScript Applications
Unit Testing JavaScript Applications
Ynon Perek
 
How to write easy-to-test JavaScript
How to write easy-to-test JavaScriptHow to write easy-to-test JavaScript
How to write easy-to-test JavaScript
Ynon Perek
 
Introduction To Web Application Testing
Introduction To Web Application TestingIntroduction To Web Application Testing
Introduction To Web Application Testing
Ynon Perek
 
Qt Design Patterns
Qt Design PatternsQt Design Patterns
Qt Design Patterns
Ynon Perek
 
Web Application Security
Web Application SecurityWeb Application Security
Web Application Security
Ynon Perek
 
JavaScript DOM Manipulations
JavaScript DOM ManipulationsJavaScript DOM Manipulations
JavaScript DOM Manipulations
Ynon Perek
 
Ad

Recently uploaded (20)

Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Asthma presentación en inglés abril 2025 pdf
Asthma presentación en inglés abril 2025 pdfAsthma presentación en inglés abril 2025 pdf
Asthma presentación en inglés abril 2025 pdf
VanessaRaudez
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Hands On: Create a Lightning Aura Component with force:RecordData
Hands On: Create a Lightning Aura Component with force:RecordDataHands On: Create a Lightning Aura Component with force:RecordData
Hands On: Create a Lightning Aura Component with force:RecordData
Lynda Kane
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Automation Dreamin': Capture User Feedback From Anywhere
Automation Dreamin': Capture User Feedback From AnywhereAutomation Dreamin': Capture User Feedback From Anywhere
Automation Dreamin': Capture User Feedback From Anywhere
Lynda Kane
 
"Client Partnership — the Path to Exponential Growth for Companies Sized 50-5...
"Client Partnership — the Path to Exponential Growth for Companies Sized 50-5..."Client Partnership — the Path to Exponential Growth for Companies Sized 50-5...
"Client Partnership — the Path to Exponential Growth for Companies Sized 50-5...
Fwdays
 
Automation Dreamin' 2022: Sharing Some Gratitude with Your Users
Automation Dreamin' 2022: Sharing Some Gratitude with Your UsersAutomation Dreamin' 2022: Sharing Some Gratitude with Your Users
Automation Dreamin' 2022: Sharing Some Gratitude with Your Users
Lynda Kane
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
"PHP and MySQL CRUD Operations for Student Management System"
"PHP and MySQL CRUD Operations for Student Management System""PHP and MySQL CRUD Operations for Student Management System"
"PHP and MySQL CRUD Operations for Student Management System"
Jainul Musani
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Automation Hour 1/28/2022: Capture User Feedback from Anywhere
Automation Hour 1/28/2022: Capture User Feedback from AnywhereAutomation Hour 1/28/2022: Capture User Feedback from Anywhere
Automation Hour 1/28/2022: Capture User Feedback from Anywhere
Lynda Kane
 
Image processinglab image processing image processing
Image processinglab image processing  image processingImage processinglab image processing  image processing
Image processinglab image processing image processing
RaghadHany
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Asthma presentación en inglés abril 2025 pdf
Asthma presentación en inglés abril 2025 pdfAsthma presentación en inglés abril 2025 pdf
Asthma presentación en inglés abril 2025 pdf
VanessaRaudez
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Hands On: Create a Lightning Aura Component with force:RecordData
Hands On: Create a Lightning Aura Component with force:RecordDataHands On: Create a Lightning Aura Component with force:RecordData
Hands On: Create a Lightning Aura Component with force:RecordData
Lynda Kane
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Automation Dreamin': Capture User Feedback From Anywhere
Automation Dreamin': Capture User Feedback From AnywhereAutomation Dreamin': Capture User Feedback From Anywhere
Automation Dreamin': Capture User Feedback From Anywhere
Lynda Kane
 
"Client Partnership — the Path to Exponential Growth for Companies Sized 50-5...
"Client Partnership — the Path to Exponential Growth for Companies Sized 50-5..."Client Partnership — the Path to Exponential Growth for Companies Sized 50-5...
"Client Partnership — the Path to Exponential Growth for Companies Sized 50-5...
Fwdays
 
Automation Dreamin' 2022: Sharing Some Gratitude with Your Users
Automation Dreamin' 2022: Sharing Some Gratitude with Your UsersAutomation Dreamin' 2022: Sharing Some Gratitude with Your Users
Automation Dreamin' 2022: Sharing Some Gratitude with Your Users
Lynda Kane
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
"PHP and MySQL CRUD Operations for Student Management System"
"PHP and MySQL CRUD Operations for Student Management System""PHP and MySQL CRUD Operations for Student Management System"
"PHP and MySQL CRUD Operations for Student Management System"
Jainul Musani
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Automation Hour 1/28/2022: Capture User Feedback from Anywhere
Automation Hour 1/28/2022: Capture User Feedback from AnywhereAutomation Hour 1/28/2022: Capture User Feedback from Anywhere
Automation Hour 1/28/2022: Capture User Feedback from Anywhere
Lynda Kane
 
Image processinglab image processing image processing
Image processinglab image processing  image processingImage processinglab image processing  image processing
Image processinglab image processing image processing
RaghadHany
 

Introduction to Selenium and Ruby

  • 6. Application Testing • Don’t need to change source code • Can test (almost) anything • Less focused than unit testing
  • 7. Testing Tools • Selenium server • Web driver client • Browsers
  • 9. Supported Languages • Official: • Java, C#, Ruby, Python, JavaScript • Community: • perl, php, Haskell, Objective-C
  • 10. Sample Driver Code require 'selenium-webdriver' ! driver = Selenium::WebDriver.for :firefox driver.navigate.to "https://duckduckgo.com/" ! ! driver.find_element(:id, 'search_form_input_homepage') .send_keys("webdriver") ! driver.find_element(:id, 'search_button_homepage') .click ! puts "Search page title = #{driver.title}" ! driver.quit
  • 11. Online Resources • Ruby Selenium Wiki:
 https://code.google.com/p/selenium/wiki/ RubyBindings • Selenium Ruby API:
 http://selenium.googlecode.com/git/docs/ api/rb/index.html
  • 14. Main Classes # Create a driver for Firefox driver = Selenium::WebDriver.for :firefox ! # Create a driver for Safari driver = Selenium::WebDriver.for :safari ! # If your FF is installed in a non-default location # Use this before creating the driver Selenium::WebDriver::Firefox.path = "/path/to/firefox"
  • 15. WebDriver Functions # Load a web page driver.navigate.to "http://www.google.com" ! # Returns page title driver.title ! # Returns HTML page source driver.page_source ! # Call a JS function driver.execute_script("alert('hello world');") ! # Quit the browser driver.quit
  • 16. Web Element • Query and interact with elements on the page • Both visual and functional • Get using a locator
  • 17. Locating Web Elements # Get an element on the page # By name el = driver.find_element(:name, 'btnK') ! # By css selector el = driver.find_element(:css, '.menu-item') ! # By id el = driver.find_element(:id, 'login-form') ! # By xpath el = driver.find_element(:xpath, "//h2[@class='title']")
  • 18. Web Element • Visual Methods: el = driver.find_element(:css, '.menu-item') ! # Get the location of the element # (top-left corner) el.location ! # Get size of an element el.size ! # Bool: is element visible el.displayed?
  • 19. Web Element • Functional Methods # Get attribute value el.attribute('id') ! # Get inner text value el.text ! # Mouse click on the element el.click ! # Focus and send keyboard presses el.send_keys('hello')
  • 20. Testing with Ruby, RSpec and Selenium
  • 21. RSpec • Ruby’s testing framework • Looks like jasmine / mocha
  • 22. RSpec 1 2 3 4 5 6 7 8 9 10 11 12 require 'person'! ! describe 'Person' do! describe '#grow_up' do! it "should increase a persons's age" do! p = Person.new(10)! p.grow_up! ! expect(p.age).to eq(11)! end! end! end!
  • 23. Running RSpec • Save your code in lib/ • Save your spec in spec/ • Just type rspec 1 2 3 5 6 7 8 " Press ? for help! ! .. (up a dir)! ▾ lib/! Person.rb! ▾ spec/! person_spec.rb!
  • 24. Running Cloud RSpec • Sign up and use a cloud based selenium testing provider
  • 25. Sauce Cloud Demo • Use ruby-sauce gem • Specify all browsers in Config 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 require 'sauce'! ! Sauce.config do |c|! c[:browsers] = [! ["Windows 7","Firefox","18"],! ]! end! ! # s / selenium are automatically available! # inside the test! describe 'Testing Google', :sauce => :true do! it 'should be Google' do! s.navigate.to('http://www.google.com')! expect(s.title).to eq('Google')! end! end!
  • 26. Demos • Let’s test duckduckgo’s title for the input search string (http://duckduckgo.com/) • Let’s test designmodo’s siedbar disappears on small screen (http://designmodo.com/)
  • 27. RSpec Hooks • • Use hooks for setup/teardown code before(:each), before(:all), after(:each) and after(:all) describe Thing do! before(:each) do! @thing = Thing.new! end! ! ! ! describe "initialized in before(:each)" do! it "has 0 widgets" do! expect(@thing.widgets.count).to eq(0)! end! it "can get accept new widgets" do! @thing.widgets << Object.new! end! it "does not share state across examples" do! expect(@thing.widgets.count).to eq(0)! end! end
  • 29. Target Locator • Selenium driver is “focused” on a single frame or modal dialog • Change active frame using switch_to
  • 30. Target Locator 1 2 3 4 5 6 7 8 9 frame = driver.find_elements(:css, 'iframe').first! ! driver.switch_to.frame(frame['id'])! element = driver.find_element(:css, 'button')! element.click! ! alert = driver.switch_to.alert! puts alert.text! alert.accept! Demo URL: http://jsfiddle.net/Wchm5/embedded/result/
  • 31. Explicit Waits • When async JS is involved, you may need to wait for state change • Selenium has a Wait object
  • 32. Explicit Wait # Create a wait object with 30 seconds timeout wait = Selenium::WebDriver::Wait.new( :timeout => 30 ) ! driver.find_element(:name, 'q').send_keys('webdriver') driver.find_element(:name, 'btnK').click ! # Page title is not yet changed # so this just prints google puts driver.title ! # So we wait... wait.until { driver.title != 'Google' } ! # And now get the right value puts driver.title
  • 34. Selenium Actions # Use method chaining to describe the sequence, # and perform to execute ! # Move mouse to el1 center and click driver.action.move_to(el1).click.perform ! # Press and hold shift, move mouse to el1 and click # then move mouse to second_element and click again # release shift key, and drag element to third_element driver.action.key_down(:shift). click(el1). click(second_element). key_up(:shift). drag_and_drop(element, third_element). perform
  • 35. Live Demo #1 • Enter AccuWeather • Check weather for Tel Aviv • Make sure (F) and (C) match • Use SaucaLabs to run on multiple browsers
  • 36. Takeaways • Wrap website access in your own ruby class (which uses Selenium) • Aim for short test specs
  • 37. System Testing • Be selective about what you test • Run tests nightly • Use a remote test server