Selenium WebDriver
-
Upload
yuriy-bezgachnyuk -
Category
Internet
-
view
177 -
download
1
description
Transcript of Selenium WebDriver
![Page 1: Selenium WebDriver](https://reader033.fdocuments.in/reader033/viewer/2022061122/547069ffaf7959a41e8b48cf/html5/thumbnails/1.jpg)
SELENIUM WEBDRIVER
Yuriy Bezgachnyuk, SSU/ITAOctober, 2014
![Page 2: Selenium WebDriver](https://reader033.fdocuments.in/reader033/viewer/2022061122/547069ffaf7959a41e8b48cf/html5/thumbnails/2.jpg)
2
Test automationWhat is Selenium WebDriverSelenium WD FeaturesDocument Object Model (DOM)
LocatorsExample task
PageObject pattern introduction
Agenda
![Page 3: Selenium WebDriver](https://reader033.fdocuments.in/reader033/viewer/2022061122/547069ffaf7959a41e8b48cf/html5/thumbnails/3.jpg)
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
![Page 4: Selenium WebDriver](https://reader033.fdocuments.in/reader033/viewer/2022061122/547069ffaf7959a41e8b48cf/html5/thumbnails/4.jpg)
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
![Page 5: Selenium WebDriver](https://reader033.fdocuments.in/reader033/viewer/2022061122/547069ffaf7959a41e8b48cf/html5/thumbnails/5.jpg)
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
![Page 6: Selenium WebDriver](https://reader033.fdocuments.in/reader033/viewer/2022061122/547069ffaf7959a41e8b48cf/html5/thumbnails/6.jpg)
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)
![Page 7: Selenium WebDriver](https://reader033.fdocuments.in/reader033/viewer/2022061122/547069ffaf7959a41e8b48cf/html5/thumbnails/7.jpg)
7DOM [Locators]
Select any HTML element(s) from DOM by using tags name attributes of tags
• id, name, … CSS selectors XPath
DOM [Locators]
![Page 8: Selenium WebDriver](https://reader033.fdocuments.in/reader033/viewer/2022061122/547069ffaf7959a41e8b48cf/html5/thumbnails/8.jpg)
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
![Page 9: Selenium WebDriver](https://reader033.fdocuments.in/reader033/viewer/2022061122/547069ffaf7959a41e8b48cf/html5/thumbnails/9.jpg)
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
![Page 10: Selenium WebDriver](https://reader033.fdocuments.in/reader033/viewer/2022061122/547069ffaf7959a41e8b48cf/html5/thumbnails/10.jpg)
10Template
JUnit 4 testing framework will be used
Implementation [Template]
Initial operations
Our main part of code will be here
Finally operations
![Page 11: Selenium WebDriver](https://reader033.fdocuments.in/reader033/viewer/2022061122/547069ffaf7959a41e8b48cf/html5/thumbnails/11.jpg)
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
![Page 12: Selenium WebDriver](https://reader033.fdocuments.in/reader033/viewer/2022061122/547069ffaf7959a41e8b48cf/html5/thumbnails/12.jpg)
12
tearDown() method provides post-test actions (WebDriver object disposal, used resources freeing).
tearDown() method
tearDown() method
Close WebDriver and free
resources
![Page 13: Selenium WebDriver](https://reader033.fdocuments.in/reader033/viewer/2022061122/547069ffaf7959a41e8b48cf/html5/thumbnails/13.jpg)
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
![Page 14: Selenium WebDriver](https://reader033.fdocuments.in/reader033/viewer/2022061122/547069ffaf7959a41e8b48cf/html5/thumbnails/14.jpg)
14PageObject Pattern
PageObject Pattern
![Page 15: Selenium WebDriver](https://reader033.fdocuments.in/reader033/viewer/2022061122/547069ffaf7959a41e8b48cf/html5/thumbnails/15.jpg)
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
![Page 16: Selenium WebDriver](https://reader033.fdocuments.in/reader033/viewer/2022061122/547069ffaf7959a41e8b48cf/html5/thumbnails/16.jpg)
16
Class HomePage
Method for set values into HTML form and submit
data to server
![Page 17: Selenium WebDriver](https://reader033.fdocuments.in/reader033/viewer/2022061122/547069ffaf7959a41e8b48cf/html5/thumbnails/17.jpg)
17Code investigation
Code sample
![Page 18: Selenium WebDriver](https://reader033.fdocuments.in/reader033/viewer/2022061122/547069ffaf7959a41e8b48cf/html5/thumbnails/18.jpg)
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
![Page 19: Selenium WebDriver](https://reader033.fdocuments.in/reader033/viewer/2022061122/547069ffaf7959a41e8b48cf/html5/thumbnails/19.jpg)
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
![Page 20: Selenium WebDriver](https://reader033.fdocuments.in/reader033/viewer/2022061122/547069ffaf7959a41e8b48cf/html5/thumbnails/20.jpg)
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
![Page 21: Selenium WebDriver](https://reader033.fdocuments.in/reader033/viewer/2022061122/547069ffaf7959a41e8b48cf/html5/thumbnails/21.jpg)
21Example #2 [Code]
Let’s take a look at the code
Example #2 [Code]
Switch to JS alert window and click ‘OK’
button
![Page 22: Selenium WebDriver](https://reader033.fdocuments.in/reader033/viewer/2022061122/547069ffaf7959a41e8b48cf/html5/thumbnails/22.jpg)
22
“Main” class source
![Page 23: Selenium WebDriver](https://reader033.fdocuments.in/reader033/viewer/2022061122/547069ffaf7959a41e8b48cf/html5/thumbnails/23.jpg)
23
http://www.w3schools.com/https://developer.mozilla.org/http://docs.seleniumhq.org/
References and Sources
![Page 24: Selenium WebDriver](https://reader033.fdocuments.in/reader033/viewer/2022061122/547069ffaf7959a41e8b48cf/html5/thumbnails/24.jpg)
QUESTIONS?