Transcript

Functional Testing

Using Selenium

and ColdFusion

Our Agenda• What is Functional Testing?

• What is Selenium?

• Introducing the Selenium IDE

• Creating and Running Tests

• Using TestRunner

• Dynamic Tests Using ColdFusion

• Additional Resources

Me: Theo Rushin, Jr. ([email protected])

Senior Web Application Developer

@ TwinTechnologies

Application Developer and Trainer Since ‟85

ColdFusion Developer Since ‟99

Flash Developer Since ‟99

Flex Developer Since ‟05

Deploying Flex applications to AIR Since ‟07

Christian, husband, father, magician, snowboarder,

paintballer

Introductions

What is Functional TestingAn Overview

• It is the purpose of the functional testing to identify test cases that can be used to prove that the corresponding functionality is available and can be executed as well.

• It involves running a suite of tests on the completed system.

• Each individual test, known as a case, exercises a particular operating condition of the user's environment or feature of the system.

• These tests result in a pass or fail outcome.

What is Functional TestingWhy test?

• The objective is to provide confidence that the

delivered system meets the business

requirements of both sponsors and users.

• Proper testing can focus the discussion on the

problem, instead of the people - The problem

may be with the software and/or environment

and not with the person and/or organization.

What is SeleniumAn Overview

Selenium is a suite of tools used to automate web application testing across many platforms.

http://seleniumhq.org/

• Selenium IDE

• Selenium Remote Control (RC)

• Selenium Grid

What is SeleniumSelenium IDE

is a Firefox extension that enables you to record, edit, and debug tests.

• It‟s a complete IDE!

• These tests can then be played back in the browser.

• Selenium IDE contains the Selenium Core, the original Javascript-based testing system.

• Although Selenium Core can also be used as a pure Javascript/HTML testing system, it is primarily used as a component of the Selenium IDE and the Selenium Remote Control.

What is SeleniumSelenium Remote Control (RC)

allows you to write automated web application tests in

any programming language.

• Selenium Remote Control is a java-based server.

• This is an ideal solution for those who want to write

tests in a more expressive programming language

What is SeleniumSelenium Grid

enables you to distribute your tests on multiple

machines so that you can run your tests in parallel.

• Selenium Grid is a java-based server.

• Think of it as a distributed grid of Selenium Remote

Controls that we could easily be shared across

builds, applications, and projects.

SELENIUM IDE

SELENIUM REMOTE CONTROL SELENIUM GRID

Record and

play back

tests

Save test scripts in various

languages

What is SeleniumConcepts

• Commands tells Selenium what to do.

• Selenium commands come in three

„flavors‟: Actions, Accessors and

Assertions.

• Each command call is one line in the

test table.

command target value

What is SeleniumActions …

… are commands that generally manipulate the

state of the application.

• They do things like "click this link" and "select

that option".

• If an Action fails, or has an error, the

execution of the current test is stopped.

What is SeleniumAssertions …

… verify that the state of the application

conforms to what is expected

• Examples include:

“make sure the page title is …”

“verify that a checkbox is checked”.

What is SeleniumAssertions (cont.)

• All Selenium Assertions can be used in 3 modes: “assert”, “verify”, and “waitFor”

• “verify” and “assert” assertions are used to test form field values, labels, etc.

• When an “assert” fails, the test is aborted.

• When a “verify” fails, the test will continue execution, logging the failure.

• “waitFor” commands wait for some condition to become true.

• “waitFor” assertions will fail and halt the test if the condition does not become true within the current timeout setting

What is SeleniumAccessors …

… examine the state of the application and store

the results in variables, e.g. "storeTitle

• They are also used to automatically generate

Assertions.

• For example, the storeAlert Accessor

automatically generates the following Assertions:

assertAlert(), assertNotAlert(), verifyAlert(),

verifyNotAlert(), waitForAlert(), waitForNotAlert()

What is SeleniumExample HTML Test Script

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head profile="http://selenium-ide.openqa.org/profiles/test-case">

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<link rel="selenium.base" href="" />

<title>New Test</title>

</head>

<body>

<table cellpadding="1" cellspacing="1" border="1">

<thead>

<tr><td rowspan="1" colspan="3">New Test</td></tr>

</thead><tbody>

<tr>

<td>open</td>

<td>/</td>

<td></td>

</tr>

<tr>

<td>type</td>

<td>p</td>

<td>selenium</td>

</tr>

<tr>

<td>clickAndWait</td>

<td>searchsubmit</td>

<td></td>

</tr>

</tbody></table>

</body>

</html>

Command to open to a

specific URL

Command to type the

word „selenium‟

Command to click on the

Search button and wait.

What is SeleniumElement Locators …

… tell Selenium which HTML element a command refers to.

• The following strategies for locating elements are supported

• identifer=id

• id=id

• name=name

• dom=javascriptExpression

• xpath=xpathExpression

• link=textPatter

• css=sccSelector Syntax

What is SeleniumPatterns …

… can be used in actions, accessors, and locators, they

include regular-expressions.

What is SeleniumVariables …

... can be javascript or simple variables. Stored

Variables are referenced through Selenium

commands. Substitution Variables are called like

${variableName}

Introducing the Selenium IDEOverview

• Easily record and playback tests.

• Intelligent field selection will use IDs, names, or XPath as needed.

• Autocomplete for all common Selenium commands.

• Step 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.

Introducing the Selenium IDEOverview (cont.)

Creating and Running TestsA Demonstration

• Record a Test Script

• Run the Test Script

• Step Through the Test Script

• Debug the Test Script

Using TestRunnerAn Overview

Selenium TestRunner enables you to automate the execution of test scripts.

• The Selenium Core code, the tests, and the web application to be tested all reside under the web server's document root.

• Used without the Selenium IDE.

• Use the TestRunner URL in a browser with an argument pointing to the tests.

• The tests are read and TestRunner sends Javascript to the browser to execute them.

Using TestRunnerA Demonstration

URL Syntax:

chrome://selenium-

ide/content/selenium/TestRunner.html?ba

seURL=[baseurl]&test=file:///[testdir]/[test

suite].html&auto=true

Dynamic Tests Using ColdFusionA Demonstration

• Note: This strategy does not use the

Selenium Remote Control.

• Use CFQuery to retrieve “values” from a

database.

• Provide calculated “values”.

Additional Resources

• SeleniumHQ:

http://seleniumhq.org/

• Selenium Reference:

http://release.seleniumhq.org/selenium-

core/0.8.0/reference.html

• Selenium Forum:

http://clearspace.openqa.org/community/sele

nium


Recommended