test automation & seleniun by oren rubin

Post on 03-Jul-2015

595 Views

Category:

Software

3 Downloads

Preview:

Click to see full reader

DESCRIPTION

Overview explanation on End to End Test Automation with focus UI Testing (and Selenium).

TRANSCRIPT

Test Automation & Selenium

Oren RubinCEO, Testim.io

Oren Rubin

● Why Unit Tests aren't enough?

● Writing Unit Tests !== Writing E2E Tests

● Meet Selenium

● Best practices & Design Patterns

● Selenium Grid

● UI Validations

● Record / Playback

Today's Menu

Selenium to UI-Testing is like..

Power Steering & Automatic Transmission is to Driving

I'm not making you

coffee!

Unit Tests: Same language, Easy setup. Synchronous.

// Setup Account account = new Account();

// Stimuli e.g. click, setting text, XHRaccount.login( "borg", "resistance is futile" );

// Validation assert( account.isLoggedIn(), true );

E2E vs. Unit - same same but different

E2E is

the real

SHIT!

● Synchronous?

● Same language?

● Easy setup?

○ Where are the browsers running?

○ Who's in charge of keeping them alive?

E2E is hard!

Expected: Actual:

Cowabunga

It gets worse.. I shit you not!

Cowabunga Cowabungaz-index

Cowabungasize

CowabungaThe Flying Pony

Cowabunga

Over here!

Blur, Focus, ….

CSS

HTML

JS Event

One browser.. you wish!

* What about responsive design?!

Which language do you prefer?

Test Language?

Meet Selenium

Why the name Selenium?

Selenium 1 - JS based

Selenium 2 - WebDriver & WebElements

Selenium 3 - Mobile

Past, Present, and Future

Google Trends - Same for Jobs

Example - la login

// setupWebDriver driver = new Chrome();driver.get("http://www.google.com");

// stimulidriver.findElement( By.id("user") ).sendKeys("mel brooks");driver.findElement( By.id("password") ).sendKeys("12345");driver.findElement( By.id("submit") ).submit();

// assertionassert(driver.getTitle(), "That's the kind of thing an idiot would have on his luggage!");

// tear downdriver.quit();

Example

Architecture

?Can anyone suggest a good architecture?

...

...

One (W3C) Standard to rule them all!

https://code.google.com/p/selenium/wiki/JsonWireProtocol http://www.w3.org/TR/webdriver/

HTTP as a universal language

? The WireProtocol

SDK Driver

Closer look

new Chrome(); chromedriver.exe

BrowserHTTP Request

localhost:4444/click

driver = new Chrome();...submitBtn.click();

driver

note: don't forget to frequently update chromedriver.exe

Now for Firefox

new Firefox(); webdriver.xpi

BrowserHTTP Request

localhost:4444/click

driver

driver = new Firefox();...submitBtn.click();

Let's improveloginChromeTest () { driver = new Chrome(); loginTest(driver);}

loginFirefoxTest () { driver = new Firefox(); loginTest(driver);}

loginTest (driver) { driver.findElement( By.id("user") ).sendKeys("mel brooks"); driver.findElement( By.id("password") ).sendKeys("12345"); driver.findElement( By.id("submit") ).submit();}

Page Objects

A Design Pattern.

Provides a programmatic API to drive and interrogate a UI

Best Practices & Design Patterns

http://www.slideshare.net/orenrubin/page-objects-presentation-selenium-conference-2014-38767492

// setupWebDriver driver = new Chrome();driver.get("http://www.google.com");

// stimulidriver.findElement( By.id("user") ).sendKeys("mel brooks");driver.findElement( By.id("password") ).sendKeys("12345");driver.findElement( By.id("submit") ).submit();

// assertionassert(driver.getTitle(), "That's the kind of thing an idiot would have on his luggage!");

// tear downdriver.quit();

ExampleSimon says no!

@Testvoid loginTest () {

Test Automation Architecture

Link to "Page Objects Done Right" Presentation

Selenium Grid

● Concurrency

● Multiple Platforms

Remember this?

new Chrome(); chromedriver.exe

BrowserHTTP Request

localhost:8989/click

driver = new Chrome();...submitBtn.click();

driver

What we want

new Chrome(); chromedriver.exe

BrowserHTTP Request

<some-ip>:8989/click

driver = new Chrome();...submitBtn.click();

driver

computer 1 computer 2

Selenium Grid

java -jar selenium.jar -port 4444 -role hub

selenium hub

Node 0 on 10.0

Selenium Grid

Node 1 on 10.1

Node 2 on 10.2

selenium node

java -jar selenium.jar -role webdriver -browser firefox -hubHost 10.0 –port 8989

java -jar selenium.jar -port 4444 -role hub

selenium node

java -jar selenium.jar -role webdriver -browser chrome -hubHost 10.0 –port 8989

selenium hub

Node 0 on 10.0

chromedriver.exe

firefox-webdriver.dpi

Selenium Grid

new Chrome();

BrowserHTTP Request

10.0:4444/chrome

hub = new URL("10.0:4444/wd/hub")cap = new Capabilities ("chrome", "v3", "windows")driver = new RemoteWebDriver( hub, cap );...

driver

my computer / CI server

Node 1 on 10.1

Node 2 on 10.2

selenium node

java -jar selenium.jar -role webdriver -hubHost 10.1 –port 8989

java -jar selenium.jar -port 4444 -role hub

selenium node

java -jar selenium.jar -role webdriver -hubHost 10.1 –port 8989

selenium hub

Node 0 on 10.0

HTTP Request

10.2:8989/chrome

chromedriver.exe

firefox-webdriver.dpi

Selenium Grid

new Chrome();

BrowserHTTP Request

10.0:4444/click

driver = ...

submitBtn = driver.find(By.id("submit"));submitBtn.click();

driver

my computer / CI server

Node 1 on 10.1

Node 2 on 10.2

selenium node

java -jar selenium.jar -role webdriver -hubHost 10.1 –port 8989

java -jar selenium.jar -port 4444 -role hub

selenium node

java -jar selenium.jar -role webdriver -hubHost 10.1 –port 8989

selenium hub

Node 0 on 10.0

HTTP Request

10.2:8989/click

chromedriver.exe

firefox-webdriver.dpi

Browsers in the cloudSelenium Grid as a Service

SaaS Open source

Spot the differences

UI Verification - Applitools eyeOne image is worth a 1000 assertions

Oren Rubin

Testim.io

oren@testim.io

Thank you!

top related