Selenium is an extremely useful tool for simulating user interaction with your website for testing. When used through a service such as browsermob.com it can amplify a script to simulate multiple users using your website. This can be extremely useful for load testing and discovering the limitations of your web server e.g. how many user connections your web server can manage before it becomes slow and perhaps even crashes.
Selenium is an extremely easy tool to use and can be downloaded as a Firefox plug-in extension here: http://seleniumhq.org/download/. The plug-in allows you to navigate your website as a user would and it records the actions for you, practically creating the test automatically. This can then be uploaded to browsermob.com as a HTML file to produce a JavaScript test. Selenium tests can also be created in many different languages, such as C# in conjunction with NUnit. However the HTML/browsermob.com method is so simple the other languages are only really useful for more advanced tests that may involve iteration.
The plug-in is extremely useful but not perfect. It is almost always necessary to debug the script produced by Selenium using browermob.com. Most of the time it is changing a click command to clickAndWait as the script is trying to access objects which haven’t appeared due to the previous command causing a page refresh. Also depending on your sites HTML it may be necessary to step through the site using firebug to get the correct image and a href link identifications.
Sites I found useful to start using Selenium are:
http://www.dynamitemap.com/selenium/
http://www.testandtry.com/2010/05/05/browsermob-tailor-made-cloud-testing/
Along with the sites online documentation:
I include a sample script below. The script is fairly simple to understand so I will not explain unless people ask questions via comments. Hopefully it will allow people to work out how to learn or resolve some issues they may be facing with clickAndWait or waitForPageLoad.
var selenium = browserMob.openBrowser();
var csv = browserMob.getCSV("emails.csv");
var row = csv.random();
var timeout = 30000;
selenium.setTimeout(timeout);
var tx = browserMob.beginTransaction();
//Open webpage
var step = browserMob.beginStep("Step 1");
selenium.open("web site base URL");
browserMob.endStep();
//Select Fantasy Football Package
browserMob.beginStep("Step 2");
selenium.click("//a[@onclick='GoToPackageSelection();return false;']");
selenium.waitForPageToLoad(timeout);
selenium.clickAndWait("//div[@id='ctl00_StandardMainBodyPlaceHolder
_ctl02_PackageSelectionOptionPanel']/a");
browserMob.endStep();
//Select Team
browserMob.beginStep("Step 3");
selenium.select("dropdownlist_gk", "label=B Foster £3.00m");
selenium.select("dropdownlist_def1", "label=G Clichy £5.00m");
selenium.select("dropdownlist_def2", "label=J Collins £4.00m");
selenium.select("dropdownlist_def3", "label=S Dann £2.00m");
selenium.select("dropdownlist_def4", "label=G Givet £2.50m");
selenium.select("dropdownlist_mid1", "label=A Arshavin £7.00m");
selenium.select("dropdownlist_mid2", "label=S Petrov £3.00m");
selenium.select("dropdownlist_mid3", "label=J Milner £5.50m");
selenium.select("dropdownlist_midstr", "label=B Ormerod £1.00m");
selenium.select("dropdownlist_str1", "label=E Adebayor £6.50m");
selenium.select("dropdownlist_str2", "label=W Rooney £8.50m");
selenium.type("player_select_team_name", "Test Team");
selenium.click("ConfirmTeamSelectButton");
selenium.click("bg_ts_1");
selenium.click("bg_ts_2");
selenium.click("bg_ts_3");
selenium.click("bg_ts_4");
selenium.click("//img[@alt='Done selecting your teams?
Click proceed to continue.']");
browserMob.endStep();
//Registration
browserMob.beginStep("Step 4");
selenium.waitForPageToLoad(timeout);
selenium.clickAndWait("ctl00_StandardMainBodyPlaceHolder_SignUpLink");
var Email = row.get("email");
selenium.type("ctl00_StandardMainBodyPlaceHolder_ctl00_TextBoxEmail"
, Email);
selenium.type("ctl00_StandardMainBodyPlaceHolder_ctl00
_TextBoxEmailConfirm", Email);
selenium.type("ctl00_StandardMainBodyPlaceHolder_ctl00_TextBoxPassword"
, "password123");
selenium.type("ctl00_StandardMainBodyPlaceHolder_ctl00
_TextBoxPasswordConfirm", "password123");
selenium.select("ctl00_StandardMainBodyPlaceHolder_ctl00_DropDownListTitle"
, "label=Mr");
selenium.type("ctl00_StandardMainBodyPlaceHolder_ctl00_TextBoxFirstName"
, "Test");
selenium.type("ctl00_StandardMainBodyPlaceHolder_ctl00_TextBoxLastName"
, "Test");
selenium.select("ctl00_StandardMainBodyPlaceHolder_ctl00_DropDownGender"
, "label=male");
selenium.select("ctl00_StandardMainBodyPlaceHolder_ctl00
_DropDownListDobDay", "label=23");
selenium.select("ctl00_StandardMainBodyPlaceHolder_ctl00
_DropDownListDobMonth", "label=March");
selenium.select("ctl00_StandardMainBodyPlaceHolder_ctl00
_DropDownListDobYear", "label=1987");
selenium.type("ctl00_StandardMainBodyPlaceHolder_ctl00
_TextBoxFlatOrHouseNumber", "1");
selenium.type("ctl00_StandardMainBodyPlaceHolder_ctl00_TextBoxAddress1"
, "Test Ave");
selenium.type("ctl00_StandardMainBodyPlaceHolder_ctl00_TextBoxTownCity"
, "Test City");
selenium.type("ctl00_StandardMainBodyPlaceHolder_ctl00_TextBoxCounty"
, "Test County");
selenium.type("ctl00_StandardMainBodyPlaceHolder_ctl00_TextBoxPostCode"
, "TE1 9ST");
selenium.select("ctl00_StandardMainBodyPlaceHolder_ctl00
_DropDownListCountryOfResidence", "label=United Kingdom");
selenium.type("ctl00_StandardMainBodyPlaceHolder_ctl00
_TextBoxHomeTelephone", "00000000000");
selenium.clickAndWait("ctl00_StandardMainBodyPlaceHolder
_ctl00_ButtonRegister");
browserMob.endStep();
browserMob.beginStep("Step 5");
selenium.waitForPageToLoad(timeout);
selenium.pause(timeout);
selenium.select("AVQ1", "label=DAILY MAIL");
selenium.select("AVQ2", "label=4 - 6 times per week");
selenium.select("AVQ3", "label=NEWS OF THE WORLD");
selenium.select("AVQ4", "label=3 - 4 times per month");
selenium.click("checkboxTermsAndConditions");
selenium.click("PackageConfirmationProceedButton");
browserMob.endStep();
//Payment
browserMob.beginStep("Step 6");
selenium.waitForPageToLoad(timeout);
selenium.select("ctl00_StandardMainBodyPlaceHolder_ctl00
_ucCreditCardEntry_ddlCardTypes", "label=MasterCard");
selenium.type("ctl00_StandardMainBodyPlaceHolder_ctl00
_ucCreditCardEntry_txtCardNumber", "1000010000000007");
selenium.type("ctl00_StandardMainBodyPlaceHolder_ctl00
_ucCreditCardEntry_txtNameOnCard", "Test");
selenium.type("ctl00_StandardMainBodyPlaceHolder_ctl00
_ucCreditCardEntry_txtCV2", "123");
selenium.select("ctl00_StandardMainBodyPlaceHolder_ctl00
_ucCreditCardEntry_ddlStartMonth", "label=02");
selenium.select("ctl00_StandardMainBodyPlaceHolder_ctl00
_ucCreditCardEntry_ddlStartYear", "label=2005");
selenium.select("ctl00_StandardMainBodyPlaceHolder_ctl00
_ucCreditCardEntry_ddlExpiryMonth", "label=02");
selenium.select("ctl00_StandardMainBodyPlaceHolder_ctl00
_ucCreditCardEntry_ddlExpiryYear", "label=2010");
selenium.click("ctl00_StandardMainBodyPlaceHolder_ctl00
_ucCreditCardEntry_ibMakePayment");
browserMob.endStep();
//View Team and Make Transfers
browserMob.beginStep("Step 7");
selenium.waitForPageToLoad(timeout);
selenium.clickAndWait("//img[@alt='View Teams']");
selenium.clickAndWait("link=Test Team");
selenium.clickAndWait("link=Make Transfers");
selenium.select("dropdownlist_mid2", "label=K Fahey £2.00m");
selenium.select("dropdownlist_str1", "label=D Kitson £1.50m");
selenium.select("dropdownlist_str2", "label=M Owen £3.00m");
selenium.clickAndWait("//img[@alt='SubmitTransfers']");
browserMob.endStep();
//Finalise Transfers
browserMob.beginStep("Step 8");
selenium.clickAndWait("//img[@alt='Done selecting your teams?
Click proceed to continue.']");
selenium.clickAndWait("//img[@alt='View Teams']");
selenium.waitForPageToLoad(timeout);
selenium.clickAndWait("link=Test Team");
browserMob.endStep();
//Log out
browserMob.beginStep("Step 9");
selenium.click("LogOut");
selenium.waitForPageToLoad(timeout);
browserMob.endStep();
browserMob.endTransaction();
[...] This post was mentioned on Twitter by Sauce Labs, Jonathan Stowell. Jonathan Stowell said: New blog post about the basics of Selenium http://bit.ly/a6xw8R [...]