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

The Advanced part of Selenium IDE-Rollup Strategy

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 IDE Rollup strategy

Why do you need to use the Rollup strategy?

Using Rollup strategies can make your test scripts look more concise, test command sets more reusable, and using Rollup can make your scripts look like the following code:

Among them, loggincommands in the rollup command is a collection of selenese instructions that contains login partial script instructions. In this way, any part that is repeated in multiple scripts can be extracted for reuse by more test scripts. This has three major advantages:

The script is simple and easy to understand.

§the common part of the selenese command set gets the maximum reusability.

§provides a single point of access, a modification, and the effect of being used everywhere.

Let's take a look at how to define a set of rollup policies. Defining rollup requires the creation of a new javascript file ending with .js.

Var manager = new RollupManager ()

Manager.addRollupRule ({...})

Manager.addRollupRule ({...})

...

RollupManager as the management object of rollup policy implementation, we can add multiple groups of rollupRule to rollup manager, and we can simply use the RollupManager#addRollupRule (Object) method to add rollup policy.

After adding rollupRule, let's take a look at how to define rollup objects:

Manager.addRollupRule ({name: 'logincommands', description:' register & login into newtours.com', args: [{name: 'email', description:' register one user account, used it just for the identifier.', exampleValues: ['aa',' bb' 'cc']}, {name:' passwd', description: 'register one user account, used it just for the identifier.', exampleValues: [' 122', '333', '222]}] CommandMatchers: [{command: 'type', target:' id=email', updateArgs: function (command, args) {args.email = command.value Return args }}, {command: 'type', target:' name=password', updateArgs: function (command, args) {args.passwd = command.value Return args }}, {command: 'type', target:' name=confirmPassword', updateArgs: function (command, args) {args.passwd = command.value Return args;}}, {command: 'clickAndWait', target:' name=register'}], getExpandedCommands: function (args) {var commands = [] Commands.push ({command: 'type', target:' id=email', value: args.email}) Commands.push ({command: 'type', target:' name=password', value: args.passwd}) Commands.push ({command: 'clickAndWait', target:' name=register'}); return commands;})

The above code snippet is a complete Rollup policy definition that contains multiple attributes in the rollup object: name, description, args, commandMatchers, getExpandedCommands, which are described below:

The name of the Name:rollup policy should be unique in the rollup manager.

Description: a description of the rollup policy, which is displayed to the user as a help document.

Args: array type, which can have multiple sets of args,args parameters for the caller to pass in the rollup policy. For example, two parameters are passed when calling logincommand, which corresponds to two args definitions in the args array. There are three parameters in the args definition: name (parameter name), description (parameter description), exampleValues (no practical significance, showing the parameter value type to the user). The variables defined in Args are applied to two locations. The updateArgs method in commandMatchers, and the getExpandedCommands method.

CommandMatchers, this parameter is used to apply the group policy function in Selenium IDE, that is, in Selenium IDE

Which is available only when commandMatchers is defined

CommandMatchers is used to match the selenese command in the script that conforms to the rules defined by commandMachers and generates the rollup command with one click.

{command: 'type', target:' id=email', updateArgs: function (command, args) {args.email = command.value; return args;}}

Multiple sets of command can be defined in commandMatchers, and each command can contain several parameters such as command, target and updateArgs.

Command: that is, the selenese command, that is, the command that the command matcher wants to match.

Target: element locator. Here you can match multiple target in a regular way. If you use regular, that is, the command matcher can match multiple selenese commands, provided of course that the same type of command is used.

UpdateArgs:Function, the implementation of the function is used to dynamically receive the parameters and parameter values worn by the rollup caller, and dynamically update the variables defined in args according to the custom rules. Note that here only dynamically modify the value of the args variable according to the parameter values passed by the caller, and finally return the value return as the args object.

When the value of args is empty when rollup is defined, for example, args: [], the updateArgs definition is invalid.

GetExpandedCommands

The getExpandedCommands parameter is used to define the collection of Selenese commands contained in the rollup command, that is, the commands that really need to be executed at run time

This parameter is defined as a function with an args parameter, and the function returns an array of all the commands that need to be executed.

Commands.push ({command: 'type', target:' name=password', value: args.passwd})

The array element contains three parts, namely, the three parts of the selenese instruction, namely command, target, and value, in which value can be dynamically updated by the parameters passed in when the user invokes the rollup command.

To sum up, rollup policy is a very powerful function provided by a selenium ide. There are three benefits of using rollup strategy. Mastering rollup strategy only requires script developers to master the javascript language to use it easily and flexibly.

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