WHAT IS SELENIUM?
• Suite of tools
• Automates browsers
• Testing purposes
• Boring web-based administration tasks
TOOLS - SELENIUM IDE
• Selenium IDE
• Firefox extension
• Record and playback interactions
• Use it to
• Create quick bug reproduction scripts
• Create scripts to aid in automation-aided exploratory
testing
TOOLS - SELENIUM RC
• Selenium Remote Control
• Server
• Automatically launches and kills browsers
• Acts as a HTTP proxy for web requests from them
• Client libraries
• for your favourite computer language
• Deprecated
TOOLS - SELENIUM WEBDRIVER
• Successor to Selenium RC
• Driving a browser natively
• Accepts commands > browser
• Sent in Selenese or Client API
• Using a browser driver
TOOLS - SELENIUM GRID
• Web browsers on remote machines
• One server acts as a hub
• Tests contact hub to access browsers
• Running tests in parallel
TEXT PATTERNS - GLOBBING
• glob:
• *
• Match anything inside character class
• [ ]
• Character class
• [aeiou]
• [0-9]
• [a-zA-Z0-9]
TEXT PATTERNS – REGULAR
EXPRESSIONS
• regexp: or regexpi:
PATTERN MATCH
. any single character
[ ] character class: any single character that appears inside the brackets
* quantifier: 0 or more of the preceding character (or group)
+ quantifier: 1 or more of the preceding character (or group)
? quantifier: 0 or 1 of the preceding character (or group)
{1,5} quantifier: 1 through 5 of the preceding character (or group)
|
alternation: the character/group on the left or the character/group on the
right
( ) grouping: often used with alternation and/or quantifier
TEXT PATTERNS - EXACT
• Exact:
• “Real *”
• glob:Real * will also match “Real number”
• exact:Real *
• regexp:Real *
TEST SUITES
• A test suite is a collection of tests
• <html>
<head>
<title>Test Suite Function Tests - Priority 1</title>
</head>
<body>
<table>
<tr><td><b>Suite Of Tests</b></td></tr>
<tr><td><a href="./ultimateQuestionOfLive.html">Ultimate question of live</a></td></tr>
<tr><td><a href="./recursion.html">Recursion</a></td></tr>
</table>
</body>
</html>
COMMONLY USED
COMMANDS
• open
• opens a page using a URL.
• click/clickAndWait
• performs a click operation, and optionally waits for a new page to load.
• waitForPageToLoad
• pauses execution until an expected new page loads. Called automatically when
clickAndWait is used.
• waitForElementPresent
• pauses execution until an expected UI element, as defined by its HTML tag, is present
on the page.
COMMONLY USED
COMMANDS
• verifyTitle/assertTitle
• verifies an expected page title.
• verifyTextPresent
• verifies expected text is somewhere on the page.
• verifyElementPresent
• verifies an expected UI element, as defined by its HTML tag, is present on the
page.
• verifyText
• verifies expected text and its corresponding HTML tag are present on the page.
EXAMPLE
abstract class AbstractSeleniumTestCase extends TestCase
{
protected $webDriverUrl = ‘http://127.0.0.1:4444/wd/hub';
protected $webDriver;
public function setUp()
{
$this->webDriver = RemoteWebDriver::create(
$this->webDriverUrl, DesiredCapabilities::firefox()
);
}
public function tearDown()
{
if ($this->webDriver) {
$this->webDriver->quit();
}
}
}