Post on 11-Jan-2017
Object Spy, Visual Analysis and XML/XpathIntro and Demo for Partners
David BroermanPartner Enablement ManagerPhone: 727. 225.2826 / Email: davidb@perfectomobile.com
Agenda
• Basics around XML and Xpath• What are XML and Xpath?• Working with XML and Xpath• Object Analysis and the Perfecto Object Spy
• Visual Analysis• Quick Demo• Open Perfecto Automation• Discuss Object Spy , Visual and Xpath
• Open existing Perfecto Lab Selenium Project in Eclipse• Discuss Object Spy , Visual and Xpath
What are XML and Xpath?
• XML • EXtensible Markup Language• XML enables you to create data that can read by any application on any
platform• Native Object analysis relies on XML• The Object Tree is an XML document
• Xpath (XML Path Language)• XPath is the query language for XML documents
• Describes a way to locate and process items in XML documents• In automation, Xpath allows us to identify the object/objects
Importance of Understanding XML and XPath
4
• Native Object analysis relies on XML • Retrieves the XML document and analyzes it • However, it this is not enough to identify the object using its location in the
object tree. This approach is fragile.• It is necessary to use specific XPath expressions to uniquely identify the object. • This will enable your object to be found across multiple platforms and
devices.
5
Native Objects Analysis
• The Object Tree is an XML document
• The way to find elements inside XML is through XPath
• To properly work with Objects, a good grasp of XML/XPath is needed.
The Perfecto Approach for Mobile Objects
Native Object Analysis
and
Visual Object Analysis = HYBRID APPROACH!
Best Practice: Use Native Object Analysis for Navigating and Visual/OCR for Validation.
ProsCons
The Object Spy enables working with objects
• The Object Spy accesses the XML of the application
• Identifies the element and writes an XPath Expression.• May need to export the XML into Firebug/FirePath.• Inserts the expression back into the Object Spy.• Applies the required action:
• Click – click on the element• Set – an edit field with a value• Info – to retrieve an element to receive its properties• Find – find an element
Website & Apps – Object Trees/Identifying Objects• Web Objects
• DOM• Same Tree (PM or Appium
Framework)
• Native App Objects• PM or Appium framework• Appium -Separate naming for
Android and iOS• Perfecto – Script Once
• Hybrid Application• PM automation framework• Mix of Native and DOM objects
DOM Perfecto Mobile
Appium
Working with the Object Spy
Selected Automation Function and Parameter fields
Object XPath
Object TreePreview Panel
Search and
Export
Filter displayed Objects
Object Properties
Automation functions
associated with the selected
object type
Adding Commands from the Object Spy
11
Working with Firebug and FirePath
Object Spy: Object Locator Available – Release 8.6
• Object Locator is now available for Native, Web and Hybrid apps.• Easily generate
accurate XPath identifiers from within the Perfecto Object Spy • Don’t have to
export to XML and use tools such as FireBug and FirePath.
Visual Analysis
• Visual analysis is an alternative way of interacting with a device. • Its’ source is the screenshot taken from the device (what the user sees).
• Perfecto can analyze the screenshot looking for either text or images, with text being the recommended option.
Best Practice: Use Native Object Analysis for Navigating and Visual for Validation.
Visual - Available Commands• Select - Clicks on the image/text
• Find – Finds an image/text for visual relationship
• Check – A Checkpoint that validates the text/image appears on the screen• (Sync is same command , Sync has a default timeout of 60 seconds and check does not)
• Button – Clicks a Button
• Edit - Sets a value inside an input field
05/01/2023 14© 2015, Perfecto Mobile Ltd. All Rights Reserved.
Example - Coding Visual Analysis – Java
• Visual Analysis – Perfecto Proprietary command executed using RemoteWebDriver• Use the
executeScript method• The script
parameter contains the command name, in the following format: mobile:command:subcommand.
05/01/2023 15© 2015, Perfecto Mobile Ltd. All Rights Reserved.
Map<String, Object> params3 = new HashMap<>();// Check for the text that indicates that the sign in was successfulparams3.put("content", "Welcome back John");// allow up-to 30 seconds for the page to displayparams3.put("timeout", "30");resultString = (String) driver.executeScript("mobile:checkpoint:text", params3);if (!resultString.equalsIgnoreCase("true")) {System.out.println("'Welcome back John' text not found");}
Did You Know?
•When talking with users of the Perfecto Solution• Approximately 90% of testing defects are found using Visual
Validation!• Mobile is different as we want to understand the UX• Need to see what the user sees• An object on the screen may be found, but it may be hidden behind
something else (need visual validation).
XPath Examples
Example of Power of Xpath with Objects
18
Let's say that we want to work on a username field.
Remember:· The default path generated by the Object Spy refers to its location; its placement on the page.· The placement of that object can change, or be slightly different in another platform
(i.e. tablet vs. smartphone).· So, it's important to refer to it by its logical function instead of an arbitrary placement on the
page.
XPath will allow this to be specified: //[@username]· This expression explicitly refers to the input field called 'username'.
Advantages: It is easy to read. It is likely to work well with minimal maintenance. It is likely to be identical across devices and platforms.
19
XPath Expression Syntax
Expression Description
nodename Selects all nodes with the name "nodename"
// Selects nodes in the document from the current node that match the selection no matter where they are
//vehicle Selects all vehicle elements no matter where they are in the document
//@make Selects all attributes named make
//*[@make="Toyota"] Select all attributes named make with value of Toyota
//vehicle[@*] Selects all vehicle elements which have any attribute
//*[text()=’Corolla’] Select all objects with the text Corolla
//vehicle[2] Select the second vehicle element
Demo• Open Perfecto Automation and also Open existing Perfecto Lab Selenium
Project in Eclipse• Discuss Object Spy , Visual Analysis and Xpath
Resources• Sample script and Demo Apps• https://community.perfectomobile.com/series/25427/posts/1064930
• Working with Object Spy and XPath• https://community.perfectomobile.com/posts/914140-web-objects
• XPath Tutorial• http://www.w3schools.com/XPath/
• XML Tutorial• http://www.w3schools.com/xml/
Thank You
David BroermanPartner Enablement ManagerPhone: 727. 225.2826 / Email: davidb@perfectomobile.com