introduction to selenium
DESCRIPTION
This is a quick introduction to the Selenium Test Automation tool.TRANSCRIPT
SeleniumWeb Test Automation Tool
Rohit Nayak
Talentica Software
Agenda
• Demo
• What is Selenium? Why? Pros/Cons
• Writing test cases using Selenium
• Architecture
• Best Practices
Demo
• Record a test in Selenium IDE
• Review test in Selenese HTML
Similar Tools
• Bad Boy
• Sahi
• Silk Test, QTP (paid)
• Grinder
• Others: Watir, OpenSTA
What is Selenium?
• Test tool for web applications• Actually runs in a browser• Supports tests in many languages• Selenese (pure HTML, no backend required)• Java, C#, Perl, Python, Ruby• Record/playback (Firefox plugin: Selenium IDE)• Open Source with corporate backing• Lives at selenium.org
Advantages
• Free!
• Can test across multiple browsers
• Mimics actual user experience
• Ajax / CSS support
• Use language of choice
• Large user community
• Great tools: CubicTest, Grid, HRMES
Common Problems in Web Testing
• Record/replay is not reusable, is fragile
• Managing test cases
• UI Changes make tests brittle
Problems
• Performance (~HTMLUnit, WebTest)
• Reporting (~WebTest)
• Fancy CSS/Ajax needs tricky coding
• Data dependency should be avoided
Best Practices
• All tests should be source control• One test per function not per page• Nightly runs• Separate environ specific variables • Automate fixed function, others manual• Abstract out functionality and reuse them• Parameterize your tests• Framework!!
Code for testability
• Demand this from Development• Visible feedback on actions (hidden values
in case div appears/disappears)• (dev-only) url for database teardown• Use of IDs for important UI elements• Good HTML• Good logs
Demo 2
• Show same test written in Java
• Show same test written in PHP
Java Example
public void testGoogleTestSearch() throws Exception
{selenium.open("http://www.google.com/webhp");assertEquals("Google", selenium.getTitle());selenium.type("q", "Selenium OpenQA");selenium.click("btnG");selenium.waitForPageToLoad("5000");assertEquals("Selenium OpenQA - Google Search",selenium.getTitle());
}
JUnit
public void setUp() throws Exception{
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.google.com");
selenium.start();
}public void tearDown() throws Exception{selenium.stop();
}
Some Selenese Commands
click waitForCondition isVisible
getTitle keyPress assertSelected
storeText mouseOver Input
goBack open dragdrop
fireEvent isElementPresent createCookie
isTextPresent type submit
Element locators
• ID: id=foo• Name: name=foo• First ID, then name: identifier=foo• DOM: document.forms[‘myform’].myDropdown• XPath: xpath=//table[@id='table1']//tr[4]/td[2]• Link Text: link=sometext• Sensible defaults, e.g. xpath if starts with //
Selenium Modules
• Selenium Core
• Selenium IDE
• Selenium Remote Control
• Client Drivers
• JS Extensions
How it works
Selenium Usage Patterns
Creating Tests• Recording using Selenium IDE• Writing tests in Selenese • Building a FrameworkRunning Tests• Through IDE• Using Selenium RC• Using Framework
Advanced
• Cubic Test
• HRMES
• Selenium Grid
• BrowserMob
• Tellurium