TechTalk: Taking the Mystery Out of Object ID Automation

22
Object Spy, Visual Analysis and XML/Xpath Intro and Demo for Partners David Broerman Partner Enablement Manager Phone: 727. 225.2826 / Email: [email protected]

Transcript of TechTalk: Taking the Mystery Out of Object ID Automation

Page 1: TechTalk: Taking the Mystery Out of Object ID Automation

Object Spy, Visual Analysis and XML/XpathIntro and Demo for Partners

David BroermanPartner Enablement ManagerPhone: 727. 225.2826 / Email: [email protected]

Page 2: TechTalk: Taking the Mystery Out of Object ID Automation

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

Page 3: TechTalk: Taking the Mystery Out of Object ID Automation

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

Page 4: TechTalk: Taking the Mystery Out of Object ID Automation

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.

Page 5: TechTalk: Taking the Mystery Out of Object ID Automation

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.

Page 6: TechTalk: Taking the Mystery Out of Object ID Automation

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

Page 7: TechTalk: Taking the Mystery Out of Object ID Automation

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

Page 8: TechTalk: Taking the Mystery Out of Object ID Automation

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

Page 9: TechTalk: Taking the Mystery Out of Object ID Automation

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

Page 10: TechTalk: Taking the Mystery Out of Object ID Automation

Adding Commands from the Object Spy

Page 11: TechTalk: Taking the Mystery Out of Object ID Automation

11

Working with Firebug and FirePath

Page 12: TechTalk: Taking the Mystery Out of Object ID Automation

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.

Page 13: TechTalk: Taking the Mystery Out of Object ID Automation

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.

Page 14: TechTalk: Taking the Mystery Out of Object ID Automation

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.

Page 15: TechTalk: Taking the Mystery Out of Object ID Automation

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");}

Page 16: TechTalk: Taking the Mystery Out of Object ID Automation

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).

Page 17: TechTalk: Taking the Mystery Out of Object ID Automation

XPath Examples

Page 18: TechTalk: Taking the Mystery Out of Object ID Automation

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.

Page 19: TechTalk: Taking the Mystery Out of Object ID Automation

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

Page 20: TechTalk: Taking the Mystery Out of Object ID Automation

Demo• Open Perfecto Automation and also Open existing Perfecto Lab Selenium

Project in Eclipse• Discuss Object Spy , Visual Analysis and Xpath

Page 21: TechTalk: Taking the Mystery Out of Object ID Automation

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/

Page 22: TechTalk: Taking the Mystery Out of Object ID Automation

Thank You

David BroermanPartner Enablement ManagerPhone: 727. 225.2826 / Email: [email protected]