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

  • View
    1.902

  • Download
    0

  • Category

    Software

Preview:

Citation preview

Selenium WorkshopSelenium Workshop

By Atirek GuptaBy Atirek Gupta

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

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

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).

HTML DOM Tree of ObjectsHTML DOM Tree of Objects

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.

Understanding same origin Understanding same origin policy policy

How Selenium RC How Selenium RC worksworks

How How WebDriver WebDriver

worksworks

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

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)

How Browser WorksHow Browser Works

LocatorsLocators

CSS

XPath

More about Selenium-More about Selenium-WebDriverWebDriver

How does WebDriver know if the page is completely loaded?

When document.readyState is “complete”

More about Selenium-More about Selenium-WebDriverWebDriver

What is StaleElementReferenceException

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

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);

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

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

Reference -

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

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?

Components of frameworkComponents of framework

Let’s codeLet’s code

Thank YouThank You

Atirek Gupta

atirekg@gmail.com, agupta@thoughtworks.com

Recommended