Check out the Latest Articles:
Selenium

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:

http://seleniumhq.org/docs/

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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();


  1. [...] 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 [...]

  2. M Donisi (Reply) on Monday 26, 2010

    Looking over you code, I am assuming that this is a user-extension. Did you expereince any problems with the “WaitForPageToLoad” command not waiting for the page to load and skipping on to the next command?

  3. jonathan (Reply) on Monday 26, 2010

    I think I may have. Especially when there were AJAX requests going on adding to the page. So Selenium would look for an anchor which didn’t yet exist. It was a long time ago now I think and this was just a trial with work to look into load testing. We were looking into using Browser Mob https://browsermob.com/performance-testing. I think in the end I just used wait to put the script to sleep for a little while until the page would be loaded.

    We also ended up running it using our own server and I was able to write the tests in C#. Quite a nice way to automate front end testing.