efficient automated test creation with selenium ide plugins

55
Efficient Automated Test Creation With Selenium IDE Plugins Selenium Conference 2011 San Francisco 4 th April 2011

Upload: samit-badle

Post on 28-May-2015

7.140 views

Category:

Technology


0 download

DESCRIPTION

A taste of creating Selenium IDE plugins and an idea of generating automated tests

TRANSCRIPT

Page 1: Efficient Automated Test Creation With Selenium IDE Plugins

Efficient Automated Test

Creation With Selenium IDE

Plugins

Selenium Conference 2011

San Francisco

4th April 2011

Page 2: Efficient Automated Test Creation With Selenium IDE Plugins

Samit Badle

@samitbadle

http://blog.reallysimplethoughts.com

Page 3: Efficient Automated Test Creation With Selenium IDE Plugins

Goals

• Give you a taste of creating a Selenium IDE plugin

• Make you aware of the code in various files by completing the TODOs in the exercises

• Introduce you to ideas for efficiently creating tests or test data

Page 4: Efficient Automated Test Creation With Selenium IDE Plugins

Agenda

• Brief introduction

• Create a Selenium IDE plugin with

– Menu and Toolbar buttons

– Selenium IDE Plugin API

– Preferences

– Command Builder

• Ideas to efficiently create tests

Page 5: Efficient Automated Test Creation With Selenium IDE Plugins

Getting Ready

• Install the latest version of Firefox

– Either Firefox 3.6.16 or Firefox 4.0

• Install 7-Zip or your favorite zip tool

• Download the WorkshopFiles.zip

– http://links.reallysimplethoughts.com/files/Wor

kshopFiles.zip

Page 6: Efficient Automated Test Creation With Selenium IDE Plugins

Using WorkshopFiles.zip

• Extract WorkshopFiles.zip

• Install the special version of Selenium IDE (selenium-ide-multi-workshop.xpi) included in it

• The HandsOn folder contains the exercises

• The Solutions folder contains the completed versions and pre-built plugins

Page 7: Efficient Automated Test Creation With Selenium IDE Plugins

What are Selenium IDE Plugins?

Demos!

Page 8: Efficient Automated Test Creation With Selenium IDE Plugins

Where to find them?

• Selenium download page

http://seleniumhq.org/download/

• Firefox add-ons page

https://addons.mozilla.org/en-US/firefox/

• Other places on the Internet

Google ☺

Page 9: Efficient Automated Test Creation With Selenium IDE Plugins

http://seleniumhq.org/download/

Page 10: Efficient Automated Test Creation With Selenium IDE Plugins

https://addons.mozilla.org/

Page 11: Efficient Automated Test Creation With Selenium IDE Plugins

Efficient Automated Test Creation?

“Automated Tests are Cool!”

“Automating Generation of Automated Tests is

Even Cooler.”

“But How?”

Page 12: Efficient Automated Test Creation With Selenium IDE Plugins

“Be Efficient” Selenium IDE Plugin

Here’s How!

• Add “Write My Test” to the context menu

• When I click on it, write my test for me

Page 13: Efficient Automated Test Creation With Selenium IDE Plugins

“Be Efficient” Selenium IDE Plugin

The Benefits

• Capture test data or test commands directly

• Direct access to the web page

• Reuse code from Selenium IDE and Selenium

Page 14: Efficient Automated Test Creation With Selenium IDE Plugins

Demo!

Page 15: Efficient Automated Test Creation With Selenium IDE Plugins

Be Efficient In Action

• Open Selenium IDE

• In Firefox, open www.bing.com

• Type selenium in search box

• Hit the enter key

• Right click on the results web page

• Select Write My Test!

• Check the generated test case

• Execute the test case (maybe with highlight elements plugin)

Page 16: Efficient Automated Test Creation With Selenium IDE Plugins

Be Efficient In Action

Page 17: Efficient Automated Test Creation With Selenium IDE Plugins

Be Efficient In Action

Page 18: Efficient Automated Test Creation With Selenium IDE Plugins

Be Efficient In Action

Page 19: Efficient Automated Test Creation With Selenium IDE Plugins

Be Efficient In Action

Page 20: Efficient Automated Test Creation With Selenium IDE Plugins

Be Efficient In Action

Page 21: Efficient Automated Test Creation With Selenium IDE Plugins

Be Efficient Code

Main code

User interface

Installation / registration code

Preferences defaults

Files required for a Firefox add-on

User interface styling

Page 22: Efficient Automated Test Creation With Selenium IDE Plugins

Simple Firefox Add-on

Page 23: Efficient Automated Test Creation With Selenium IDE Plugins

Simple Firefox Add-on

• XPI (zippy)

• Install Manifest (install.rdf)

• Chrome Manifest (chrome.manifest)

• Overlay containing a menu and toolbar button

• Style-sheet for the toolbar button

• Icon for the toolbar button

Page 24: Efficient Automated Test Creation With Selenium IDE Plugins

Simple Firefox Addon

Page 25: Efficient Automated Test Creation With Selenium IDE Plugins

Your Turn

• Explore the files in the first exercise HandsOn/selenium-ide_be-efficient_ex1

• Complete the TODO in the following files

– Install Manifest (install.rdf)

– Chrome Manifest (chrome.manifest)

– Overlay (ovIDE.xul)

– Style sheet (beefficient.css)

Page 26: Efficient Automated Test Creation With Selenium IDE Plugins

Package and Install

• Create a zip of all files in src folder

• Change the file extension from .zip to .xpi

• Open this xpi file in Firefox

• Click on install button

• Restart to complete

Page 27: Efficient Automated Test Creation With Selenium IDE Plugins

Result

Page 28: Efficient Automated Test Creation With Selenium IDE Plugins

Result

• New menu item in the Options menu in Selenium IDE

• A new toolbar button on the right side

• Clicking on the menu item or toolbar item results in a simple alert message

Page 29: Efficient Automated Test Creation With Selenium IDE Plugins

Selenium IDE Plugin API

Page 30: Efficient Automated Test Creation With Selenium IDE Plugins

Plugin API Functions

• addPlugin

• addPluginProvidedIdeExtension

• addPluginProvidedFormatter

• addPluginProvidedUserExtension

Page 31: Efficient Automated Test Creation With Selenium IDE Plugins

Using the Plugin API

• Code to register plugin with Selenium IDE

• Load the real plugin code as an IDE extension

• Lots of boilerplate code

Page 32: Efficient Automated Test Creation With Selenium IDE Plugins

Using My pluginframework.js

Lots of boilerplate code hidden away in pluginframework.js and reduces the

required code to two lines.

Page 33: Efficient Automated Test Creation With Selenium IDE Plugins

Plugin API

Page 34: Efficient Automated Test Creation With Selenium IDE Plugins

Your Turn

• Explore the files in the second exercise HandsOn/selenium-ide_be-efficient_ex2

• Complete the TODO in the following files

– Chrome Manifest (chrome.manifest)

– Setup overlay (setup.xul)

– Setup code (setup.js)

– Overlay (ovIDE.xul)

– Real plugin code (BeEfficient.js)

Page 35: Efficient Automated Test Creation With Selenium IDE Plugins

Result

• Be Efficient Plugin now shows up in Plugins tab of the Selenium IDE options dialog

• The plugin code in BeEfficient and ovIDE.xul can now change the enabled state from the UI

Page 36: Efficient Automated Test Creation With Selenium IDE Plugins

Result

Page 37: Efficient Automated Test Creation With Selenium IDE Plugins

Preferences

Page 38: Efficient Automated Test Creation With Selenium IDE Plugins

Preferences

• Lot of support is built into Firefox

• Involves mostly boilerplate code

Page 39: Efficient Automated Test Creation With Selenium IDE Plugins

Preferences

• Create defaults for the preferences

• Create dialog to allow user to change preference

• Create an observer to receive notification of changes

• And one of the following (or both):– Define options in Install manifest

– Create UI (usually menu) to show Options dialog

Page 40: Efficient Automated Test Creation With Selenium IDE Plugins

Preferences

Page 41: Efficient Automated Test Creation With Selenium IDE Plugins

Your Turn

• Explore the files in the third exercise HandsOn/selenium-ide_be-efficient_ex3

• Complete the TODO in the following files

– Preference defaults (defaults.js)

– Options dialog (options.xul)

– Plugin code (BeEfficient.js)

– Install Manifest (install.rdf)

Page 42: Efficient Automated Test Creation With Selenium IDE Plugins

Result

• Be Efficient Plugin options dialog is available

• The options dialog can now be opened from the menu item

• The preference can be seen in about:config

• The preference and the UI elements are now in sync

Page 43: Efficient Automated Test Creation With Selenium IDE Plugins

Result

Page 44: Efficient Automated Test Creation With Selenium IDE Plugins

Result

Page 45: Efficient Automated Test Creation With Selenium IDE Plugins

Creating a Command Builder

Page 46: Efficient Automated Test Creation With Selenium IDE Plugins

Command Builder

• Puts a menu item in the context menu on the web page when Selenium IDE is open

• Three types: Action, Accessor, Util

• Util type will be available with Selenium IDE v1.0.11

Page 47: Efficient Automated Test Creation With Selenium IDE Plugins

Util Command Builder

• Register the Util command builder functions

• Prepare (builder) function– Returns the menu item to show

• Execute function– Called when the menu item is clicked

– Can return zero or more commands to add to the test case

Page 48: Efficient Automated Test Creation With Selenium IDE Plugins

Be Efficient Command Builder

• When the Write My Test! context menu item is pressed, create commands for the following

• Verify page title

• Wait for all results

• Verify each result

Page 49: Efficient Automated Test Creation With Selenium IDE Plugins

Your Turn

• Explore the files in the third exercise HandsOn/selenium-ide_be-efficient_ex4

• Complete the TODO in the following file

– Plugin code (BeEfficient.js)

Page 50: Efficient Automated Test Creation With Selenium IDE Plugins

Result

• Write My Test! context menu is available on the web page when Selenium IDE is open

• Clicking on the write my test on bing.comsearch results page will generate your test

Page 51: Efficient Automated Test Creation With Selenium IDE Plugins

Be Efficient In Action

• Open Selenium IDE

• In Firefox, open www.bing.com

• Type selenium in search box

• Hit the enter key

• Right click on the results web page

• Select Write My Test!

• Check the generated test case

• Execute the test case (maybe with highlight elements plugin)

Page 52: Efficient Automated Test Creation With Selenium IDE Plugins

Resources for Selenium IDE Plugins

• Selenium IDE Plugin Documentation

http://seleniumhq.org/projects/ide/plugins.html

• My Blog

http://blog.reallysimplethoughts.com/

Page 53: Efficient Automated Test Creation With Selenium IDE Plugins

Resources for Firefox Add-ons

https://developer.mozilla.org/en/XUL_School

https://developer.mozilla.org/en/Building_an_Extension

https://developer.mozilla.org/En/Firefox_addons_developer_guide

http://robertnyman.com/2009/01/24/how-to-develop-a-firefox-extension/

http://books.mozdev.org/chapters/index.html

https://developer.mozilla.org/en/Creating_XPCOM_Components

http://blog.mozilla.com/addons/2009/01/28/how-to-develop-a-firefox-extension/

http://roachfiend.com/archives/2004/12/08/how-to-create-firefox-extensions/

Page 54: Efficient Automated Test Creation With Selenium IDE Plugins

Time to Celebrate!

Thanks for Joining!

Page 55: Efficient Automated Test Creation With Selenium IDE Plugins

Questions?

Feel free to chat with me anytime