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
- *** Settings ***
- 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:
- *** Settings ***
- Library SeleniumLibrary
- *** Variables ***
- ${url} https://www.google.com/
- *** Test Cases ***
- BrowserCommands
- Create Webdriver Chrome executable_path="C:\Driver\chromedriver.exe"
- Open Browser ${url} Chrome
- Maximize Browser Window
- ${title} Get Title
- Log To Console Title of the current page : ${title}
- ${pageSource} Get Source
- Log To Console ${pageSource}
- ${pageURL} Get Location
- Log To Console Current page URL : ${pageURL}
- Close window
Output:
- Title of the page : Google
- <html> --------------- </html>
- Current page URL : https://www.google.com/
No comments:
Post a Comment