Wednesday, November 5, 2014

Sample Selenium IDE Test Script Manually:



Now, we shall recreate the same test case manually, by typing in the commands. This time, we will need to use Firebug.

Step 1:



                   
  • Open Firefox and Selenium IDE.


  •                
  • Type the base URL (http://newtours.demoaut.com/).


  •                
  • The record button should be OFF.1




Step 2:



                   
  • Click on the topmost blank line in the Editor.2


  •                
  • Type “open” in the Command text box and press Enter.3




Step 3:



                   
  • Navigate Firefox to our base URL and activate Firebug


  •                
  • In the Selenium IDE Editor pane, select the second line (the line below the “open” command) and create the second command by typing “assertTitle” on the Command box.


  •                
  • Feel free to use the autocomplete feature.




 Step 4:



                   
  • In Firebug, expand the <head> tag to display the <title> tag.


  •                
  • Click on the value of the <title> tag (which is “Welcome: Mercury Tours”) and paste it onto the Target field in the Editor.4




Step 5:



                   
  • To create the third command, click on the third blank line in the Editor and key-in “type” on the Command text box.


  •                
  • In Firebug, click on the “Inspect” button.5




Click on the User Name text box. Notice that Firebug automatically shows you the HTML code for that element.

6

 Step 6:



                   
  • Notice that the User Name text box does not have an ID, but it has a NAME attribute. We shall, therefore, use its NAME as the locator. Copy the NAME value and paste it onto the Target field in Selenium IDE.




7



                   
  •  Still in the Target text box, prefix “userName” with “name=”, indicating that Selenium IDE should target an element whose NAME attribute is “userName.”




8



                   
  • Type “invalidUN” in the Value text box of Selenium IDE. Your test script should now look like the image below. We are done with the third command. Note: Instead of invalidUN , you may enter any other text string. But Selenium IDE is case sensitive and you type values/attributes exactly like in application.




9

 Step 7:



                   
  • To create the fourth command, key-in “type” on the Command text box.


  •                
  • Again, use Firebug’s “Inspect” button to get the locator for the “Password” text box.




10



                   
  • Paste the NAME attribute (“password”) onto the Target field and prefix it with “name=”


  •                
  • Type “invalidPW” in the Value field in Selenium IDE. Your test script should now look like the image below.




11

 Step 8:



                   
  • For the fifth command, type “clickAndWait” on the Command text box in Selenium IDE.


  •                
  • Use Firebug’s “Inspect” button to get the locator for the “Sign In” button.




12



                   
  • Paste the value of the NAME attribute (“login”) onto the Target text box and prefix it with “name=”.




Your test script should now look like the image below.

13

 Step 9:



                   
  • Save the test case in the same way as we did in the previous section.






Using the Find Button


The Find button in Selenium IDE is used to verify if what we had put in the Target text box is indeed the correct UI element.

Let us use the Invalid_login test case that we created in the previous sections. Click on any command with a Target entry, say, the third command.

14



Click on the Find button. Notice that the User Name text box within the Mercury Tours page becomes highlighted for a second.

15



This indicates that Selenium IDE was able to detect and access the expected element correctly. If the Find button highlighted a different element or no element at all, then there must be something wrong with your script.

 Execute Command



This allows you to execute any single command without running the whole test case. Just click on the line you wish to execute and then either click on “Actions > Execute this command” from the menu bar or simply press “X” on your keyboard.

 Step 1: Make sure that your browser is on the Mercury Tours homepage. Click on the command you wish to execute. In this example, click on the “type | userName | invalidUN” line.

16

 Step 2: Press “X” on your keyboard.

Step 3: Observe that the text box for username becomes populated with the text “invalidUN”

17



Executing commands this way is highly dependent on the page that Firefox is currently displaying. This means that if you try the example above with the Google homepage displayed instead of Mercury Tours’ then your step will fail because there is no text box with a “userName” attribute within Google’s homepage.

 Start point

A start point is an indicator that tells Selenium IDE which line the execution will start. Its shortcut key is “S”.

18



In the example above, playback will start on the third line (type | password | invalidPW). You can only have one start point in a single test script.

Start point is similar to Execute Command in such that they are dependent on the currently displayed page. The start point will fail if you are on the wrong page.

 Breakpoints

Breakpoints are indicators that tell Selenium IDE where to automatically pause the test. The shortcut key is “B”.

19

The yellow highlight means that the current step is pending. This proves that Selenium IDE has paused execution on that step. You can have multiple breakpoints in one test case.

 Step

It allows you to execute succeeding commands one at a time after pausing the test case. Let us use the scenario in the previous section “Breakpoints.”

20

0 comments:

Post a Comment