how my comic book obsession birthed a new functional testing tool

20
How My Comic Book Obsession Birthed a New Functional Testing Tool Feihong Hsu Testing in Python Birds of a Feather March 12, 2011

Upload: feihong-hsu

Post on 17-Jul-2015

196 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: How My Comic Book Obsession Birthed a New Functional Testing Tool

How My Comic Book Obsession Birthed a New Functional Testing Tool

Feihong Hsu Testing in Python Birds of a Feather

March 12, 2011

Page 2: How My Comic Book Obsession Birthed a New Functional Testing Tool

I like comics

Page 3: How My Comic Book Obsession Birthed a New Functional Testing Tool

I like studying Chinese

我喜欢学中文

我喜歡學中文

Page 4: How My Comic Book Obsession Birthed a New Functional Testing Tool

These are two tastes that go great together!

Page 5: How My Comic Book Obsession Birthed a New Functional Testing Tool

Especially when you find a real gem like this:

Page 6: How My Comic Book Obsession Birthed a New Functional Testing Tool

Problem: Chinese comics portals load slowly and have poor usability Solution: Write a web scraping tool to batch download images, so I canbe a proper Apple fanboy and read comics on my iPad

Page 7: How My Comic Book Obsession Birthed a New Functional Testing Tool

First approach: urllib2 + lxml.html

Verdict: Total fail, couldn't handle JavaScript and cookies

Page 8: How My Comic Book Obsession Birthed a New Functional Testing Tool

Second approach: XULRunner

Verdict: Asynchronous logic was painful, Python integration would not have been trivial

Page 9: How My Comic Book Obsession Birthed a New Functional Testing Tool

Third approach: spynner

Verdict: Not bad! But... some sites don't load. Why?

Page 10: How My Comic Book Obsession Birthed a New Functional Testing Tool

Fourth approach: Make spynner dumber

Verdict: Frickin' awesome

Page 11: How My Comic Book Obsession Birthed a New Functional Testing Tool

Coincidence: At Leapfrog, we needed a better way to test JavaScriptbehavior on our sites

Result: Leapfrog subsidizes my comic book addiction

Page 12: How My Comic Book Obsession Birthed a New Functional Testing Tool

Over time, we added some nice stuff to our spynner fork

- Ability to ignore SSL errors- Form manipulation methods- Screen capture (consistently-sized images)- Other stuff that I can't remember

Page 13: How My Comic Book Obsession Birthed a New Functional Testing Tool

Question: Hey Feihong, where can I get this sexy library?

Answer: Nowhere, I'm too busy reading comics to open source it

Page 14: How My Comic Book Obsession Birthed a New Functional Testing Tool

Real answer: We're working on open sourcing it, but we ran into some blocks

(Cast sidelong glance at Terry)

Page 15: How My Comic Book Obsession Birthed a New Functional Testing Tool

However, we are NOT soliciting suggestions for a

name. We have thePERFECT name already.

Page 16: How My Comic Book Obsession Birthed a New Functional Testing Tool

PunkyBrowster

Page 17: How My Comic Book Obsession Birthed a New Functional Testing Tool

Some basic usage

Page 18: How My Comic Book Obsession Birthed a New Functional Testing Tool

from punky import Browster browser = Browster(auto_load_images=True)browser.create_webview(show=True) browser.load('http://www.duckduckgo.com/') browser.fill('input#hfih', 'How do I de-pube-ify waterless urinals?')browser.submit('form#hfh', wait_load=True) for element in browser.all('#r12 > div'): print unicode(element.toPlainText())

Page 19: How My Comic Book Obsession Birthed a New Functional Testing Tool

Random note: I never want to have the need to see a urologist. But if Ido, I hope he's

wearing a badge like this:

Page 20: How My Comic Book Obsession Birthed a New Functional Testing Tool

I am done