62
Selenium 2 Jason Huggins Co-creator, The Selenium Project Co-founder, CTO, Sauce Labs Inc twitter: @hugs email: [email protected]

Selenium 2 - PyCon 2011

  • Upload
    hugs

  • View
    110

  • Download
    1

Embed Size (px)

DESCRIPTION

Jason Huggins presents Selenium 2 at PyCon 2011 in Atlanta on 12 March 2011

Citation preview

Page 1: Selenium 2 - PyCon 2011

Selenium 2Jason Huggins

Co-creator, The Selenium ProjectCo-founder, CTO, Sauce Labs Inc

twitter: @hugsemail: [email protected]

Page 2: Selenium 2 - PyCon 2011

Follow me on Twitter:

@hugs

Page 3: Selenium 2 - PyCon 2011

Get Library from PyPI

$ pip install -U selenium

Page 4: Selenium 2 - PyCon 2011

Agenda

• Overview of Selenium

• Selenium IDE, Builder (new!), RC, Grid

• Why: Selenium 2

• What: Selenium 2

• Demos!

Page 5: Selenium 2 - PyCon 2011

+ =

What is Selenium?

Page 6: Selenium 2 - PyCon 2011

The Problem

Page 7: Selenium 2 - PyCon 2011

Selenium IDE for Firefox

Page 8: Selenium 2 - PyCon 2011

Builder (new!)

Page 9: Selenium 2 - PyCon 2011

9

!"#$%"&'$(%)$*

+%%,-..///01*234)03$#.,+$%$5.23"6$(".789:;8<=:

Page 10: Selenium 2 - PyCon 2011

Python, Ruby, Java, C#, or Perl

Test ScriptHTTP

Your AwesomeWeb App

Selenium RC Server

HTTP HTTP

Selenium Remote Control

Page 11: Selenium 2 - PyCon 2011

Example Selenium RC Test - Java

Page 12: Selenium 2 - PyCon 2011

Example Selenium RC Test - C#

Page 13: Selenium 2 - PyCon 2011

!"#$

%&&'())***+,-#./"+.01)'%0&02)$345)67879:;)

Selenium Grid

Page 14: Selenium 2 - PyCon 2011

Time

Servers

Unit of Work

Page 15: Selenium 2 - PyCon 2011

Time

Servers

Unit of Work

Page 16: Selenium 2 - PyCon 2011

Selenium 2: Why and What

Page 17: Selenium 2 - PyCon 2011

Mobile

Page 18: Selenium 2 - PyCon 2011

Types of Mobile Testing

• Emulator

• Real device (tethered to workstation)

• Real device in a real location on a real network

Page 19: Selenium 2 - PyCon 2011

Native vs Web

Page 20: Selenium 2 - PyCon 2011

Life before the Web

Total Application Market

Page 21: Selenium 2 - PyCon 2011

Total Application Market

JS+HTML

Yesterday

Page 22: Selenium 2 - PyCon 2011

Total Application Market

JS+HTML5

Today

Page 23: Selenium 2 - PyCon 2011

Data?

Page 24: Selenium 2 - PyCon 2011
Page 25: Selenium 2 - PyCon 2011

Sencha

Page 26: Selenium 2 - PyCon 2011

SproutCore

Page 27: Selenium 2 - PyCon 2011

PhoneGap

Page 28: Selenium 2 - PyCon 2011

Total Application Market

JS+HTML5

TodaySelenium lives here!

Page 29: Selenium 2 - PyCon 2011
Page 30: Selenium 2 - PyCon 2011

Total Application Market

JS+HTML5

TodaySelenium lives here!

Page 31: Selenium 2 - PyCon 2011

Total Application Market

JS+HTML5

TomorrowSelenium lives here!

Page 32: Selenium 2 - PyCon 2011

The Pareto Principle

Page 33: Selenium 2 - PyCon 2011

AKA (“The Pacman Problem”)

Selenium 1

Selenium 2

Page 34: Selenium 2 - PyCon 2011

• Native keyboard & mouse events• Same Origin Policy / XSS / HTTP(S)• Pop-ups, dialogs

– Basic Authentication– Self-signed certi!cates– File upload/download

Solving the last 20%

Page 35: Selenium 2 - PyCon 2011
Page 36: Selenium 2 - PyCon 2011

• WebDriver Object

• WebElement Objects

Cleaner API

Page 37: Selenium 2 - PyCon 2011

• Improved architecture• Removing road-blocks, hacks, and workarounds• Scales down (more developer friendly) experience

Other Bene!ts

Page 38: Selenium 2 - PyCon 2011

Python, Ruby, Java, C#, or Perl

Test ScriptHTTP

Your AwesomeWeb App

Selenium RC Server

HTTP HTTP

Selenium Remote Control

Page 39: Selenium 2 - PyCon 2011

Python, Ruby, Java, C#, or Perl

Test ScriptHTTP

Your AwesomeWeb App

Selenium RC Server

HTTP HTTP

Selenium 2

Page 40: Selenium 2 - PyCon 2011

Python, Ruby, Java, C#, or Perl

Test Script

Your AwesomeWeb App

HTTP HTTP

Page 41: Selenium 2 - PyCon 2011

Python, Ruby, Java, C#, or Perl

Test Script

Your AwesomeWeb App

C/C++ HTTP

Page 42: Selenium 2 - PyCon 2011

Running a server is now optional!

Python, Ruby, Java, C#, or Perl

Test ScriptHTTP

Your AwesomeWeb App

Selenium Grid

HTTP HTTP

Page 43: Selenium 2 - PyCon 2011

Mobile - How?

Page 44: Selenium 2 - PyCon 2011

Checkout Selenium

Page 45: Selenium 2 - PyCon 2011

Android

Page 46: Selenium 2 - PyCon 2011

Download Android SDK

Page 47: Selenium 2 - PyCon 2011

Unpack

~/android_sdk

Page 48: Selenium 2 - PyCon 2011

Update

$ cd ~/android_sdk/tools$ ./android update sdk

Page 49: Selenium 2 - PyCon 2011

Create AVD

$ ./android create avd \ -n my_android \ -t 8 \ -c 100M

Page 50: Selenium 2 - PyCon 2011

Start Emulator

$ ./emulator -avd my_android \ -no-audio \ -no-boot-anim \ -scale .8 &

Page 51: Selenium 2 - PyCon 2011

Install Selenium APK

$ cd ~/android_sdk/platform-tools/$ ./adb -e install \ -r ~/selenium/android/prebuilt/android-server.apk

Page 52: Selenium 2 - PyCon 2011

Port Forwarding

$ ./adb forward tcp:8080 tcp:8080

Page 53: Selenium 2 - PyCon 2011

(One More Step)

Launch WebDriver App

Page 54: Selenium 2 - PyCon 2011

iPhone

Page 55: Selenium 2 - PyCon 2011

Open in XCode

$ open ~/selenium/iphone/iWebDriver.xcodeproj/

Page 56: Selenium 2 - PyCon 2011

Build & Run

Page 57: Selenium 2 - PyCon 2011

Demo!

Page 58: Selenium 2 - PyCon 2011

The Code:# Import the Selenium 2 namespace (aka "webdriver")from selenium import webdriver

# Run one of the four following commands:

# iPhonedriver = webdriver.Remote(browser_name="iphone", command_executor='http://172.24.101.36:3001/hub')

# Androiddriver = webdriver.Remote(browser_name="android", command_executor='http://127.0.0.1:8080/hub')

# Google Chrome driver = webdriver.Chrome()

# Firefox driver = webdriver.Firefox()

Page 59: Selenium 2 - PyCon 2011

The Code:# The actual test scenario: Test the codepad.org code execution service.

# Go to codepad.orgdriver.get('http://codepad.org')

# Select the Python language optionpython_link = driver.find_elements_by_xpath("//input[@name='lang' and @value='Python']")[0]python_link.click()

# Enter some text!text_area = driver.find_element_by_id('textarea')text_area.send_keys("print 'Hello,' + ' World!'")

# Submit the form!submit_button = driver.find_element_by_name('submit')submit_button.click()

# Make this an actual test. Isn't Python beautiful?assert "Hello, World!" in driver.get_page_source()

# Close the browser!driver.quit()

Page 60: Selenium 2 - PyCon 2011

Selenium 2 - The Moviehttp://www.youtube.com/watch?v=IUUcEIfkOEY

Page 61: Selenium 2 - PyCon 2011

LinksFor More Information:✓http://seleniumhq.org

✓http://code.google.com/p/selenium

✓http://code.google.com/p/se-builder/

✓http://saucelabs.com/docs/selenium2

✓http://twitter.com/hugs

Slides:✓http://www.slideshare.net/hugs/se2pycon

Demo Screencast:✓http://www.youtube.com/watch?v=IUUcEIfkOEY

Code:✓http://gist.github.com/830011

Page 62: Selenium 2 - PyCon 2011

Thanks!Jason Huggins

Co-creator, The Selenium ProjectCo-founder, CTO, Sauce Labs Inc

twitter: @hugsemail: [email protected]