Selenium Tutorial

Components of Selenium: a. Selenium IDE - Plugin to Firefox to record and play test in firefox and also export tests in different languages. The most appealing format is the html test case which seems to based on fit html.
b. Selenium RC- Allows playing of exported test in different platform/OS.
c. Selenium Grid - Allows to control lots of selenium machines.

Selenium RC Tutorial: Selenium RC is a Java based command line server that starts browsers and runs commands you pass from your tests.

Steps to set up the Selenium tool and execute the test case:

1. Install Selenium IDE

2. Record a test case using Selenium IDE in firefox and Export file as “PHP selanium RC” with filename Example.php

3. Open PHP file in notepad and verify that following code should be displayed:


Last line Complexity in the code - ‘$this->getText…’. The function ‘getText’ returns the text found at the element specified in the expression. The complex looking line is an xpath expression.

An easy way is to use the XPather Firefox addon to get the xpath of any element on a page. After you download and install the addon, restart Firefox, right-click on any element and from the context menu select ‘Show in XPather’. XPather retrieves the xpath to the specified element, which you can than use in your test code.

4. Download and Install Java Runtime

5. Downloaded Selenium RC

6. Start the Selenium RC server by typing “java -jar selenium-server.jar” command in command prompt.

7. Now the server is ready to accept test commands from your PHP script. Make sure you keep this server running till you finish testing.

8. Download and Install WAMP and PHPUnit on Windows.

a. Once you have installed and setup WAMP, open up the command prompt and go to your php directory in WAMP [C:\>cd wamp\bin\php\php5.2.5]

b. From here you must run the go-pear.bat file to install PEAR and all the files needed for it [C:\wamp\bin\php\php5.2.5>go-pear.bat]

c. When executed PEAR will ask you a series of question to set itself up correctly, if you don’t know what your doing then just accept the defaults.

d. Once installed you must run the PEAR_ENV.reg which will create the environment variables for the user, so that PEAR can be called in any directory on the command line [C:\wamp\bin\php\php5.2.5>PEAR_ENV.reg].

e. It should work but if you cannot call PEAR from the command prompt, then you must manually add the directory to the path in the Environment Variables list, found in System Properties -> Advanced-> Environment Variables, then add the directory [C:\wamp\bin\php\php5.2.5 to the PATH variable].

f. Once you have PEAR setup, then you must register the PHPUnit channel with PEAR [C:\wamp\bin\php\php5.2.5>pear channel-discover pear.phpunit.de].

g. Now you can use the PEAR to install packages from the PHPUnit channel [C:\wamp\bin\php\php5.2.5>pear install phpunit/PHPUnit]

9. Copy and paste the “Example.php” file in php folder [C:\wamp\bin\php\php5.2.8]

10. Open another command window and write [cd C:\wamp\bin\php\php5.2.8]

11. Run command [phpunit Example]

Run LoadRunner Controller from command line?

You can open LoadRunner Controller scenario with:

LoadRunner\bin\Wlrun.exe -Run -TestPath scenario.lrs -ResultName res_folder


For example: 


(note: click the image to enlarge it)

As a result of above command, LoadRunner Controller: 

  • starts
  • opens Controller scenario
  • executes it
  • saves results to folder 'C:\Temp\LR_Res\result_0'
After that, Controller finishes working and closes.
Please, see files from created 'C:\Temp\LR_Res\result_0' folder:



Tips: As you see, there is LoadRunner Result file (result_0.lrr). You can pass it automatically to LoadRunner Analysis for further processing.

Actually, Wlrun.exe can have several settings. There are their descriptions from HP LoadRunner Controller User's Guide (© HP/Mercury Interactive):

TestPathPath to the scenario.
For example, C:\LoadRunner\scenario\Scenario.lrs
If the path includes blank spaces, use quotation marks.
RunRuns the scenario, dumps all output messages into res_dir\output.txt and closes Controller
InvokeAnalysisInstructs LoadRunner to invoke Analysis upon scenario termination. If this argument is not specified, LoadRunner uses the scenario default setting.
ResultNameFull results path. For example, "C:\Temp\Res_01"
ResultCleanNameResults name. For example, "Res_01"
ResultLocationResults directory. For example, "C:\Temp"

Note: ResultName (full path) = ResultLocation (directory) + ResultCleanName (name)



Well, let's see different variants of how to open and run LoadRunner Controller script: 


1. Open LoadRunner Controller:

  Wlrun.exe


2. Open LoadRunner Controller scenario 'scenario.lrs' and do not execute it: 

  Wlrun.exe -TestPath scenario.lrs


3. Open LoadRunner Controller scenario 'scenario.lrs', execute it, and save results to default folder ('C:\Documents and Settings\user_login\Local Settings\Temp\res'): 

  Wlrun.exe -Run -TestPath scenario.lrs



4. Open LoadRunner Controller scenario 'scenario.lrs', execute it, and save results to 'res_folder' folder:


 Wlrun.exe -Run -TestPath scenario.lrs -ResultName res_folder

5. Open LoadRunner Controller scenario 'scenario.lrs', execute it, save results to 'res_folder' folder, and after that start Analysis on created results with default template: 


Wlrun.exe -Run -TestPath scenario.lrs -ResultName res_folder - InvokeAnalysis


And please see more complex example for desert :) 

6. Open LoadRunner Controller scenario 'scenario.lrs', execute it, save results to 'res_folder' folder, and after that start Analysis on created results with default template. Repeat all these steps 10 times: 

 set LR_HOME=C:\Program Files\Mercury\LoadRunner
 for /L %%i in (1,1,10) do "%LR_HOME%\bin\Wlrun.exe" -Run -TestPath "%LR_HOME%\scenario\memory_leak_crash.lrs"
 -ResultName C:\Temp\LR_Res\result%%i 

Result is: 


Well, where to use execution from a command line?
It can be very useful in some cases, when you plain to:

  • run LoadRunner Controller and pass its results to LoadRunner Analysis
  • run LoadRunner scripts by schedule

Selenium Interview Questions


1) What does SIDE stand for? 

2) What is the difference between an assert and a verify with Selenium commands? 

3) What Selenium commands can be used to help debug a regexp? 

4) What is one big difference between SilkTest and Selenium, excluding the price? 

5) Which browsers can Selenium IDE be run in? 

6) If a Selenium function requires a script argument, what would that argument look like in general terms? 

7) If a Selenium function requires a pattern argument, what five prefixes might that argument have? 

8) What is the regular expression sequence that loosely translates to "anything or nothing?" 

9) What is the globbing sequence that loosely translates to "anything or nothing? 

10) What does a character class for all alphabetic characters and digits look like in regular expressions? 

11) What does a character class for all alphabetic characters and digits look like in globbing? 

12) What must one set within SIDE in order to run a test from the beginning to a certain point within the test? 

13) What does a right-pointing green triangle at the beginning of a command in SIDE indicate? 

14) How does one get rid of the right-pointing green triangle? 

15) How can one add vertical white space between sections of a single test? 

16) What Selenium functionality uses wildcards? 

17) Which wildcards does SIDE support? 

18) What are the four types of regular expression quantifiers which we've studied? 

19) What regular expression special character(s) means "any character?" 

20) What distinguishes between an absolute and relative URL in SIDE? 

21) How one access a Selenium variable would named "count" from within a JavaScript snippet? 

22) What Selenese command can be used to display the value of a variable in the log file, which can be very valuable for debugging? 

23) If one wanted to display the value of a variable named answer in the log file, what would the first argument to the previous command look like? 

24) Where did the name "Selenium" come from? 

25) Which Selenium command(s) simulates selecting a link? 

26) Which two commands can be used to check that an alert with a particular message popped up? 

27) What does a comment look like in Column view? 

28) What does a comment look like in Source view? 

29) What are Selenium tests normally named (as displayed at the top of each test when viewed from within a browser)? 

30) What command simulates selecting the browser's Back button? 

31) If the Test Case frame contains several test cases, how can one execute just the selected one of those test cases? 

32) What globbing functionality is NOT supported by SIDE? 

33) What is wrong with this character class range? [A-z] 

34) What are four ways of specifying an uppercase or lowercase M in a Selenese pattern? 

35) What does this regular expression match? 

36) regexp:[1-9][0-9],[0-9]{3},[0-9]{3}

37) What are two ways to match an asterisk within a Selenese regexp? 

38) What is the generic name for an argument (to a Selenese command) which starts with //? 

39) What Selenese command is used to choose an item from a list? 

40) How many matches exist for this pattern? 

41) regexp:[13579][02468]

42) What is the oddity associated with testing an alert? 

43) How can one get SIDE to always record an absolute URL for the open command's argument? 

44) What Selenese command and argument can be used to transfer the value of a JavaScript variable into a SIDE variable? 

45) How would one access the value of a SIDE variable named name from within a JavaScript snippet used as the argument to a Selenese command? 

46) What is the name of the type of JavaScript entity represented by the last answer? 

47) What string(s) does this regular expression match? 

48) regexp:August|April 5, 2010

49) What Selenium regular expression pattern can be used instead of the glob below to produce the same results? 

50) verifyTextPresent | glob:9512?

51) What Selenium globbing pattern can be used instead of the regexp below to produce the same results? 


Selenium Test Tool


Selenium is a set of tools that supports development of test automation for web-based applications. Selenium supports multiple browser platforms.

Selenium can be used for Functional and Performance Test Automation for web based Applications.

Selenium Components

Selenium is composed of three major tools. Each one has a specific role in aiding the development of web application test automation.

Selenium-IDE

Selenium-IDE is the Integrated Development Environment for building Selenium test cases. 

Selenium-RC (Remote Control) 

Selenium-RC allows the test automation developer to use a programming language for maximum flexibility and extensibility in developing test logic. 

Selenium-RC provides an API (Application Programming Interface) and library for each of its supported languages: HTML, Java, C#, Perl, PHP, Python, and Ruby. 

Selenium-Grid

Selenium-Grid allows the Selenium-RC solution to scale for large test suites or test suites that must be run in multiple environments. 

Supported Browsers

o Firefox 3.x, Firefox 3, Firefox 2

o IE 8, IE 7, IE 6

o Safari 4, Safari 3, Safari 2

o Opera 10, Opera 9, Opera 8

and Google Chrome


* Tests developed on Firefox via Selenium-IDE can be executed on any other supported browser via a simple Selenium-RC command line.

** Selenium-RC server can start any executable, but depending on browser security settings there may be technical limitations that would limit certain features.

Extensibility

Selenium is highly flexible. There are multiple ways in which one can add functionality to Selenium’s framework to customize test automation for one’s specific testing needs. 

Selenium-IDE allows for the addition of user-defined “user-extensions” for creating additional commands customized to the user’s needs.