Monday, January 27, 2014

WHAT ARE THE COMPONENTS OF SELENIUM?

Selenium has following components:
  • Selenium IDE
  • Selenium Remote Control (Selenium RC)
  • Webdriver
  • Selenium Grid 

Now Selenium RC and Webdriver had merged to Selenium 2.0 to enhance the user experience of automation testing.


WHAT ARE THE SELENIUM COMMON COMMANDS?

  • open : Opens a page using a URL. 
  • click/clickAndWait  : Performs a click operation, and optionally waits for a new page to load. 
  • verifyTextPresent  : Verifies expected text is somewhere on the page. 
  • verifyElementPresent : Verifies an expected UI element, as defined by its HTML tag, is present on the page. 
  • verifyText : Verifies expected text and it’s corresponding HTML tag are present on the page. 
  • verifyTable : Verifies a table’s expected contents. 
  • waitForPageToLoad : Pauses execution until an expected new page loads. Called automatically when clickAndWait is used. 
  • waitForElementPresent : Pauses execution until an expected UI element, as defined by its HTML tag, is present on the page.

WHAT IS SELENIUM WEBDRIVER?

Descriptions of Selenium Webdriver are:
  • Selenium 2.0 is introduced as Webdriver API.
    • A enhanced solution to cross browser testing.
      • Better features for Ajax testing. 
        • Handling multiple frames, multiple browser windows, popups, and alerts.
        • Framework is very easy to build in Webdriver.


        ELEMENT LOCATORS IN SELENIUM

        ID (id) Locator: Select the element with the specified @id attribute.
        For example
        1. id=name  
        is the id locator in below html code:
        1. <input type="text" name="name" id="name" />  


        NAME (name) Locator: Select the first element with the specified @name attribute.
        For example,
        1. namename=name  
        is the name locator in below html code:
        1. <input type="text" name="name" id="name" />  


        CSS (cssSelectorSyntax) Locator: Select the element using css selectors.
        For example,
        1. css=a[href="#id3"]  
        is the css locator in below html code:
        1. <a href="#id3">Test Link 3</a>  

        DOM (javascriptExpression) Locator: Find an element using JavaScript traversal of the HTML Document Object Model. DOM locators must begin with "document.".
        For example,
        1. dom=document.forms['myForm'].myName  
        is the dom locator in below html code:
        1. <form name="myForm" id="myForm" action="#" method="post">  
        2.   
        3. <input type="text" name=" myName " id="myName" />  
        4.   
        5. </form>  


        Xpath (xpathExpression) Locator: Locate an element using an XPath expression.
        For example,
        1. xpath=//table[@id='table1']//tr[2]/td[2]  
        is the xpath locator of “link22” element in below html code:
        1. <table id="table1">  
        2.   
        3. <tbody>  
        4.   
        5. <tr><td>link11</td><td>link12</td></tr>  
        6.   
        7. <tr><td>link21</td><td>link22</td></tr>  
        8.   
        9. </tbody>  
        10.   
        11. </table>  

        ABSOLUTE XPATH LOCATOR

        This locator is start with root element.
        For example, “xpath=//table[@id='table1']/tr/td” is the absolute xpath locator for “link11” element in below html code:


        1. <table id="table1" border="1" cellspacing="10" cellpadding="10">  
        2.   
        3. <tbody>  
        4.   
        5. <tr><td>link11</td><td>link12</td></tr>  
        6.   
        7. <tr><td>link21</td><td>link22</td></tr>  
        8.   
        9. </tbody>  
        10.   
        11. </table>  

        RELATIVE XPATH LOCATOR

        This locator is start with current element.
        For example, “xpath=//td[4]” is the relative xpath locator for “link22” element in below html code:


        1. <table id="table1" border="1" cellspacing="10" cellpadding="10">  
        2.   
        3. <tbody>  
        4.   
        5. <tr><td>link11</td><td>link12</td></tr>  
        6.   
        7. <tr><td>link21</td><td>link22</td></tr>  
        8.   
        9. </tbody>  
        10.   
        11. </table>  

        XPATH LOCATOR’S EXAMPLE IN SELENIUM

        We have already learned about Xpath locator in previous posts.

        Following are different example of Xpath locator:


        1. <div class="MsoListParagraphCxSpFirst">  
        2. <table id="table1"><o:p></o:p></div>  
        3. <div class="MsoListParagraphCxSpMiddle">  
        4. <form method="POST"  
        5. action="#"><o:p></o:p></div>  
        6. <div class="MsoListParagraphCxSpMiddle">  
        7. <tbody><o:p></o:p></div>  
        8. <div class="MsoListParagraphCxSpMiddle">  
        9. <tr><td>Name: </td><td><input  
        10. type="text" id="name" size="20"></td></tr><o:p></o:p></div>  
        11. <div class="MsoListParagraphCxSpMiddle">  
        12. <tr><td>Email Address: </td><td><input  
        13. type="text" name="email" size="20"></td></tr><o:p></o:p></div>  
        14. <div class="MsoListParagraphCxSpMiddle">  
        15. <tr><td><input  
        16. type="submit" value="Submit"  
        17. class="button"></td></tr><o:p></o:p></div>  
        18. <div class="MsoListParagraphCxSpLast">  
        19. </tbody><o:p></o:p></div>  
        20. </table>  

        Xpath Locator based on id of element:
        For example,
        1. xpath=//input[@id='name']  
        is the xpath based on id for Name textbox in above html code.

        Xpath Locator based on name of element: 
        For example,
        1. xpath=//input[@name='email']  
        is the xpath based on name for Email Address textbox in above html code.

        Xpath Locator based on class of element: 
        For example,
        1. xpath=//input[@class='button']  
        is the xpath based on class for Submit button in above html code.

        Xpath Locator based on value of element: 
        For example,
        1. xpath=//input[@value='Submit ']  
        is the xpath based on value for Submit button in above html code.

        Xpath Locator based on containing text by element: 
        For example,
        1. xpath=//p[contains(text(),'Name')]  
        is the xpath based containing text for Name label in below html code.