9

Click here to load reader

Seconf2011 - annotated lightning talk - a smattering of selenium tips

  • Upload
    zugwalt

  • View
    1.166

  • Download
    0

Embed Size (px)

DESCRIPTION

Annotated slides of the lightning talk I gave at the 2011 selenium conference. The transcript of the poem is included in boxes at the bottom of each slide. The audio/video can be seen on YouTube: http://www.youtube.com/watch?v=5HmvzaLodL0

Citation preview

Page 1: Seconf2011 -  annotated lightning talk - a smattering of selenium tips

Tips

Aaron SilvermanA Poem By

Like Patrick kindly did last evening, I want to take advantage of being on the soapbox and share some tips I found useful andthat I think will help you all out. So, borrowing from the official selenium blog title, I present you a smattering of seleniumtips: A poem about lessons learned.

YouTube Video: http://www.youtube.com/watch?v=5HmvzaLodL0 (0:10 – 3:10)

Page 2: Seconf2011 -  annotated lightning talk - a smattering of selenium tips

XPATH <

Locating elements by XPATH is one of the deadly selenium sinsIt is even worse, and slower, than using Windows MEBut if you need to traverse up and down the DOM you cannot winYou will have to use XPATH, but proceed carefully!

Page 3: Seconf2011 -  annotated lightning talk - a smattering of selenium tips

BUTTON

Complicated Page With Dynamic Content

ID = my_parent

#my_parent .orange_star

What we found works best is to use XPATH only one timeFind a useful parent element and then get or assign it an IDUse this ID to reference child nodes without the XPATH crimeYour tests will be faster and more maintainable as you will see

Page 4: Seconf2011 -  annotated lightning talk - a smattering of selenium tips

Issue Threat Level Solution

Velociraptor 3 Shotgun

XPATH 7 CSS

Delayed Flight 5 Beer

Testing Code

[[‘Velociraptor’, ‘3’, ‘Shotgun’],[‘XPATH’,’7’,’CSS’],[‘Delayed Flight’,’5’,’Beer’]]

Often we validate the contents of an entire table—which can be a lot!We found that grabbing the contents cell by cell is way too slowInstead use JavaScript injection to grab and return the contents in one shotReturning a JSON 2D array of the table contents is the way to go

Page 5: Seconf2011 -  annotated lightning talk - a smattering of selenium tips

Complicated Page With Dynamic Content

Name:

Quest:

Favorite Color:

Robert’) DROP TABLE students;--

JavaScript injection can helps in many other situations too!Like randomly filling in every input on the page as fast as lightningUsers love to break things so I think this is something you should doThe fact that somebody may be named Robbert’); Drop Table Students is quite frightening!

Page 6: Seconf2011 -  annotated lightning talk - a smattering of selenium tips

(Invisible Element)

Complicated Page With Dynamic Content

Am I visible?Of Course!

I am not a crook!

Display: none?Class: hidden?

LIAR!

Often you want to know if an element is visible, which makes senseBut visible(), like Nixon, will sometimes just lie to your faceWe use JavaScript injection to traverse the style or class attributes of parentsCombined with a regex or two, we determine visibility with grace

Page 7: Seconf2011 -  annotated lightning talk - a smattering of selenium tips

Complicated Page With Dynamic Content

Oh no!

Selenium tries its best, but in some cases like a deer in headlights it may freezeTo prevent everything from hanging we run commands in a separate threadIf the join timeout is reached, we the log the error and end the test as we pleaseAllowing our teardown to properly run, instead of the whole execution being dead

Page 8: Seconf2011 -  annotated lightning talk - a smattering of selenium tips

Testing CodeThe test did thisAnd then thisAnd then this

AbrahCadabra!

Log everything you can about each run in the database!Inputs, outputs, Log statements, and screenshots are what engineers craveYou can always delete information you no longer need, when that’s the case But only David Copperfield can produce information you did not save

Page 9: Seconf2011 -  annotated lightning talk - a smattering of selenium tips

Testing Code

Click

Click

Type

ScreenshotUpload Screenshot to DB

Validate

Click

Speaking of screenshots, they are an engineer’s best friend—they are divine!But sending them over the series of tubes can sometimes be quite slowWe found that having your test wait for them to upload is a sub-par designUse a separate thread to upload, and letting your test proceed, is the way to go