Based on the study in the previous section, we believe that we have basically used selnium ide. In order to make selenium more powerful, Selenium also provides good scalability.
---- // User Extension
User extension is usedJavascriptFile to create custom features and add new features. In general, such extensions are customized commands, but extensions are not limited to commands.
Here there are some column extensions: http://wiki.openqa.org/display/SEL/Contributed+User-Extensions
1. Next we use the extended method to generate a random user number.
To use user extensions, we need to create a file, which can also be downloaded from the above link. File Name: user-extention.js
// Generate random number
Selenium. Prototype. dostorerandom = Function (Variablename ){
Random = math. Floor (math. Random () * 10000000 );
Storedvars [variablename] = random;
}
// Dialog 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 <10 ){
Day = '0' + Day;
}
Month = dates. getmonth () + 1;
If (Month <10 ){
Month = '0' + month;
}
VaR Year = dates. getfullyear ();
VaR Prettyday = day + '/' + month + '/' + year;
This . Dotype (locator, 'ddddddd ');
}
Set the aboveCodeCopy to a notepad and save it as a: user-extention.js File
Import this file in selenium IDE, for example:
Select the file and click "OK. You must disable selenium IDE and restart selenium ide to read the extension file. Selenium ide must be disabled and restarted for any scaling changes.
2. Convert the code format
Select the format in the Options menu, and allow you to select a language to protect and test the case of the warrior. The default format is HTML.
If you use selenium RC to run the test case. This feature helps you translate test casesProgramming Language.
We can select "file" ---- export test case as... to convert the language format we need. For specific examples, see selenium RC environment setup
3. Perform selenium ide testing on different browsers.
Selenium IDE can only run on friefox, but it can run on other browsers through automated tests developed by selenium IDE. You only need to use a simple command to wake up the selenium RC Server.
If the browser is not directly supported, use"* Custom"Run mode, you can still run the selenium test case in a browser.
Cmd = getnewbrowsersession & 1= * Custom C: \ Program Files \ Mozilla Firefox \Mybrowser.exe& 2= Http://Fnng.cnblogs.com
The following code:
PackageCom. example. tests;
ImportCom. thoughtworks. Selenium .*;
ImportOrg. JUnit. After;
ImportOrg. JUnit. before;
ImportOrg. JUnit. test;
ImportJava. util. RegEx. pattern;
Public ClassTestExtendsSelenesetestcase {
@ Before
Public VoidSetup ()ThrowsException {
Selenium =NewDefaultselenium ("localhost", 4444, "* Chrome", http://fnng.cnblogs.com /);
//You can use the following line of code to replace the previous line of code.
// Cmd = getnewbrowsersession & 1= * Custom C: \ Program Files \ Mozilla Firefox \Mybrowser.exe& 2= Http://Fnng.cnblogs.com
// For IE browser, you can directly modify the browser name. The Code is as follows:
// Selenium =NewDefaselselenium ("localhost", 4444 ,"* Iexplore", Http://fnng.cnblogs.com/); this method is easier.
Selenium. Start ();
}
@ Test
Public VoidTesttest ()ThrowsException {
Selenium. Open ("/");
Selenium. Click ("ID = homepage=homepagedays_dayslist_dayitem_0_daylist_0_titleurl_0 ");
Selenium. waitforpagetoload ("30000 ");
}
@ After
Public VoidTeardown ()ThrowsException {
Selenium. Stop ();
}
}
For more information about how to configure the Java environment to verify a piece of code, see《Setup of selenium RC Environment"
Note:: If you start the browser in this way, you must manually configure the browser to use selenium server as the proxy. Generally, this only means to open your browser parameter file and specify "localhost: 4444 "as the HTTP proxy. However, the commands of different browsers may be completely different, so you need to find more details from your browser support documentation.
========================================================== ==========
This article reference: http://luyongxin88.blog.163.com/blog/static/9255807201181114747437/ drool pig (his blog test)ArticleA lot of examples)