WebDriverJS Session in Selenium Conf

41
WebDriver and Cucumber in the JavaScript Land Surya Sreedevi Vedula Ramalingam Sangarasubramanian

description

The slide deck is from a demo presented in SeConf2014.

Transcript of WebDriverJS Session in Selenium Conf

Page 1: WebDriverJS Session in Selenium Conf

WebDriver and Cucumber in the JavaScript Land

Surya Sreedevi VedulaRamalingam Sangarasubramanian

Page 2: WebDriverJS Session in Selenium Conf

About

• Software Testing for 10 Years• Test Frameworks in Java, Python, Ruby and

JavaScript• Associated with Selenium since Selenium 1.0

and RC days• Twitter : @suryasreevedula

Page 3: WebDriverJS Session in Selenium Conf

Agenda

• What is WebDriverJS?• How is it different from other bindings?• Demo a framework using WebDriverJS• Demo a framework using Protractor• Continuous Integration and Test Reports

Page 4: WebDriverJS Session in Selenium Conf

Before we get started…

Page 5: WebDriverJS Session in Selenium Conf

Language Bindings for WebDriver in JavaScript

What is WebDriverJS?

Page 6: WebDriverJS Session in Selenium Conf

SELENIUM

SERVER

CHROMEDRIVER

FIREFOXDRIVER

JAVA

C# RUBY

JAVASCRIPT (JS) IE DRIVER

Language Bindings

Browser Drivers

Page 7: WebDriverJS Session in Selenium Conf

WebDriverJS

• NPM module selenium-webdriver

Page 8: WebDriverJS Session in Selenium Conf

Why WebDriverJS?

Page 9: WebDriverJS Session in Selenium Conf

• WebDriverJS for testing JS front-end apps– Leverages the app environment setup– Leverages the build and CI processes– Use Common Mock and Test Services across

different layers of tests– Helps use common IDE tools– Better collaboration with the developers– Easier for any one in the team to maintain tests

Page 10: WebDriverJS Session in Selenium Conf

How is it different?

Page 11: WebDriverJS Session in Selenium Conf

SELENIUM

SERVER

CHROMEDRIVER

FIREFOXDRIVER

JAVA

SYNC

C# RUBY

JAVASCRIPT (JS) IE DRIVER

Language Bindings

SYNC SYNC

ASYNC

Browser Drivers

Page 12: WebDriverJS Session in Selenium Conf

What is “Asynchronous” Language Binding?

Page 13: WebDriverJS Session in Selenium Conf

ASynchronous

quick_call();

ti me_consuming_call();

i_wont_wait();

DOES NOT wait for ti me_consuming_call() to COMPLETE

Synchronous

quick_call();

ti me_consuming_call();

i_have_to_wait();

WAITS for ti me_consuming_call() to COMPLETE

Page 14: WebDriverJS Session in Selenium Conf

Asynchronous WebDriverJS

• JS is Asynchronous• Node.js centered around JS’s asynchrony• WebDriverJS is a Node.js Application

Page 15: WebDriverJS Session in Selenium Conf

Getting Started with WebDriverJS

• Create a npm project$ npm init

• Install WebDriverJS$ npm install selenium-webdriver

• Install mocha$ npm install mocha

• Write Spec• Run Spec

$ node_modules/mocha/bin/mocha spec/

Page 16: WebDriverJS Session in Selenium Conf

Our First Test

Page 17: WebDriverJS Session in Selenium Conf

A Detour into Asynchronous JavaScript

Page 18: WebDriverJS Session in Selenium Conf

Asynchronous JavaScript

• Asynchronous functions CANNOT– Return values to the current execution context– Throw errors to the current execution context

Page 19: WebDriverJS Session in Selenium Conf

Promises

• Promises are a software abstraction that makes working with asynchronous operations easy.

• Promises– Return Values.– Propagate errors.

Page 20: WebDriverJS Session in Selenium Conf

Promises

• A promise is defined as an object that has a function as the value for the property then

promise.then(fulfillHandler, errorHandler);

Page 21: WebDriverJS Session in Selenium Conf

Let’s Complete the First Test

Page 22: WebDriverJS Session in Selenium Conf

WebDriverJS – A Quick View

Page 23: WebDriverJS Session in Selenium Conf

Major Components

• webdriver.WebDriver• webdriver.WebElement• webdriver.By• webdriver.Options

Page 24: WebDriverJS Session in Selenium Conf

webdriver.WebDriver

• Manages Browser– get, quit, close, executeScript, getTitle, getCurrentUrl

• Element Finder Functions– findElement, findElements, isElementPresent

• Helper functions– sleep, wait, takeScreenshot

• Gateway to other WebDriver API– manage() helps manage Options interface

Page 25: WebDriverJS Session in Selenium Conf

webdriver.WebElement

• Provides UI Actions– click, sendKeys, isDisplayed, isSelected,

getAttribute, getText, clear

• Nested Element Finder Functions– findElement, findElements, isElementPresent

Page 26: WebDriverJS Session in Selenium Conf

webdriver.By

Provides locator strategies1. webdriver.By.id2. webdriver.By.css3. webdriver.By.className4. webdriver.By.linkText5. webdriver.By.js6. webdriver.By.name7. webdriver.By.xpath8. webdriver.By.tagName

Page 27: WebDriverJS Session in Selenium Conf

webdriver.Options

• Accessible via driver.manage() • Manage Timeouts– implicitlyWait, pageLoadTimeOut

• Manage Current Window– maximize, getPosition

• Manage Cookies– addCookie, deleteCookie

Page 28: WebDriverJS Session in Selenium Conf

A Special Mention…

Page 29: WebDriverJS Session in Selenium Conf

webdriver.Promise.ControlFlow

• Responsible for queuing webdriver.promise.Promise calls.

driver.get("http://localhost:8082/community-app"); var element = driver.findElement(webdriver.By.id("uid")); element.sendKeys("mifos"); var value = element.getAttribute("value"); value.then(function(value) {

assert.equal(value, "mifos"); });

Page 30: WebDriverJS Session in Selenium Conf

Framework Using WebDriverJS

Page 31: WebDriverJS Session in Selenium Conf

JS Concepts to note…

• Object Inheritance and not class inheritance– prototypal inheritance

• Module Imports – using Node.js CommonJS

• IIFE Blocks– Avoid Global Namespace

Page 32: WebDriverJS Session in Selenium Conf

Framework Components

• Pages– BasePage– Page Inheritance

• Specs– Using Mocha

• Config Files– DriverConfig– AppConfig

• Test Data– LoginData

Page 33: WebDriverJS Session in Selenium Conf

Code Walk-through

Page 34: WebDriverJS Session in Selenium Conf

Protractor

• Framework to test Angular JS Applications.• Provides Angular JS Locators• waitForAngular• webdriver-manager• Cross Browser Testing using Selenium Grid• Multiple Test Framework Support

Page 35: WebDriverJS Session in Selenium Conf

Setting Up Protractor

• npm install protractor

Page 36: WebDriverJS Session in Selenium Conf

Leverage Protractor

• Use browser, by global functions• Use element for UI elements.• Leverage element function for getters• Remove waitForLoad and waitForElement

methods• Remove DriverConfig as it is handled by conf file• Leverage Angular JS Locators, by.• Use Jasmine Framework for the Specs

Page 37: WebDriverJS Session in Selenium Conf

CI and Test Reports

Page 38: WebDriverJS Session in Selenium Conf

Repos

• Framework– https://github.com/sreedevivedula/wdjs_fw/

• First Test Repo– https://github.com/sreedevivedula/wdjs_first_test

• JsAsync– https://github.com/sreedevivedula/jsasync

Page 39: WebDriverJS Session in Selenium Conf

References

• WebDriverJS– http://code.google.com/p/selenium/wiki/WebDriv

erJs• You are missing the point of promises– http://domenic.me/2012/10/14/youre-missing-th

e-point-of-promises

Page 40: WebDriverJS Session in Selenium Conf

Questions