Galactic Civilizations 3
Create a custom command in Selenium

Create a custom command in Selenium

Category: Javascript.
Posted by on the 10/04/2014.
Last update on the 13/04/2014.

<<Previous tutorial 

Description

This tutorial explains how create your own custom commande in Selenium and how to use it in your script.

Introduction

This tutorial requires that Selenium IDE is installed. It also requires that the plugins flowControl and selblocks are installed. This tutorial has been done with Firefox. This tutorial can be realized with a simple text editor like « Notepad ».

Creation of the command

First of all we need to create a javascript file (.js).

For example: tutorielsenfolie.js.

The command need to be written like this:

Selenium.prototype.doMyCommand = function() {
...
// Code of my custom command
...
};

MyCommand is the name of our new command.

Using other commands

Inside our command, we can use other existing commands. For example, if we want to execute the « echo » command to display the title of a webpage. To do that, you need to write this:

Selenium.prototype.doMyCommand = function(myParameter) {
var title = this.getText("//h1");
this.doEcho(title);
};

As you can see, to call the « echo » command, we need to add "do" and set the first letter in capital.

The getText method corresponds to the « storeText » command. To know that, we need to check the « Reference » tab of Selenium.

Command reference in Selenium

Add a file as Selenium extension

To be able to use your new command in Selenium, you need to add it as extension. To do that:

  • Click on « Options » — « Options... » ;
  • In « Selenium Core extensions » section, click on « Browse »;

Using the custom command in Selenium

We can now use the new command like this:

MyCommand | ${myParameter}

Using custom command in Selenium

You like this tutorial ?
Like this website in order to promote it on facebook !

<<Previous tutorial 

You like this tutorial ? Share it with your friends !
Partager sur Facebook Partager sur Twitter Partager sur Myspace Partager sur Stumbleupon Soumettre sur Reddit Partager sur Digg Ajouter à vos favoris Technorati Ajouter à vos favoris Live Ajouter à vos favoris Google Ajouter sur vos favoris Yahoo