Your ultimate guide

Robot Framework SeleniumLibrary - Browser Keywords

SeleniumLibrary:
  • SeleniumLibrary is a web testing library for Robot Framework.
  • SeleniumLibrary uses the Selenium WebDriver modules internally to control a web browser.
  • Currently, Selenium Library provides 177 Keywords. Every keyword has one specific action.
  • To use this library in the robot framework script we need to import it. In the robot framework libraries are implemented in the *** settings *** section.
    • Syntax: for importing in the selenium library
      1. *** Settings ***
      2. Library SeleniumLibrary


Browser Keywords:

Create Webdriver: 
  • It Creates an instance of Selenium WebDriver. By this, we can give the location of the Webdriver.
  • This keyword should only be used if provided by Open Browser.
  • driver_name must be a WebDriver implementation name like Chrome, Firefox, Edge, Safari, or Remote.
  • If the WebDriver is configured in a "Python_installed_location/Scripts" folder, there is no need to use the "Create Webdriver" function.
    Syntax: 
    Create Webdriver        driver_name        executable_path="path to the webdriver"

    Example:
    Create Webdriver        Chrome        executable_path="C:\Driver\chromedriver.exe"



Open Browser: This keyword helps to open a URL in a specific Browser.
    Syntax: 
            Open Browser        URL        Browser_Name(Chrome/Firefox/Edge/Safari)
    Example: 
            Open Browser        http://example.com        Chrome



Maximize Browser Window: It maximizes the current browser window.



Get Title: Returns the Title of the Current page.



Get Source: Returns the entire HTML source code of the current page.



Get Location: Returns the Current Bowser window URL.



Close Window: Close the currently opened and selected browser window/tab.



Close Browser: Close the current browser.



Close All Browser: Closes all open browsers.



Example Program:
  1. *** Settings ***
  2. Library       SeleniumLibrary

  3. *** Variables ***
  4. ${url}       https://www.google.com/

  5. *** Test Cases ***
  6. BrowserCommands
  7.        Create Webdriver       Chrome    executable_path="C:\Driver\chromedriver.exe"
  8.        Open Browser       ${url}       Chrome

  9.        Maximize Browser Window

  10.        ${title}       Get    Title
  11.        Log To Console       Title of the current page : ${title}

  12.        ${pageSource}       Get    Source
  13.        Log To Console       ${pageSource}

  14.        ${pageURL}       Get    Location
  15.        Log To Console       Current page URL : ${pageURL}

  16.        Close window
Output:
  1. Title of the page : Google
  2. <html> --------------- </html>
  3. Current page URL : https://www.google.com/

No comments:

Post a Comment