Saturday, September 29, 2012

4 Selenese Commands

Commands that we use in Selenium IDE are called as "Selenese commands" and language is know as "Selenese language".

Test Step in Selenium IDE  =  Command + Target + Value. 



Command: Selenium IDE offers a set of ready made commands that we can use directly in our test cases. These commands forms the functionality of the test step. You can find set of predefined commands that Selenium IDE offers by clicking on command combo box (refer snapshot below)




Target: Target identifies the element on the webpage on which functionality of the command has to be executed. we will talk more about identifying an element in "Xpath, Firebug and Firepath" post. 

Note: Find button highlight's the element on the webpage identified in Target field of a command. Click on it and view the webpage to observe the magic.  



Value: This is applicable only for few commands in Selenium IDE. Input given here forms the "expected result" for a given command on specified target. ex: presence of specific text in a given location.


Selenese commands

Now let us learn most frequently used commands in Selenium IDE.





open: Open's the webpage with URL derived from concatenating Base URL and Target argument. This takes 1 argument i.e. Target. If you are testing "questionselenium" then you can keep the home page URL as the Base URL and then switch between pages by providing target to open command.

Note:
  1.  If Base URL is "http://www.questionselenium.com/" and Target is "/" then it opens "http://www.questionselenium.com/" 
  2.  If Base URL is "http://www.questionselenium.com/" and Target is "2012/09/table-of-contents-selenium-rc.html" then it opens Selenium RC page with URL "http://www.questionselenium.com/2012/09/table-of-contents-selenium-rc.html". This way you can switch between pages of same web application in your test case. 


type:  Sets the value of an input field, as though you typed it in.
     Arguments: 
            *Target -> Element locator(generally Xpath) 
            *Value -> The value to type.



verifyTitle: Will check for page title. This can be used to validate if we are in the expected webpage. Will not stop execution of test case if verification failed.
     Arguments:
            *Target -> Expected Title 

Note: 
*In the above command, we are providing expected output in target field. There are similar commands in Selenium IDE to which we pass expected output in target field. This is because the command is independent of element location and this command takes only one argument i.e., title of form text. Always remember argument 1 goes into "Target" and argument 2 goes into "Value". For commands with only one argument, argument 1 goes into "Target" field and "Value" field remains null.
*You can find title of a webpage by looking for tag <title> in it source code. Right click anywhere on a webpage and select "view source" to view source code of a webpage.

verifyText:  verifies text at specified element locator. Will not stop execution of test case if verification failed.

Arguments:
            *Target -> Element Locator
            *Value -> Expected text to be present.


verifyTextPresent: Verifies that the specified text pattern appears somewhere on the rendered page shown to the user. Will not stop execution of test case if verification failed.

Arguments:
            *Target ->Expected text to be present.
         

verifyElementPresent: Verifies element present at specified element locator. Will not stop execution of test case if verification failed.


Arguments:
            *Target ->Element Locator.



assertTitle: Will check for page title. This can be used to validate if we are in the expected webpage. Will stop execution of test case if assertion failed.
         Arguments:
                *Target -> Expected Title 


    assertText:  check for text at specified element locator. Will stop execution of test case if assertion failed.

    Arguments:
                *Target -> Element Locator
                *Value -> Expected text to be present.


    assertTextPresentCheck for the specified text pattern appears somewhere on the rendered page shown to the user. Will stop execution of test case if assertion failed.

    Arguments:
                *Target ->Expected text to be present.
             

    assertElementPresentCheck for element present at specified element locator. Will stop execution of test case if assertion failed.


    Arguments:
                *Target ->Element Locator.


    click:  Clicks on a link, button, checkbox or radio button specified as element locator in Target field.

    Arguments:
                *Target ->Element Locator.


    clickAndWaitClicks on a link, button, checkbox or radio button specified as element locator in Target field. If the click action causes a new page to load (like a link usually does), it will wait for page to load completely.


    Arguments:
                *Target ->Element Locator.


    Note:

    *The difference between a command and its "AndWait" alternative is that the regular command(ex:click) will do the action and continue with the following command as fast as it can, while the "AndWait" alternative(ex:clickAndWait) will wait until the page is loaded after the action is performed. It is always advised to use "AndWait" commands when performing operations that will result in new pages to load.

    *Default wait time is 30000ms i.e 30 seconds. You can change this value by clicking on menu item Options > Options and under General tab changing the value at field "Default time out".



    We discussed most frequently used Selenese commands but there are many more commands Selenium IDE offers a user. You can find the list of commands that Selenium IDE offers by click on command drop down (refer snapshot below)


    After you select a command from the drop down, you can also understand what the command can do by looking at "Reference" tab which populates arguments required and definition of the command. (refer snapshot below)


    Note: You can always insert a new command at any location in you test case by performing a right click at that location in test case and selecting "Insert New Command" option (refer snapshot below).


    Please look into various commands and their definitions and also try to experiment them on various web pages. This way you can master commands in Selenium IDE. Thank you.

    4 comments:

     

    QuestionSelenium Copyright @Shiva Krishna