Selenium

46
Presentation @ selemium tool Jagdish Patel Sr. QA Engineer

Transcript of Selenium

Page 1: Selenium

Presentation @ selemium tool

Jagdish PatelSr. QA Engineer

Page 2: Selenium

A brief overview of functional, regression and compatibility testing

An introduction to Selenium tool

Understanding various concepts related to Selenium

Practical examples

Q&A

Topics for today's presentation

© Copyright 2008, Gateway Group of companies.

Page 3: Selenium

Measures the quality of the business components of the system.

Verifies that the system behaves correctly from the user / business perspective.

Verifies that each component or business event performs in accordance to the specifications, responds correctly to all conditions that may be presented by incoming events / data, moves data correctly from one business event to the next in the order required to meet the business objectives of the system.

Functional testing

© Copyright 2008: Gateway Group of companies.

Page 4: Selenium

Testing of a program that has been modified in order to ensure that additional bugs have not been introduced. When a program is enhanced, testing is often done only for the newly added features. However, adding source code to a program often introduces errors in other routines. Hence the old and stable functions must be retested along with the new ones.

Regression testing

© Copyright 2008, Gateway Group of companies.

Page 5: Selenium

Part of software non-functional testing, conducted on the application to evaluate the application's compatibility with the computing environment like:

Browser compatibility (Firefox, Netscape, Internet Explorer,Safari, etc.)

Operating systems (MVS, UNIX, Windows, etc.)

Database (Oracle, Sybase, DB2, etc.)

Other System Software (Web server, networking/ messaging tool, etc.)

Computing capacity of Hardware Platform (IBM 360, HP 9000, etc.)

Bandwidth handling capacity of networking hardware

Compatibility testing

© Copyright 2008, Gateway Group of companies.

Page 6: Selenium

A test case is a set of test data and test programs (test scripts) and their expected results. A test case validates one or more system requirements and generates a pass or fail.

A test suite is collection of test scenarios and/or test cases that are related or that

cooperate with each other.

Test Case & Test Suite

© Copyright 2008, Gateway Group of companies.

Page 7: Selenium

Selenium is a portable software testing framework for web applications. The tests can be written as HTML tables or coded in a number of popular programming languages and can be run directly in most modern web browsers. Selenium can be deployed on Windows, Linux, and Macintosh.

Selenium was developed by a team of programmers and testers at ThoughtWorks Inc.

It is released under the Apache 2.0 license and can be downloaded and used without charge.

What is Selenium?

© Copyright 2008, Gateway Group of companies.

Page 8: Selenium

Reduce the time in regression testing

Platform independent

Browser compatibility

Open source

Light weight

Check periodically to see if the site is on-line and works correctly

Why should we care?

© Copyright 2008, Gateway Group of companies.

Page 9: Selenium

Get everything at: www.openqa.org/selenium/

Additional requirements:

JDK 1.5 or above: www.sun.com

Ant 1.7: http://apache.mirrors.hoobly.com/ant/binaries/apache-ant-1.7.0-bin.zip

Where to get Selenium

© Copyright 2008, Gateway Group of companies.

Page 10: Selenium

Selenium Core

Selenium IDE

Selenium Remote Control

Selenium Grid

Selenium core concepts

© Copyright 2008, Gateway Group of companies.

Page 11: Selenium

How Selenium Works

© Copyright 2008, Gateway Group of companies.

Page 12: Selenium

Browser support

Platforms supported by Selenium

© Copyright 2008, Gateway Group of companies.

Browser Selenium IDE Selenium RC Selenium Core

Firefox 3 Record and playback tests Start browser, run tests Run test

Firefox 2 Record and playback tests Start browser, run tests Run test

IE 6 not supported Start browser, run tests Run test

IE 7 not supported Start browser, run tests Run test

Safari 3 not supported Start browser, run tests Run test

Safari 2 not supported Start browser, run tests Run test

Opera 9 not supported Start browser, run tests Run test

Page 13: Selenium

OS Support

Platforms supported by Selenium..

© Copyright 2008, Gateway Group of companies.

OS Selenium IDE Selenium RC Selenium Core

Windows Works in Firefox 2+ Start browser, run tests Run test

OS X Works in Firefox 2+ Start browser, run tests Run test

Linux Works in Firefox 2+ Start browser, run tests Run test

Solaris Works in Firefox 2+ Start browser, run tests Run test

Page 14: Selenium

Programming Languages support

Platforms supported by Selenium..

© Copyright 2008, Gateway Group of companies.

Language Selenium IDE Selenium RC Selenium Core

C# Generate code Library ("driver") support

n/a

Java Generate code Library ("driver") support n/a

Perl Generate code Library ("driver") supportn/a

PHP Generate code Library ("driver") supportn/a

Python Generate code Library ("driver") supportn/a

Ruby Generate code Library ("driver") supportn/a

Page 15: Selenium

Selenium Core

© Copyright 2008, Gateway Group of companies.

Selenium Core is a test tool for web applications. Selenium Core tests run directly in a browser, just as real users do. The test cases/suites can be tested on various browsers like: IE, FireFox and Opera and also on multiple platforms like: Mac, Windows, Linux etc.

Page 16: Selenium

Selenium Core uses a unique mechanism which allows it to run on so many platformsWritten in pure JavaScript/DHTMLWe must have 'write' access to the machine our web application server is running on to install Selenium Core.

Selenium Core..

© Copyright 2008, Gateway Group of companies.

Page 17: Selenium

Platform and Browser Compatibility:

Windows: Internet Explorer 6.0 and 7.0 Firefox 0.8 to 2.0 Mozilla Suite 1.6+, 1.7+ Seamonkey 1.0 Opera 8 & 9 Mac OS X:Safari 2.0.4+ Firefox 0.8 to 2.0 Camino 1.0a1 Mozilla Suite 1.6+, 1.7+ Seamonkey 1.0 Not yet supported: OmniWeb

Selenium Core..

© Copyright 2008, Gateway Group of companies.

Page 18: Selenium

Linux: Firefox 0.8 to 2.0 Mozilla Suite 1.6+, 1.7+ Konqueror Opera 8 & 9

Selenium Core..

© Copyright 2008, Gateway Group of companies.

Page 19: Selenium

We need to extract the Selenium Core zip file into the 'DocumentRoot', 'htdocs', or 'webroot' folder of our webserver.

We then try to open the TestRunner.html page on our website, which should be in the folder/directory.

http://10.0.1.106/selenium core/core/TestRunner.html

Installing Selenium Core

© Copyright 2008, Gateway Group of companies.

Page 20: Selenium

Selenium uses javascript and iframes to embed a test automation engine in yourbrowser.This technique should work with any javascript-enabled browser. Because different browsers handle javascript somewhat differently, we usually have totweak the engine to support a wide range of browsers on Windows, Mac OS X and Linux.

How does Selenium Core Work

© Copyright 2008, Gateway Group of companies.

Page 21: Selenium

Running Selenium's Test Suite

© Copyright 2008, Gateway Group of companies.

Page 22: Selenium

Test Suite

Application being tested

Test Cases

Steps of the test case

Execution Control

Page 23: Selenium

Run All Tests

Run Selected Test

Pause/Play Execution Step through

Execution

Control Speed of Execution

Highlight Elements in the Execution

View the DOM of the current Page being tested

Summary of the Test

View the log of the current execution

Page 24: Selenium

To use Selenium Core, we need to make it available from the same web server as the application you want to test. That means that we can't use Selenium Core (pure DHTML/JavaScript) to write a test of google.com This is because Selenium Core is pure DHTML/JavaScript, and so it is bound by JavaScript's security restrictions. Specifically, JavaScript enforces (This is a JavaScript security requirement. If we can't/won't modify the webserver we want to test, Selenium Core may not be the right tool for us; We may just want to use Selenium IDE or Selenium RC instead.

Limitation of Selenium Core

© Copyright 2008, Gateway Group of companies.

Page 25: Selenium

Selenium IDE is an integrated development environment for Selenium tests. It is implemented as a Firefox extension, and allows us to record, edit, and debug tests. Selenium IDE includes the entire Selenium Core, allowing us to easily and quickly record and play back tests in the actual environment that they will run.

Selenium IDE is not only recording tool: it is a complete IDE. We can choose to use its recording capability, or we may edit our scripts by hand. With the autocomplete support and the ability to move commands around quickly, Selenium IDE is the ideal environment for creating Selenium tests no matter what style of tests we prefer.

Selenium IDE

© Copyright 2008, Gateway Group of companies.

Page 26: Selenium

The root of web application you want to test

The list of actions in the actual test case to execute

The log of the events that were executed, including any errors or warning that have occurred

Page 27: Selenium

ExecutionCommands

Try the test in the Web based TestRunner

Reference of the currently selected command

Record test actions

Specify commands, including asserts

Page 28: Selenium

Features: Easy record and playback Intelligent field selection will use IDs, names, or XPath as needed Autocomplete for all common Selenium commands Walk through tests Debug and set breakpoints Save tests as HTML, Ruby scripts, or any other format Support for Selenium user-extensions.js file Option to automatically assert the title of every page

Selenium IDE..

© Copyright 2008, Gateway Group of companies.

Page 29: Selenium

How to create a test plan in Selenium IDE

Install Selenium IDE 1.0-beta, a Firefox plugin. After installing Selenium we need to restart your Firefox browser for the plugin to be activated. Now we should see a new added menu item named Selenium IDE under the Firefox 'Tools' menu. We open / browse the site for which we want to prepare a test case. We start Selenium IDE from Firefox Tools->Selenium IDE. We browse some pages. We click red button to stop recording.

Selenium IDE..

© Copyright 2008, Gateway Group of companies.

Page 30: Selenium

Creating a Test Suite

A Test Suite in Selenium is just an HTML file that contains a table of links to tests

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head> <meta content="text/html; charset=UTF-8" http-equiv="content-type" /><title>Test Suite</title></head><body> <table id="suiteTable" cellpadding="1" cellspacing="1" border="1" class="selenium"><tbody><tr><td><b>Test Suite</b></td></tr><tr><td><a href="hotel.html">hotel</a></td></tr><tr><td><a href="Restaurant.html">Restaurant</a></td></tr><tr><td><a href="Meeting.html">Meeting</a></td></tr><tr><td><a href="Vacancies.html">Vacancies</a></td></tr></tbody></table></body></html>

Page 31: Selenium

Selenium Remote Control (RC) is a test tool that allows you to write automated web application UI tests in any programming language against any HTTP website using any mainstream JavaScript-enabled browser.Selenium tests run directly in a browser, just as real users do. These tests can be used for both acceptance testing (by performing higher-level tests on the integrated system instead of just testing each unit of the system independently) and browser compatibility testing (by testing the web application on different operating systems and browsers

Selenium-Remote Control

© Copyright 2008, Gateway Group of companies.

Page 32: Selenium

Selenium RC comes in two parts.

1 A server which automatically launches and kills browsers, and acts as a HTTP proxy for web requests from them. 2. Client libraries for your favourite computer language.

The RC server also bundles Selenium Core, and automatically loads it into the browser.

Selenium-Remote Control..

© Copyright 2008, Gateway Group of companies.

Page 33: Selenium

Selenium-Remote Control

© Copyright 2008, Gateway Group of companies.

Page 34: Selenium

The Selenium Server is written in Java, and requires the Java Runtime Environment (JRE) version 1.5.0 or higher in order to start. You may already have it installed. Try running this from the command line: java -versionYou should see a brief message telling you what version of Java is installed, like this:java version "1.5.0_07"Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_07-b03)Java HotSpot(TM) Client VM (build 1.5.0_07-b03, mixed mode)If you see an error message instead, you may need to install the JRE, or you may need to add it to your PATH environment variable.

Selenium-Remote Control..

© Copyright 2008, Gateway Group of companies.

Page 35: Selenium

C:\Program Files\Java>d:D:\>cd jag*D:\jagdish>cd se*D:\jagdish\seleniumtool>cd se*D:\jagdish\seleniumtool\SELenium core>cd..D:\jagdish\seleniumtool>cd seleniumrcD:\jagdish\seleniumtool\SeleniumRC>cd selenium-re*D:\jagdish\seleniumtool\SeleniumRC\selenium-remote-control-1.0-beta-1>cd selenium-se*D:\jagdish\seleniumtool\SeleniumRC\selenium-remote-control-1.0- beta-1\selenium-server-1.0-beta-1>D:\jagdish\seleniumtool\SeleniumRC\selenium-remote-control-1.0- beta-1\selenium-server-1.0-beta-1>java -jar selenium-server.jar -htmlsuite *firefox http://10.0.1.106/chagallhotel/ c:\testsuite\Chagallhotel.html c:\testsuite\results.html

Selenium-Remote Control..

© Copyright 2008, Gateway Group of companies.

Page 36: Selenium

Selenium-Remote Control..

© Copyright 2008, Gateway Group of companies.

Page 37: Selenium

(+) Java (JUnit)

import com.thoughtworks.selenium.*;

import junit.framework.*;

public class ChagallTest extends TestCase { private Selenium browser;

public void setUp() { browser = new DefaultSelenium("localhost",

4444, "*firefox", "http://10.0.1.106/chagallhotel/");

browser.start(); }

public void testGoogle() { browser.open("http://10.0.1.106/chagallhotel/admin");

browser.type("q", "ld");

browser.click("btnG"); browser.waitForPageToLoad("5000");

assertEquals(" ", browser.getTitle());

}

public void tearDown() { browser.stop();

}

}

Programming a Selenium RC Test

© Copyright 2008, Gateway Group of companies.

Page 38: Selenium

(+) C# (NUnit)

using Selenium;using Nunit.Framework; namespace MyTests { [TestFixture] public class ChagallTest { private ISelenium browser public void SetUp() { browser = new DefaultSelenium("localhost", 4444,"*firefox","http://http://10.0.1.106/chagallhotel/"); browser.Start(); } public void testChagall() { browser.Open("http://10.0.1.106/chagallhotel/"); browser.Type("q", "ld"); browser.Click("btnG"); browser.WaitForPageToLoad("5000"); Assert.AreEqual(" ", browser.GetTitle()); } public void TearDown() { browser.Stop(); } }}

Programming a Selenium RC Test

© Copyright 2008, Gateway Group of companies.

Page 39: Selenium

(+) PHP (PHPUnit)

require_once 'Testing/Selenium.php';

require_once 'PHPUnit/Framework/TestCase.php';

class ChagallTest extends PHPUnit_Framework_TestCase

{ private $browser; public function setUp() {

$this->browser = new Testing_Selenium("*firefox", "http://http://10.0.1.106/chagallhotel/");

$this->browser->start(); }

public function tearDown() {$this->browser->stop();}

public function testChagall()

{ $this->browser->open("/webhp?hl=en");

$this->browser->type("q", "ld");

$this->browser->click("btnG");

$this->browser->waitForPageToLoad(10000);

$this->assertRegExp(" ", $this->browser->getTitle());

} }

Programming a Selenium RC Test

© Copyright 2008, Gateway Group of companies.

Page 40: Selenium

Live Demo of an example

© Copyright 2008, Gateway Group of companies.

Page 41: Selenium

Q&A

© Copyright 2008, Gateway Group of companies.

Page 42: Selenium

Anand Tiwari

Thanks to...

© Copyright 2008, Gateway Group of companies.

Page 43: Selenium

Fulfilling Customer Needs

Describe the main attributes of the product Link the product attributes to customer

needs

Page 44: Selenium

Cost Analysis

Indicate the financial advantages for the customer

Compare quality and price with those of the competition

Page 45: Selenium

Strengths and Advantages

Summarize the special features and advantages of the product being introduced

Page 46: Selenium

Next Steps of Action

Explain the steps that now need to be taken