Selenium Extended Functionality

Source: Internet
Author: User

Selenium user extensions and plugins

(Reproduced: http://luyongxin88.blog.163.com/blog/static/9255807201181114747437/)

User extensions is to provide users with a way to write their own commands. The commands you write will be the same as the commands in the selenium itself, can be used in the IDE, and after the first few letters, the IDE can also give the command prompt. User extensions is stored in a separate file, we'll tell Selenium IDE or Selenium RC to use. Inside there the new function would be written in JavaScript.
Because Selenium ' s core is developed in JavaScript, creating a extension follows the standard rules for Prototypal Langua Ges. To create a extension, we create a function in the following design pattern. The format is as follows: Selenium.prototype.doFunctionName = function () {
.
.
.
}
The ' do ' in front of the function name tells Selenium, the This function can is called as a command for a step instead of An internal or private function.  in order to use our own user extensions, we need to create a file, for example, named: User-extention.js, and then edit our own command function in that file. Multiple functions can be stored in the file. Once written, load your extension in selenium and restart the IDE to use it. For example I have one of the following user extension files: C:\user-extensions.js, others have multiple command functions (dostorerandom/dodisplayalert/dotypetodaysdate)
 user-extensions.js File

 //generate random number
Selenium.prototype.doStoreRandom = function (variableName) {
Random = M Ath.floor (Math.random () *10000000);
Storedvars[variablename] = random;
}


/Popup box
Selenium.prototype.doDisplayAlert = function (value, varName) {
    alert (value);
}

//Enter the current date in the control
Selenium.prototype.doTypeTodaysDate = function (Locator) {
var dates = new Date ();
var day = Dates.getdate ();
if (Day < ten) {
Day = ' 0 ' + day;
}
Month = Dates.getmonth () + 1;
if (Month <) {
month = ' 0 ' + month;
}
var year = Dates.getfullyear ();
var prettyday = day + '/' + month + '/' + year;
This.dotype (Locator, ' dddddd ');
}

    load This user extension file ide--"options--" options here, when you need to be aware, is to select our files in "Selenium Core extensions". The original book says in the "Selenium IDE extensions" selection, but I do so after restarting always prompt "error loading Selenium IDE Extensions:ReferenceError:Selenium is not D efined "error message. Later I complete a long time on the internet to find the reason, and then accidentally saw that can choose core extensions try, really no problem, and the application of normal. At the same time, we can also find that if there is any error in the User-extensions file, it will be detected when the IDE restarts, and can give information such as error line.   Enter our own commands in the command of the IDE as stated earlier, when we have written the previous part of the command, the IDE will be able to give a hint like its own command, and a "command andwait" command in addition, Note that we write in the file is dostorerandom, but in fact our command is: Storerandom. When you use the command, do is removed, only the following parts are used, and the first letter of the command becomes lowercase, although the file is written in uppercase.    Example 1: Generate a random number of commands storerandom  Instance 2: Enter the day's date into the control to open user-extensions.js, and add the following to the other
 //Enter the current date in the control
Selenium.prototype.doTypeTodaysDate = function (Locator) {
var dates = new Date ();
var day = Dates.getdate ();
if (Day < ten) {
Day = ' 0 ' + day;
}
Month = Dates.getmonth () + 1;
if (Month <) {
month = ' 0 ' + month;
}
var year = Dates.getfullyear ();
var prettyday = day + '/' + month + '/' + year;
this.dotype (Locator, ' prettyday ');
}
It is to be explained that this example tells us that we can also use Selenium's own commands in our code, such as the red section above, using the type command.  Example 3:checkdate for this example I have not yet read the error in the book: This.browserbot.getUserWindow (). Checkdate is not a function, you can see it after filename. Example 4: In the following address, some of the better user extension code, http://wiki.openqa.org/display/SEL/Contributed+User-Extensions I was thinking, when  I'm free to practice all those things again, because some of them are not so obvious. The add-ons is not going to see it for the time being. About user Extensions and add-ons, I was thinking, is not the use of RC, this aspect of the role is not very obvious. Or when I need these functions, I can use the language itself to solve the function, for example I want to connect the database, I can use Java to connect, if I want to use random numbers, I use Java to produce, for example I want to use Datadriver, I also use Java read files to implement. Of course, the User Extensions and add-ons may have its benefits, but I'm not quite sure where his advantage lies. Of course, the non-programming operation is still needed. Reference book: "0 cost to achieve Web Automation testing---Based on seleinum and bromine"

Selenium Extended Functionality

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.