SlideShare ist ein Scribd-Unternehmen logo
1 von 17
Lessons Learned: Migrating Tests To Selenium v2 September 20, 2011 Roger Hu (rhu@hearsaycorp.com)
Hearsay Social “If 2011 is the year of social media for business, Hearsay [Social] may have some say about it.” ,[object Object]
Enables reps to compliantly capitalize on LinkedIn, Twitter, and Facebook
Backed by Sequoia, NEA, Steve Chen, FB execs
Visionary founders and management team from GOOG, SFDC, MSFT, AMZN,[object Object]
Reasons to Switch Selenium v2 more closely approximates the user experience. Internet Explorer (IE7/IE8) especially runs faster with Selenium v2 (> 20%?) Easier to write tests. WebDriver reflects how other JavaScript frameworks work.
Selenium v2 Approach Example: driver = webdriver.Firefox() driver.find_element_by_xpath(“//a[text()=‘Create New Ad’”).click() driver.find_element_by_id(“ads_headline”).send_keys(“Selenium Testers Wanted”) Selenium server launches without needing proxy-based approach.  Browser driver generates native keyboard/mouse clicks to more closely simulate user behavior. WebDriver API (REST-based) simpler.    Browser-specific driver i.e.: IEDriver.dll (IE), webdriver.xpi (Firefox) + WebDriver API
Complexities of Moving to Selenium v2 Your tests have to be rewritten to leverage the WebDriver API.  Record/playback less useful option? (Selenium IDE plug-in for Firefox) Synchronization issues: implement more implicit/explicit wait conditions (Selenium v2 sometimes acts like an impatient user)  Hidden/non-visible elements can no longer be clicked. Specific WebDriverextension for each browser. Cross-browser issues with mouse click/keyboard events. CSS3 selectors now more dependent on the browser (unlike Selenium v1). Not all WebDriver extensions are fully baked (i.e. Chrome, Android, iPhone) Keeping up with the release cycles. Release Candidates: toggle()/select() removed from API. We do a lot of pip –U selenium.  Make sure you’re using the latest version of your preferred language binding! Documentation is sparse, and hard to debug without digging through Selenium source code (Java, C++, and JavaScript).
Visibility Matters i.e. driver.find_element_by_id(“cms_toolbar_icon”).click() The X/Y coordinates of the element location are used to determine where to click. Hidden elements can no longer be acted upon until they are visible. The element gets focused and clicked.  Some quirky issues with elements at top or bottom of the screen exist. CSS z-index takes precedence now; the top-most element will be the one that receives the mouse event.    If you use any type of debug overlay tool (i.eDjango Debug Toolbar, Rails Footnotes, etc.) disable them before running your Selenium tests!
Using Cookies In the Django Debug Toolbar case, we can set a cookie called ‘djdt’ to disable the overlay. ,[object Object]
Contrary to the documentation, setting cookies actually requires passing in a dictionary of name, value, and secure parameters.driver.add_cookie({"name" : "djdt",                           "value" : "true",                           "path" : "/",                           "secure" : False}) (name, value, secure parameters required) ,[object Object],[object Object]
Demo So how does this implicit/explicit wait stuff work? Let’s play Hearsay Social Says...http://hearsaysocialsays.appspot.com (Selenium v2 source code posted on the site) def play_level(): driver.find_element_by_name("b").click() WebDriverWait(driver, timeout=10).until(lambda driver: driver.find_element_by_name("s").get_attribute("value") == "Player's  Turn") pcclicks = driver.execute_script("return pcclicks;")     for pcclick in pcclicks[1:]: ele = "pl%s" % pcclick driver.find_element_by_name(ele).click() driver.find_element_by_name("b").click()     # Alert box shows up.  Let's dismiss it. driver.switch_to_alert()     Alert(driver).accept() for i in xrange(20): play_level()
Native vs. Synthetic Events Selenium v1 relied entirely on generating events through JavaScript, while Selenium v2 tries to do it through the operating system. Selecting a dropdown: driver.find_element_by_xpath("//select[@id=‘myselect']/option[text()=‘Seattle']").select()  (deprecated) driver.find_elements_by_css_selector("#myselect option")[2].click()  # IE7/IE8 won’t click (JS issue) from selenium.webdriver.common.keys import Keys driver.find_element_by_css_selector("#myselect").send_keys(Keys.DOWN) (IE7/IE8 have different behavior for disabled elements) One workaround: driver.execute_script(“$(‘#myselect option’][2].change()’);”)  (use jQuery to trigger select-box changes) You can always bypass some cross-browser issues related to native events by reverting to JavaScript-based events, though it’s not ideal. <select id=“myselect”>   <option value="1">Seattle</option>                                                                                                                                                                                       <option value="2“ disabled=disabled>Boston</option>                                                                                                                                                                                              <option value=”3”>San Francisco</option>   <option value=“4">Washington D.C.</option>                                                                                                                                                                                   </select>
Hover states, drag-and-drop, motion-based gestures, HTML5…. Want more complex sequences of keyboard/mouse actions (i.e. right clicks, double clicks, drag/drop)?   Use the ActionChains class. Creating hover states: also done through ActionChains class.  Remember, the elements still have to be visible for them to be chained! Many advanced user interactions still somewhat experimental, so expect issues. from selenium.webdriver import ActionChains driver.get(‘http://www.espn.com’) menu_mlb= driver.find_element_by_id("menu-mlb") chain = ActionChains(driver) chain.move_to_element(menu_mlb).perform() chain.move_to_element(menu_mlb).click(scores).perform() (scores is not visible until MLB is selected) scores = driver.find_elements_by_css_selector("#menu-mlb div.mod-content ul li")[1]  scores.click()
[object Object],div:contains(“Click here”)vs. //div[text()=“Click here”) Matching by inner text?  You still may need to use XPath. CSS selectors supported in Selenium v1 are not standard (i.e. contains()) Selenium v2 relies on document.querySelector() for modern browsers (IE8+, Firefox 3.5+).   If document.querySelector() isn’t supported, the Sizzle CSS engine is used. Even if you’re using a CSS3 selector, check whether it’s supported in IE. driver.find_element_by_css_selector(“#ad-summary:last-child") (breaks in IE7) driver.find_element_by_css_selector(“#ad-summary.last") (workaround: explicitly define the  last element when  rendering the HTML) CSS Selectors in Selenium v2
Other Tips & Tricks… Use Firebug with Selenium v2. Create a profile and installing the extension: firefox -ProfileManager --no-remote  (launch profile manager and install Firebug extension) Specify profile directory: 	profile = FirefoxProfile(profile_directory=“/home/user/.mozilla/firefox/60f7of9x.selenium”) driver = webdriver.Firefox(firefox_profile=profile) Test on local browsers first, use SSH reverse tunneling when testing on remote devservers: Install Selenium server on host machine: java –jar selenium-server.jar (default port 4444) Create a SSH tunnel into remote machine:  ssh-nNT -R 9999:<IP address of server>:4444 username@myhost.com(clients connect to port 9999) Login to remote machine and connect via webdriver.Remote() driver = webdriver.Remote(command_executor=http://localhost:9999/wd/hub) Using SauceLabs?   Make sure your max-duration: option is set if your test runs exceed 30 mins.    Can’t keep up with the Selenium v2 release cycles?  Fix your version with selenium-version: option. Use exit signals handlers to issue driver.quit() commands to see your test results sooner.
Summary Selenium v2 gets closer to simulating the user experience with an entirely new architecture (WebDriver API + browser plug-in/extension). Your tests may start failing on clicking on hidden/non-visible elements, so disable your debug overlays and be aware of CSS z-index issues. Bugs/issues with generating events still persist, and you may encounter many browser quirks (i.e. dropdown boxes). WebDriver may run faster, though you may need to add more synchronization checkpoints with implicit/explicit waits. When using CSS selectors, use the ones supported across all browsers (especially IE).

Weitere ähnliche Inhalte

Was ist angesagt?

A comprehensive guide on developing responsive and common react filter component
A comprehensive guide on developing responsive and common react filter componentA comprehensive guide on developing responsive and common react filter component
A comprehensive guide on developing responsive and common react filter componentKaty Slemon
 
Migration to jQuery 3.5.x
Migration to jQuery 3.5.xMigration to jQuery 3.5.x
Migration to jQuery 3.5.xStanislavIdolov
 
Android the Agile way
Android the Agile wayAndroid the Agile way
Android the Agile wayAshwin Raghav
 
Dominando o Data Binding no Android
Dominando o Data Binding no AndroidDominando o Data Binding no Android
Dominando o Data Binding no AndroidNelson Glauber Leal
 
Business News, Personal Finance and Money News
Business News, Personal Finance and Money NewsBusiness News, Personal Finance and Money News
Business News, Personal Finance and Money Newseminentoomph4388
 
What I’ve learned when developing BlockAlertViews
What I’ve learned when developing BlockAlertViewsWhat I’ve learned when developing BlockAlertViews
What I’ve learned when developing BlockAlertViewsGustavo Ambrozio
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQueryZeeshan Khan
 
Html events with javascript
Html events with javascriptHtml events with javascript
Html events with javascriptYounusS2
 
Javascript dom event
Javascript dom eventJavascript dom event
Javascript dom eventBunlong Van
 
Web Development Introduction to jQuery
Web Development Introduction to jQueryWeb Development Introduction to jQuery
Web Development Introduction to jQueryLaurence Svekis ✔
 
Intro to jQuery
Intro to jQueryIntro to jQuery
Intro to jQueryAlan Hecht
 
SharePoint Cincy 2012 - jQuery essentials
SharePoint Cincy 2012 - jQuery essentialsSharePoint Cincy 2012 - jQuery essentials
SharePoint Cincy 2012 - jQuery essentialsMark Rackley
 

Was ist angesagt? (20)

jQuery Presentasion
jQuery PresentasionjQuery Presentasion
jQuery Presentasion
 
Javascript event handler
Javascript event handlerJavascript event handler
Javascript event handler
 
Intro to jQuery
Intro to jQueryIntro to jQuery
Intro to jQuery
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
A comprehensive guide on developing responsive and common react filter component
A comprehensive guide on developing responsive and common react filter componentA comprehensive guide on developing responsive and common react filter component
A comprehensive guide on developing responsive and common react filter component
 
Error found
Error foundError found
Error found
 
Migration to jQuery 3.5.x
Migration to jQuery 3.5.xMigration to jQuery 3.5.x
Migration to jQuery 3.5.x
 
Android the Agile way
Android the Agile wayAndroid the Agile way
Android the Agile way
 
Dominando o Data Binding no Android
Dominando o Data Binding no AndroidDominando o Data Binding no Android
Dominando o Data Binding no Android
 
Business News, Personal Finance and Money News
Business News, Personal Finance and Money NewsBusiness News, Personal Finance and Money News
Business News, Personal Finance and Money News
 
Muster in Webcontrollern
Muster in WebcontrollernMuster in Webcontrollern
Muster in Webcontrollern
 
What I’ve learned when developing BlockAlertViews
What I’ve learned when developing BlockAlertViewsWhat I’ve learned when developing BlockAlertViews
What I’ve learned when developing BlockAlertViews
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Html events with javascript
Html events with javascriptHtml events with javascript
Html events with javascript
 
Javascript dom event
Javascript dom eventJavascript dom event
Javascript dom event
 
Web Development Introduction to jQuery
Web Development Introduction to jQueryWeb Development Introduction to jQuery
Web Development Introduction to jQuery
 
Jquery ui
Jquery uiJquery ui
Jquery ui
 
Intro to jQuery
Intro to jQueryIntro to jQuery
Intro to jQuery
 
French kit2019
French kit2019French kit2019
French kit2019
 
SharePoint Cincy 2012 - jQuery essentials
SharePoint Cincy 2012 - jQuery essentialsSharePoint Cincy 2012 - jQuery essentials
SharePoint Cincy 2012 - jQuery essentials
 

Andere mochten auch

Bristol Cycle Festival
Bristol Cycle FestivalBristol Cycle Festival
Bristol Cycle FestivalMelanie Peck
 
Gay archipelago-bahasa-indonesia
Gay archipelago-bahasa-indonesiaGay archipelago-bahasa-indonesia
Gay archipelago-bahasa-indonesiaUmi Zainab
 
North American BioFortean Review - Yuri Kuchinsky
North American BioFortean Review - Yuri KuchinskyNorth American BioFortean Review - Yuri Kuchinsky
North American BioFortean Review - Yuri KuchinskyRuben LLumihucci
 
Indian Horses Before Columbus Evidences in America
Indian Horses Before Columbus Evidences in AmericaIndian Horses Before Columbus Evidences in America
Indian Horses Before Columbus Evidences in AmericaRuben LLumihucci
 
Personalized Learning at Your Fingertips: Building a PLN
Personalized Learning at Your Fingertips: Building a PLNPersonalized Learning at Your Fingertips: Building a PLN
Personalized Learning at Your Fingertips: Building a PLNTorrey Trust
 
Lorenc gordani winter outlook report 201415 and summer review 2014
Lorenc gordani   winter outlook report 201415 and summer review 2014Lorenc gordani   winter outlook report 201415 and summer review 2014
Lorenc gordani winter outlook report 201415 and summer review 2014Lorenc Gordani
 
Thoughts On Patent Damages Landscape Post-Halo - Law360
Thoughts On Patent Damages Landscape Post-Halo - Law360Thoughts On Patent Damages Landscape Post-Halo - Law360
Thoughts On Patent Damages Landscape Post-Halo - Law360Matthew Harrison
 
Albanian Res by Dr Lorenc Gordani - Slides
Albanian Res by Dr Lorenc Gordani - SlidesAlbanian Res by Dr Lorenc Gordani - Slides
Albanian Res by Dr Lorenc Gordani - SlidesLorenc Gordani
 
Tablet School ImparaDigitale
Tablet School ImparaDigitaleTablet School ImparaDigitale
Tablet School ImparaDigitalemarco anselmi
 
Pro presentationass2
Pro presentationass2Pro presentationass2
Pro presentationass2dhoke_cis235
 
Интернет-агентство "видОК" - Seo-оптимизация для сайтов
Интернет-агентство "видОК" - Seo-оптимизация для сайтовИнтернет-агентство "видОК" - Seo-оптимизация для сайтов
Интернет-агентство "видОК" - Seo-оптимизация для сайтовДенис Мидаков
 
роль русского языка, литературы, истории и обществознания в современном обще...
роль русского языка, литературы, истории и обществознания  в современном обще...роль русского языка, литературы, истории и обществознания  в современном обще...
роль русского языка, литературы, истории и обществознания в современном обще...Alexander Denisov
 
EMID Superintendents Report to School Board Working Session
EMID Superintendents Report to School Board Working SessionEMID Superintendents Report to School Board Working Session
EMID Superintendents Report to School Board Working SessionEMID Families
 
CP_Pres_2.0_-_Generic
CP_Pres_2.0_-_GenericCP_Pres_2.0_-_Generic
CP_Pres_2.0_-_Genericalroche
 

Andere mochten auch (20)

Bristol Cycle Festival
Bristol Cycle FestivalBristol Cycle Festival
Bristol Cycle Festival
 
Activitats tema 1
Activitats tema 1Activitats tema 1
Activitats tema 1
 
Gay archipelago-bahasa-indonesia
Gay archipelago-bahasa-indonesiaGay archipelago-bahasa-indonesia
Gay archipelago-bahasa-indonesia
 
North American BioFortean Review - Yuri Kuchinsky
North American BioFortean Review - Yuri KuchinskyNorth American BioFortean Review - Yuri Kuchinsky
North American BioFortean Review - Yuri Kuchinsky
 
36 quatro-níveis-de-avaliação-de-treinamento
36 quatro-níveis-de-avaliação-de-treinamento36 quatro-níveis-de-avaliação-de-treinamento
36 quatro-níveis-de-avaliação-de-treinamento
 
Indian Horses Before Columbus Evidences in America
Indian Horses Before Columbus Evidences in AmericaIndian Horses Before Columbus Evidences in America
Indian Horses Before Columbus Evidences in America
 
Personalized Learning at Your Fingertips: Building a PLN
Personalized Learning at Your Fingertips: Building a PLNPersonalized Learning at Your Fingertips: Building a PLN
Personalized Learning at Your Fingertips: Building a PLN
 
Lorenc gordani winter outlook report 201415 and summer review 2014
Lorenc gordani   winter outlook report 201415 and summer review 2014Lorenc gordani   winter outlook report 201415 and summer review 2014
Lorenc gordani winter outlook report 201415 and summer review 2014
 
Nb preparation pdf_c1slot
Nb preparation pdf_c1slotNb preparation pdf_c1slot
Nb preparation pdf_c1slot
 
Thoughts On Patent Damages Landscape Post-Halo - Law360
Thoughts On Patent Damages Landscape Post-Halo - Law360Thoughts On Patent Damages Landscape Post-Halo - Law360
Thoughts On Patent Damages Landscape Post-Halo - Law360
 
Albanian Res by Dr Lorenc Gordani - Slides
Albanian Res by Dr Lorenc Gordani - SlidesAlbanian Res by Dr Lorenc Gordani - Slides
Albanian Res by Dr Lorenc Gordani - Slides
 
Tablet School ImparaDigitale
Tablet School ImparaDigitaleTablet School ImparaDigitale
Tablet School ImparaDigitale
 
Photoshop
PhotoshopPhotoshop
Photoshop
 
Sem 7 conteo de figuras
Sem 7   conteo de figurasSem 7   conteo de figuras
Sem 7 conteo de figuras
 
Pro presentationass2
Pro presentationass2Pro presentationass2
Pro presentationass2
 
Интернет-агентство "видОК" - Seo-оптимизация для сайтов
Интернет-агентство "видОК" - Seo-оптимизация для сайтовИнтернет-агентство "видОК" - Seo-оптимизация для сайтов
Интернет-агентство "видОК" - Seo-оптимизация для сайтов
 
роль русского языка, литературы, истории и обществознания в современном обще...
роль русского языка, литературы, истории и обществознания  в современном обще...роль русского языка, литературы, истории и обществознания  в современном обще...
роль русского языка, литературы, истории и обществознания в современном обще...
 
EMID Superintendents Report to School Board Working Session
EMID Superintendents Report to School Board Working SessionEMID Superintendents Report to School Board Working Session
EMID Superintendents Report to School Board Working Session
 
CP_Pres_2.0_-_Generic
CP_Pres_2.0_-_GenericCP_Pres_2.0_-_Generic
CP_Pres_2.0_-_Generic
 
104
104104
104
 

Ähnlich wie Lessons Learned: Migrating Tests to Selenium v2

JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom ManipulationMohammed Arif
 
What's new and exciting with JSF 2.0
What's new and exciting with JSF 2.0What's new and exciting with JSF 2.0
What's new and exciting with JSF 2.0Michael Fons
 
JavaScript and DOM Pattern Implementation
JavaScript and DOM Pattern ImplementationJavaScript and DOM Pattern Implementation
JavaScript and DOM Pattern Implementationdavejohnson
 
Migrating from Struts 1 to Struts 2
Migrating from Struts 1 to Struts 2Migrating from Struts 1 to Struts 2
Migrating from Struts 1 to Struts 2Matt Raible
 
Developing and testing ajax components
Developing and testing ajax componentsDeveloping and testing ajax components
Developing and testing ajax componentsIgnacio Coloma
 
Composite Applications with WPF and PRISM
Composite Applications with WPF and PRISMComposite Applications with WPF and PRISM
Composite Applications with WPF and PRISMEyal Vardi
 
jQuery for Sharepoint Dev
jQuery for Sharepoint DevjQuery for Sharepoint Dev
jQuery for Sharepoint DevZeddy Iskandar
 
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry GervinWill your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry GervinBarry Gervin
 
Open social 2.0 sandbox ee and breaking out of the gadget box
Open social 2.0 sandbox  ee and breaking out of the gadget boxOpen social 2.0 sandbox  ee and breaking out of the gadget box
Open social 2.0 sandbox ee and breaking out of the gadget boxRyan Baxter
 
Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2borkweb
 
Jquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript BasicsJquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript BasicsEPAM Systems
 

Ähnlich wie Lessons Learned: Migrating Tests to Selenium v2 (20)

jQuery Mobile
jQuery MobilejQuery Mobile
jQuery Mobile
 
jQuery
jQueryjQuery
jQuery
 
JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom Manipulation
 
Frontin like-a-backer
Frontin like-a-backerFrontin like-a-backer
Frontin like-a-backer
 
What's new and exciting with JSF 2.0
What's new and exciting with JSF 2.0What's new and exciting with JSF 2.0
What's new and exciting with JSF 2.0
 
JavaScript and DOM Pattern Implementation
JavaScript and DOM Pattern ImplementationJavaScript and DOM Pattern Implementation
JavaScript and DOM Pattern Implementation
 
Migrating from Struts 1 to Struts 2
Migrating from Struts 1 to Struts 2Migrating from Struts 1 to Struts 2
Migrating from Struts 1 to Struts 2
 
Developing and testing ajax components
Developing and testing ajax componentsDeveloping and testing ajax components
Developing and testing ajax components
 
Composite Applications with WPF and PRISM
Composite Applications with WPF and PRISMComposite Applications with WPF and PRISM
Composite Applications with WPF and PRISM
 
jQuery for Sharepoint Dev
jQuery for Sharepoint DevjQuery for Sharepoint Dev
jQuery for Sharepoint Dev
 
J query
J queryJ query
J query
 
jQuery
jQueryjQuery
jQuery
 
J query training
J query trainingJ query training
J query training
 
Jquery
JqueryJquery
Jquery
 
Jsfsunum
JsfsunumJsfsunum
Jsfsunum
 
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry GervinWill your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
 
jQuery
jQueryjQuery
jQuery
 
Open social 2.0 sandbox ee and breaking out of the gadget box
Open social 2.0 sandbox  ee and breaking out of the gadget boxOpen social 2.0 sandbox  ee and breaking out of the gadget box
Open social 2.0 sandbox ee and breaking out of the gadget box
 
Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2
 
Jquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript BasicsJquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript Basics
 

Kürzlich hochgeladen

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 

Kürzlich hochgeladen (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 

Lessons Learned: Migrating Tests to Selenium v2

  • 1. Lessons Learned: Migrating Tests To Selenium v2 September 20, 2011 Roger Hu (rhu@hearsaycorp.com)
  • 2.
  • 3. Enables reps to compliantly capitalize on LinkedIn, Twitter, and Facebook
  • 4. Backed by Sequoia, NEA, Steve Chen, FB execs
  • 5.
  • 6. Reasons to Switch Selenium v2 more closely approximates the user experience. Internet Explorer (IE7/IE8) especially runs faster with Selenium v2 (> 20%?) Easier to write tests. WebDriver reflects how other JavaScript frameworks work.
  • 7. Selenium v2 Approach Example: driver = webdriver.Firefox() driver.find_element_by_xpath(“//a[text()=‘Create New Ad’”).click() driver.find_element_by_id(“ads_headline”).send_keys(“Selenium Testers Wanted”) Selenium server launches without needing proxy-based approach. Browser driver generates native keyboard/mouse clicks to more closely simulate user behavior. WebDriver API (REST-based) simpler. Browser-specific driver i.e.: IEDriver.dll (IE), webdriver.xpi (Firefox) + WebDriver API
  • 8. Complexities of Moving to Selenium v2 Your tests have to be rewritten to leverage the WebDriver API. Record/playback less useful option? (Selenium IDE plug-in for Firefox) Synchronization issues: implement more implicit/explicit wait conditions (Selenium v2 sometimes acts like an impatient user) Hidden/non-visible elements can no longer be clicked. Specific WebDriverextension for each browser. Cross-browser issues with mouse click/keyboard events. CSS3 selectors now more dependent on the browser (unlike Selenium v1). Not all WebDriver extensions are fully baked (i.e. Chrome, Android, iPhone) Keeping up with the release cycles. Release Candidates: toggle()/select() removed from API. We do a lot of pip –U selenium. Make sure you’re using the latest version of your preferred language binding! Documentation is sparse, and hard to debug without digging through Selenium source code (Java, C++, and JavaScript).
  • 9. Visibility Matters i.e. driver.find_element_by_id(“cms_toolbar_icon”).click() The X/Y coordinates of the element location are used to determine where to click. Hidden elements can no longer be acted upon until they are visible. The element gets focused and clicked. Some quirky issues with elements at top or bottom of the screen exist. CSS z-index takes precedence now; the top-most element will be the one that receives the mouse event. If you use any type of debug overlay tool (i.eDjango Debug Toolbar, Rails Footnotes, etc.) disable them before running your Selenium tests!
  • 10.
  • 11.
  • 12. Demo So how does this implicit/explicit wait stuff work? Let’s play Hearsay Social Says...http://hearsaysocialsays.appspot.com (Selenium v2 source code posted on the site) def play_level(): driver.find_element_by_name("b").click() WebDriverWait(driver, timeout=10).until(lambda driver: driver.find_element_by_name("s").get_attribute("value") == "Player's Turn") pcclicks = driver.execute_script("return pcclicks;") for pcclick in pcclicks[1:]: ele = "pl%s" % pcclick driver.find_element_by_name(ele).click() driver.find_element_by_name("b").click() # Alert box shows up. Let's dismiss it. driver.switch_to_alert() Alert(driver).accept() for i in xrange(20): play_level()
  • 13. Native vs. Synthetic Events Selenium v1 relied entirely on generating events through JavaScript, while Selenium v2 tries to do it through the operating system. Selecting a dropdown: driver.find_element_by_xpath("//select[@id=‘myselect']/option[text()=‘Seattle']").select() (deprecated) driver.find_elements_by_css_selector("#myselect option")[2].click() # IE7/IE8 won’t click (JS issue) from selenium.webdriver.common.keys import Keys driver.find_element_by_css_selector("#myselect").send_keys(Keys.DOWN) (IE7/IE8 have different behavior for disabled elements) One workaround: driver.execute_script(“$(‘#myselect option’][2].change()’);”) (use jQuery to trigger select-box changes) You can always bypass some cross-browser issues related to native events by reverting to JavaScript-based events, though it’s not ideal. <select id=“myselect”> <option value="1">Seattle</option> <option value="2“ disabled=disabled>Boston</option> <option value=”3”>San Francisco</option> <option value=“4">Washington D.C.</option> </select>
  • 14. Hover states, drag-and-drop, motion-based gestures, HTML5…. Want more complex sequences of keyboard/mouse actions (i.e. right clicks, double clicks, drag/drop)? Use the ActionChains class. Creating hover states: also done through ActionChains class. Remember, the elements still have to be visible for them to be chained! Many advanced user interactions still somewhat experimental, so expect issues. from selenium.webdriver import ActionChains driver.get(‘http://www.espn.com’) menu_mlb= driver.find_element_by_id("menu-mlb") chain = ActionChains(driver) chain.move_to_element(menu_mlb).perform() chain.move_to_element(menu_mlb).click(scores).perform() (scores is not visible until MLB is selected) scores = driver.find_elements_by_css_selector("#menu-mlb div.mod-content ul li")[1] scores.click()
  • 15.
  • 16. Other Tips & Tricks… Use Firebug with Selenium v2. Create a profile and installing the extension: firefox -ProfileManager --no-remote (launch profile manager and install Firebug extension) Specify profile directory: profile = FirefoxProfile(profile_directory=“/home/user/.mozilla/firefox/60f7of9x.selenium”) driver = webdriver.Firefox(firefox_profile=profile) Test on local browsers first, use SSH reverse tunneling when testing on remote devservers: Install Selenium server on host machine: java –jar selenium-server.jar (default port 4444) Create a SSH tunnel into remote machine: ssh-nNT -R 9999:<IP address of server>:4444 username@myhost.com(clients connect to port 9999) Login to remote machine and connect via webdriver.Remote() driver = webdriver.Remote(command_executor=http://localhost:9999/wd/hub) Using SauceLabs? Make sure your max-duration: option is set if your test runs exceed 30 mins. Can’t keep up with the Selenium v2 release cycles? Fix your version with selenium-version: option. Use exit signals handlers to issue driver.quit() commands to see your test results sooner.
  • 17. Summary Selenium v2 gets closer to simulating the user experience with an entirely new architecture (WebDriver API + browser plug-in/extension). Your tests may start failing on clicking on hidden/non-visible elements, so disable your debug overlays and be aware of CSS z-index issues. Bugs/issues with generating events still persist, and you may encounter many browser quirks (i.e. dropdown boxes). WebDriver may run faster, though you may need to add more synchronization checkpoints with implicit/explicit waits. When using CSS selectors, use the ones supported across all browsers (especially IE).
  • 18. Q/A