Selenium WebDriver

Post on 22-Nov-2014

174 views 1 download

Tags:

description

Selenium WebDriver introduction Page object pattern overview

transcript

SELENIUM WEBDRIVER

Yuriy Bezgachnyuk, SSU/ITAOctober, 2014

2

Test automationWhat is Selenium WebDriverSelenium WD FeaturesDocument Object Model (DOM)

LocatorsExample task

PageObject pattern introduction

Agenda

3Test automation

In software testing, test automation is the use of special software (separate from the software being tested) to control the execution of tests and the comparison of actual outcomes to predicted outcomes.

Test Automation

4What is Selenium Web Driver

Selenium WebDriver – it’s a compact Object-Oriented API for Internet Browsers control

WebDriver is the name of the key interface against which tests should be written in Java, Python, Ruby, …

What is Selenium Web Driver

5Selenium WD Features

Connects to most modern browsersAllows remote control

Finds elements by selectors Modifies values of HTML elements Interacts with DOM elements Handles modal, popup windows

Selenium WD Features

6DOM Introduction

The Document Object Model (DOM) is a cross-platform and language-independent convention for representing and interacting with objects in HTML, XHTML and XML documents.

Document Object Model (DOM)

7DOM [Locators]

Select any HTML element(s) from DOM by using tags name attributes of tags

• id, name, … CSS selectors XPath

DOM [Locators]

8Task

A web-page with a HTML form is given [Fig. 1]

User login functionality should be tested Set value for ‘login’ field Set value for ‘password’ field Click submit button Check results

Example Task

9Explanation of practical example

URL for Login formhttp://<HOME_URL>/admin/login

User inputs correct credentials and is redirected to URL:http://<HOME_URL>/adminotherwise user is redirected back to the login form page

Explanation of example

10Template

JUnit 4 testing framework will be used

Implementation [Template]

Initial operations

Our main part of code will be here

Finally operations

11

setUp() method provides pre-test WebDriver configuration.

setUp()

setUp() method

Object for concrete browser

Set time for waiting

Visit to page specified in

URL constant

12

tearDown() method provides post-test actions (WebDriver object disposal, used resources freeing).

tearDown() method

tearDown() method

Close WebDriver and free

resources

13

Page Object pattern use.Selenium WebDriver use for low-level browser API functions only!!!

Definitions of Page Object pattern: Each single web-page is represented

through a Java class User actions for each web page are

implemented as class methods

PageObject pattern [Introduction]

Task implementation

14PageObject Pattern

PageObject Pattern

15Task’s solution

Let investigate our code for test user logon

Task Implementation

Object for HomePage where login form is

placed

Object for ResultPage

URL from address bar of browser

Comparison existing URL address with needed address

16

Class HomePage

Method for set values into HTML form and submit

data to server

17Code investigation

Code sample

18WD Low-level methods

findElement(By arg) – searches and returns an object representation of DOM element. Input parameter arg – some of possible selectors (using static methods of By class)

sendKeys(CharSequence arg) – sends char sequence to a HTML form element

click() – clicks on a DOM element

WebDriver Low level methods

19Moving between windows and frames

Web applications may have frames or multiple windows, that need to be specifically handled. WebDriver supports moving between named windows with switchTo() method:

Windows switching should be used when application has JS modal windows (alerts)

driver.switchTo().window("windowName");

Windows handling

20Moving between windows and frames

When we clicking “Вхід” button without supplying credentials an alert modal window appears [Fig.1]

In order to click ‘OK’ button WebDriver should be switched to modal window

Windows handling

21Example #2 [Code]

Let’s take a look at the code

Example #2 [Code]

Switch to JS alert window and click ‘OK’

button

22

“Main” class source

23

http://www.w3schools.com/https://developer.mozilla.org/http://docs.seleniumhq.org/

References and Sources

QUESTIONS?