22
Selenium Workshop Selenium Workshop By Atirek Gupta By Atirek Gupta

Understanding Selenium/RC, Webdriver Architecture and developing the page object test automation framework

Embed Size (px)

Citation preview

Page 1: Understanding Selenium/RC, Webdriver Architecture and developing the page object test automation framework

Selenium WorkshopSelenium Workshop

By Atirek GuptaBy Atirek Gupta

Page 2: Understanding Selenium/RC, Webdriver Architecture and developing the page object test automation framework

Out of scopeOut of scope

When and why to do functional test automation.

Test specification.

Test data management.

Detailed architecture of Browser.

Going deeper into Java Script

Build tools, CI and VCS

Page 3: Understanding Selenium/RC, Webdriver Architecture and developing the page object test automation framework

AgendaAgenda

Origin of Selenium

Understanding same origin policy

Interacting with HTML using JavaScript

How Selenium-RC and WebDriver works

Locators

More about Selenium and WebDriver

Overview of how browser works

Exploring WebDriver API’s with examples

Building test automation framework using Java and WebDriver

Page 4: Understanding Selenium/RC, Webdriver Architecture and developing the page object test automation framework

Origin of SeleniumOrigin of Selenium

Selenium first came to life in 2004.

Selenium was written in pure JavaScript.

These scripts are injected into the web page, thus simulating user activity.

Limitations due to browser security policy called SOP(Same origin policy).

Page 5: Understanding Selenium/RC, Webdriver Architecture and developing the page object test automation framework

HTML DOM Tree of ObjectsHTML DOM Tree of Objects

Page 6: Understanding Selenium/RC, Webdriver Architecture and developing the page object test automation framework

Interacting with HTML using Interacting with HTML using JavaScriptJavaScript

JavaScript is a scripting language designed primarily for adding interactivity to Web pages.

Some JavaScript methods and interaction with browser e.g. document.getElementById(“id”).innerHtml =

“Some text” document.getElementById(“id”).click

Let’s do some hands on.

Page 7: Understanding Selenium/RC, Webdriver Architecture and developing the page object test automation framework

Understanding same origin Understanding same origin policy policy

Page 8: Understanding Selenium/RC, Webdriver Architecture and developing the page object test automation framework

How Selenium RC How Selenium RC worksworks

Page 9: Understanding Selenium/RC, Webdriver Architecture and developing the page object test automation framework

How How WebDriver WebDriver

worksworks

• It uses the browser’s native support for automation (different for each browser)

Page 10: Understanding Selenium/RC, Webdriver Architecture and developing the page object test automation framework

Browser SupportBrowser Support

Selenium-WebDriver supports the following browsers along with the operating systems these browsers are compatible with.

Google Chrome

Internet Explorer 6, 7, 8, 9, 10 - 32 and 64-bit where applicable

Firefox: latest ESR, previous ESR, current release, one previous release

Safari,Opera

HtmlUnit, Phantomjs

Android (with Selendroid or appium), iOS (with ios-driver or appium)

Page 11: Understanding Selenium/RC, Webdriver Architecture and developing the page object test automation framework

How Browser WorksHow Browser Works

Page 12: Understanding Selenium/RC, Webdriver Architecture and developing the page object test automation framework

LocatorsLocators

CSS

XPath

Page 13: Understanding Selenium/RC, Webdriver Architecture and developing the page object test automation framework

More about Selenium-More about Selenium-WebDriverWebDriver

How does WebDriver know if the page is completely loaded?

When document.readyState is “complete”

Page 14: Understanding Selenium/RC, Webdriver Architecture and developing the page object test automation framework

More about Selenium-More about Selenium-WebDriverWebDriver

What is StaleElementReferenceException

What causes them? Page Refresh JavaScript MVC frameworks Elements being re-rendered

Page 15: Understanding Selenium/RC, Webdriver Architecture and developing the page object test automation framework

More about Selenium-More about Selenium-WebDriverWebDriver

Can WebDriver execute javascript commands on DOM?

WebElement element = driver.findElement(By.id("gbqfd"));

JavascriptExecutor executor = (JavascriptExecutor)driver;

executor.executeScript("arguments[0].click();", element);

Page 16: Understanding Selenium/RC, Webdriver Architecture and developing the page object test automation framework

More about Selenium-More about Selenium-WebDriverWebDriver

Handling : Explicit and Implicit Waits.

driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS)

driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);

WebElement element = (new WebDriverWait(driver,10))

.until(ExpectedConditions.elementToBeClickable(By.Id(“id”))).click

Page 17: Understanding Selenium/RC, Webdriver Architecture and developing the page object test automation framework

Hands on with Hands on with WebDriver API’sWebDriver API’s

Reference -

http://selenium.googlecode.com/git/docs/api/java/index.html

Page 18: Understanding Selenium/RC, Webdriver Architecture and developing the page object test automation framework

Key principle for designing / Key principle for designing / building an Automation building an Automation

Framework?Framework?

Readable

Re-Usable

Maintainable

Well Abstracted

Scalable

Browser support?

Tests to be run in distributed environment or on one machine?

Page 19: Understanding Selenium/RC, Webdriver Architecture and developing the page object test automation framework

Components of frameworkComponents of framework

Page 20: Understanding Selenium/RC, Webdriver Architecture and developing the page object test automation framework

Let’s codeLet’s code

Page 21: Understanding Selenium/RC, Webdriver Architecture and developing the page object test automation framework
Page 22: Understanding Selenium/RC, Webdriver Architecture and developing the page object test automation framework

Thank YouThank You

Atirek Gupta

[email protected], [email protected]