introduction to selenium

19
Selenium Web Test Automation Tool Rohit Nayak Talentica Software

Upload: rohitnayak

Post on 20-May-2015

9.896 views

Category:

Technology


1 download

DESCRIPTION

This is a quick introduction to the Selenium Test Automation tool.

TRANSCRIPT

Page 1: Introduction to Selenium

SeleniumWeb Test Automation Tool

Rohit Nayak

Talentica Software

Page 2: Introduction to Selenium

Agenda

• Demo

• What is Selenium? Why? Pros/Cons

• Writing test cases using Selenium

• Architecture

• Best Practices

Page 3: Introduction to Selenium

Demo

• Record a test in Selenium IDE

• Review test in Selenese HTML

Page 4: Introduction to Selenium

Similar Tools

• Bad Boy

• Sahi

• Silk Test, QTP (paid)

• Grinder

• Others: Watir, OpenSTA

Page 5: Introduction to Selenium

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

Page 6: Introduction to Selenium

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

Page 7: Introduction to Selenium

Common Problems in Web Testing

• Record/replay is not reusable, is fragile

• Managing test cases

• UI Changes make tests brittle

Page 8: Introduction to Selenium

Problems

• Performance (~HTMLUnit, WebTest)

• Reporting (~WebTest)

• Fancy CSS/Ajax needs tricky coding

• Data dependency should be avoided

Page 9: Introduction to Selenium

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!!

Page 10: Introduction to Selenium

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

Page 11: Introduction to Selenium

Demo 2

• Show same test written in Java

• Show same test written in PHP

Page 12: Introduction to Selenium

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());

}

Page 13: Introduction to Selenium

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();

}

Page 14: Introduction to Selenium

Some Selenese Commands

click waitForCondition isVisible

getTitle keyPress assertSelected

storeText mouseOver Input

goBack open dragdrop

fireEvent isElementPresent createCookie

isTextPresent type submit

Page 15: Introduction to Selenium

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 //

Page 16: Introduction to Selenium

Selenium Modules

• Selenium Core

• Selenium IDE

• Selenium Remote Control

• Client Drivers

• JS Extensions

Page 17: Introduction to Selenium

How it works

Page 18: Introduction to Selenium

Selenium Usage Patterns

Creating Tests• Recording using Selenium IDE• Writing tests in Selenese • Building a FrameworkRunning Tests• Through IDE• Using Selenium RC• Using Framework

Page 19: Introduction to Selenium

Advanced

• Cubic Test

• HRMES

• Selenium Grid

• BrowserMob

• Tellurium