hands-on guide to object identification

17
Hands-on guide to Object Identification Speaker : Dharmesh Vaya Presented On : 24.06.2016 Twitter : @DRVaya Web : http://drvaya.wordpress.com/

Upload: dharmesh-vaya

Post on 23-Jan-2018

107 views

Category:

Software


2 download

TRANSCRIPT

Page 1: Hands-on Guide to Object Identification

Hands-on guide toObject Identification

Speaker : Dharmesh VayaPresented On : 24.06.2016Twitter : @DRVayaWeb : http://drvaya.wordpress.com/

Page 2: Hands-on Guide to Object Identification

Test Automation Consultant with 10+ yrs experience

Expertise with designing/development of Selenium based Automation frameworks (as well as other tools)

Speaker at various forums - Google DevFests, Selenium Conference

Trainer/Mentor - to different MNCs/Startups.

Dharmesh Vayaa.k.a.

Dharam

Page 3: Hands-on Guide to Object Identification

Agenda

★ Basics of Object Identification

★ What are CSS Selectors/Locator’s ?

★ What are Xpath Locators ?

★ Let’s go advanced …

★ Cheat Sheet

★ Best Practices from experience

Page 4: Hands-on Guide to Object Identification

Basics ofObject Identification

Page 5: Hands-on Guide to Object Identification

Approach ...★ More than locators you need to understand the underlying

Web development techniques.

★ Carefully understand the page source and identify the libraries

used. This will help in building robust scripts.

★ Using Firebug/Developer tools.

★ Test your element even before you do it with Selenium.

(Developer toolbars are meant for that).

★ Ultimately, Locators come first, Logic is secondary and will be

built upon the locators.

Page 6: Hands-on Guide to Object Identification

What areCSS Selectors/Locator’s?

Page 7: Hands-on Guide to Object Identification

CSS Selectors...

★ Absolute SelectorsWorld -> Continent -> Country -> State -> City -> Street

★ Relative SelectorsStreet Number or House Number

★ Class or ID based Selectors

★ Finding using other attributes

★ Partial Matching

Page 8: Hands-on Guide to Object Identification

What areXpath Locator’s ?

Page 9: Hands-on Guide to Object Identification

Xpath Locators...

★ Absolute XpathWorld -> Continent -> Country -> State -> City -> Street

★ Relative XpathStreet Number or House Number

★ Index based Xpath

★ Finding using other attributes

★ Partial Matching

Page 10: Hands-on Guide to Object Identification

Let’s go advanced..

Page 11: Hands-on Guide to Object Identification

Complex Selectors

★ Partial Matching

Description CSS Xpath

Starting with ^= starts-with()

Ending with $= ends-with()

Contains *= contains()

Page 12: Hands-on Guide to Object Identification

Few more, Complex Selectors

★ Elements based on relationships

Xpath : ancestor, descendent, preceding, following

CSS: :first-child, :last-child, :nth-child(n)

★ Based on UI state

CSS: enabled, disabled, checked, :not()

Page 13: Hands-on Guide to Object Identification

Cheat Sheet

Page 14: Hands-on Guide to Object Identification

Handy Reference for CSS/XpathApproach Description/HTML CSS Xpath

Finding by ID <input id='user'> input#user //input[@id='user']

Finding by Class <input class='user'> input.user //input[@class='user']

Any attribute <input name='text'> input[name='text'] //input[@name='text']

Direct Child <ul> has several <li> ul > li //ul/li

Any Child/Grandchild <ul> has several <li> ul li //ul//li

nth-child 4th <li> from <ul> ul li:nth-of-type(4) //ul/li[4]

Direct Parent <ul> is parent of <li class='active'> li.active:parent //li[@class='active']/..

Next Sibling 2nd <li> tag from several <li> tags li.active + li //li[@class='active']/../li[2]

By Text Link with Sign In text a:contains('Sign In') //a[contains(text(), 'Sign In')]

Page 15: Hands-on Guide to Object Identification

Best Practices from Experience

Page 16: Hands-on Guide to Object Identification

Make scripts more robust...

★ Avoid fragile selectors like ones having numbers or text that

appears to be variable

★ Don’t rely on a hierarchy of elements above 3-4 levels

★ Avoid using more than 2 attributes for a composite selector

★ Ensure the selectors in all browsers using the console

★ Store Element locators outside your classes … Excel/XML/Text

anywhere but not in your code.

★ At times, you may avoid GUI automation too !!!

Page 17: Hands-on Guide to Object Identification

Happy to answer any questions/queries related to Automation testing …..

Slides will be available on -

http://drvaya.wordpress.com/