Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Advanced part of Selenium IDE-UI-Element

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Resource recommendations:

Video resources: series of videos related to software testing

Community Resources: automated Test Communication Group

Selenium UI-Element introduction

Selenium UI-Element is about the feature that selenium ide can abstract elements in webpage to objects, abstracting page elements into objects to facilitate reuse by multiple scripts, and supporting the use of ui locator to locate page elements in selenese scripts. It provides a readable element location identifier for ui locators.

Related terms

Page refers to a complete page, or a complete DOM object.

Page element refers to any interactive page element in a page, which can be the node of DOM, or the text content it contains.

Collection of Pageset public page elements

UI element UI element belongs to PageSet and is used to locate page elements.

UI argument reuses UI element (parameterization) through parameters, and UI element dynamically generates different element positioning methods through parameters.

A collection of UI map pageset to establish the relationship between pageset and ui element through UIMap

UI specifier string A json code snippet used to explain the interpretation of pageset,element.

UI-Element test code example: clickAndWait ui=allPages::section (section=topics) clickAndWait ui=topicListingPages::topic (topic=Process)

The locator parameter of clickAndWait is specified as the ui locator

Ui=allPages::section (section=topics), encapsulating page elements in different pageset in this object-oriented way can improve the reuse rate and increase the readability of the script.

Usage

UI-Element is currently integrated into selenium core, and when we use the UI-Element feature, we only need to use the UIMap class to define the map file.

Map definition file syntax:

Var map = new UIMap (); map.addPageset ({name: 'aPageset', description:' contains elements common to all pages', pathRegexp:'. *',...}); map.addElement ('aPageset', {...}); map.addElement (' aPageset', {...}); Map.addPageset ({name: 'anotherPageset',...});. §first define an UIMap instance to build the relationship between pageset and ui element

§define one or more pageset, explain the pageset in the form of json, and add it to the UIMap instance using the UIMap#addPageset method.

Each pageset can define one or more elements, and bind the defined elements to the corresponding pageset one by one through the UIMap#addElement method.

List of Pageset related attributes:

Through the UIMap#addPageset (pagesetShothand) method, you can add to UIMap that pageset,pagesetShorthand is an object that describes pageset in the form of json. Code example:

Map.addPageset ({

Name: 'allPages'

, description: 'contains elements common to all pages'

, pathRegexp:'.

});

The name of Name,pageset, which is required. The uniqueness of the name needs to be guaranteed in UIMap.

The description of the Description,pageset, required, to describe which page elements the pageset contains.

PathPrefix

The web page path prefix contained in pageset, such as pathPreffix: "gallery/", indicates that the pageset contains all child page resources under the gallery/ path.

Paths & pathRegexp

Between Paths and pathRegexp, Paths uses an array to match the page paths contained in pageset, such as paths: ['gotoHome.do',' gotoAbout.do', 'gotoFaq.do'].

PathRegexp uses regular expressions to match the path of page resources contained in pageset, for example: pathRegexp: 'goto (Home | About | Faq)\\ .do'

ParamRegexps, which defines the url parameter to match the page resources covered by the pageset, such as: paramRegexps: {dept:'^ [abcd] $', team: 'marketing'}.

PageContent, match the appropriate pageset by judging the content of the page, such as:

PageContent: function (doc) {var id = 'address-tab'; return doc.getElementById (id)! = null;}

In PageContent, you can use document objects to get page content, including dom nodes and text content, and determine whether it conforms to the current pageset by judging these contents.

UI-Element correlation

UIMap#addElement (pagesetName, uiElementShorthand), pagesetName is the pageset name that UI Element wants to associate, and uiElementShorthand is a json object that describes UI Element. The following is a short code example:

Map.addElement ('allPages', {

Name: 'about_link'

, description: 'link to the about page'

, locator: "/ / a [contains (@ href, 'about.php')]"

});

All the attribute information contained in UI Element is listed as follows:

The name of Name, (String) UI Element should be defined in combination with the meaning of the attribute to achieve the effect of seeing the name and knowing the meaning.

Description, (String) A description of the current UI Element, which is also displayed as a document.

Args, (Array) A set of parameters used to modify the implementation of the getLocator () method, which defaults to an empty list.

Locator & getLocator (args), (Stirng | Function) locator and getLocator choose one of them to generate expressions that locate the elements of the page.

GenericLocator & getGenericLocator (), (String | Function) universal element locator, which can greatly improve the efficiency of positioning elements by specifying a universal element locator. When a universal element locator is specified, the matching element engine will give priority to using the locator. When the locator is matched successfully, the locator or getLocator locator will be called for further positioning.

Testcase*, (Object) defines a test case that is used to test getLocator, and the naming must begin with testcase.

UI-Element args related attributes

Name, (String) defines the parameter name, which is used to pass the parameter value into the getLocator.

Description, (String) description of parameters.

DefaultValues & getDefaultValues (inDocument), (Array | Function) is used to specify the default value of the parameter. GetDefaultValues must return Array type data.

Newtours enrollment process case

Newtours website address: http://newtours.demoaut.com/

Var myMap = new UIMap ()

MyMap.addPageset ({

Name: 'allPages'

, description: 'all newtours.com pages'

, pathRegexp:'.

});

MyMap.addElement ('allPages', {

Name: 'registerEntry'

Description: 'top level text link to register page.'

Locator: "xpath=//a [@ href='mercuryregister.php']"

Testcase1: {

Xhtml: 'register'

}

});

MyMap.addPageset ({

Name: 'loginPages'

, description: 'all login pages'

, paths: ['mercuryregister.php']

});

MyMap.addElement ('loginPages', {

Name: 'email'

Description: 'email is used for the user login account.'

Args: [

{name: 'email',description:' used for generate one sys account.', defaultValues: ['email',' bbb', 'ccc']}

]

GetLocator: function (args) {

Return 'name=' + args.email

}

Testcase1: {

Args: {email: 'qqq'}

, xhtml:''

}

});

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report