Selenium WebDriver is a web browser automation tool. The WebDriver API allows access to Selenium's functionality through programming languages such as Python, Ruby, and Java. Selenium Harness is a homegrown framework using the Python WebDriver bindings to take advantage of Selenium's native functionality, and additionally:
- extend and customize Selenium's commands, allowing functionality beyond the web browser (e.g., FTP access, sending e-mail, accessing databases or the filesystem)
- simplify the automation process using syntax similar to Selenium IDE's output
- optimize Selenium's native commands and expedite the automation process (e.g. automatically waiting for an element to exist and become visible before attempting user interaction)
- improve performance by executing multiple test suites concurrently
- provide detailed logging of test results
- integrate with JIRA Test Cases
The following packages are required and can be installed via Pip:
- BeautifulSoup4
- selenium
To run the Selenium Python WebDriver without any parameters:
$ python run.py
Parameter | Description | Default |
---|---|---|
-h, --help | Show the help message and exit. | |
-s SUITE, --suite SUITE | Required SUITE specifies the test suite or the test suite directory. If a directory is specified, every file within the directory will be executed as a test suite. | |
-b BASE, --base BASE | BASE specifies the base URL to use. If not specified, the program will scan for the base.url file, starting with the suite directory and traversing upwards. | |
-t TIER, --tier TIER | TIER specifies the development tier to use, e.g. qa or dev. The tier may be substituted in the default base URL or utilized by custom scripts, for example when accessing XML files organized by development tier on an FTP server. | qa |
-d, --debug | Debug mode; provides verbose output. | |
-x, --xml | Loads suite file data from an XML file. Used in conjunction with the -s parameter, allowing for JIRA filter output to drive automation. |
UI maps specify a list of actions to be run for a particular page. Actions are described below:
Action | Description | Format |
---|---|---|
action_new | Create a new Action Chain | action_new |
action_move_to_element | Adds to the current Action Chain, moving the mouse to the specified element | action_move_to_element|selector|element |
action_click | Adds a mouse click the current Action Chain | action_click |
action_keys | Adds to the current Action Chain, sending a sequence of special keys (up, down, left, right) | action_keys|key1,key2,key3 |
action_perform | Performs the Action Chain | action_perform |
base_url | Change the base URL. The tier parameter can be used in the URL. For example, if the parameter --tier dev is used, base_url|http://%(tier)host.com evaluates to the base URL http://devhost.com. | base_url|URL |
clear | Clear an input's text | clear|selector|element |
clear_type | Clears an input's text then sends keys to the element | type_var|selector|element|variable |
click | Click on an element | click|selector|element |
click_all | Click all elements | click|selector|element |
delay | Delay a specified number of milliseconds | delay|milliseconds |
exec | Evaluate arbitrary Python code with access to store variables | exec|code |
find_frame | Search through all iframes for target element, switching to frame | find_frame|selector|element |
keys | Send a sequence of special keys (up, down, left, right) to a target | keys|selector|element|key1,key2,key3 |
log | Output a string | log|string |
log_var | Output a variable's value | log_var|variable |
open | Open a URL (appended to a base URL) | open|URL |
random_ssn | Generates a random Social Security Number, saving it to variable | random_ssn|variable |
select | Select an option from a select box element by visible text | select|selector|element|option |
select_by_value | Select an option from a select box element by value | select|selector|element|option |
set_window_size | Set the browser's window size, in pixels | set_window_size|width|height |
store_attribute | Store an element's attribute into a variable | store_text|selector|element|attribute|variable |
store_text | Store an element's text into a variable | store_text|selector|element|variable |
switch_to_default | Switch to the top frame (frame 0) | switch_to_default |
switch_to_frame | Switch to a frame by name or number | switch_to_frame|frame |
type | Send keys to an element | type|selector|element|keys |
type_var | Send the value of a variable to an element | type_var|selector|element|variable |
verify_text | Verify that text exists within an element | verify_text|selector|element|text |
The Selenium specific parameters, element and selector, mirror the output of Selenium's IDE.
selector Specifies the method used to select an element. Selector must be one of the following values:
- id
- css
- xpath element Describes the element to target using the specified selector.
# sends the keys "03032022" to an element with the ID "expirationDate":
type|id|expirationDate|03032022
# clicks on a button, located using xpath selector:
click|xpath|//input[@value='Continue']
# clicks on a button, located using the css selector:
click|css|#accord-2 > div.accord-content.padded > div.accord-controls.padded > input.accord-button-next
# stores the value of an input into a variable:
store_attribute|id|__o3id0|value|REFERENCE_NUMBER
# use an Action Chain to click on an element and send arrow keys:
action_new
action_move_to_element|xpath|/html/body/div/span/ span
action_click
action_keys|down,down,down,return
action_perform
For more information, check out Locating UI Elements section in the WebDriver documentation.
- open_base: Open a URL without appending to the base URL
- is_hidden
- is_visible
- assert: Assert the return value of a boolean action