Skip to content

eXamadeus-zz/selenium-harness

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Selenium Harness

Overview

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

Dependencies

The following packages are required and can be installed via Pip:

  • BeautifulSoup4
  • selenium

Execution

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.

Actions

UI maps specify a list of actions to be run for a particular page. Actions are described below:

ActionDescriptionFormat
action_newCreate a new Action Chainaction_new
action_move_to_elementAdds to the current Action Chain, moving the mouse to the specified elementaction_move_to_element|selector|element
action_clickAdds a mouse click the current Action Chainaction_click
action_keysAdds to the current Action Chain, sending a sequence of special keys (up, down, left, right)action_keys|key1,key2,key3
action_performPerforms the Action Chainaction_perform
base_urlChange 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
clearClear an input's textclear|selector|element
clear_typeClears an input's text then sends keys to the elementtype_var|selector|element|variable
clickClick on an elementclick|selector|element
click_allClick all elementsclick|selector|element
delayDelay a specified number of millisecondsdelay|milliseconds
execEvaluate arbitrary Python code with access to store variablesexec|code
find_frameSearch through all iframes for target element, switching to framefind_frame|selector|element
keysSend a sequence of special keys (up, down, left, right) to a targetkeys|selector|element|key1,key2,key3
logOutput a stringlog|string
log_varOutput a variable's valuelog_var|variable
openOpen a URL (appended to a base URL)open|URL
random_ssnGenerates a random Social Security Number, saving it to variablerandom_ssn|variable
selectSelect an option from a select box element by visible textselect|selector|element|option
select_by_valueSelect an option from a select box element by valueselect|selector|element|option
set_window_sizeSet the browser's window size, in pixelsset_window_size|width|height
store_attributeStore an element's attribute into a variablestore_text|selector|element|attribute|variable
store_textStore an element's text into a variablestore_text|selector|element|variable
switch_to_defaultSwitch to the top frame (frame 0)switch_to_default
switch_to_frameSwitch to a frame by name or numberswitch_to_frame|frame
typeSend keys to an elementtype|selector|element|keys
type_varSend the value of a variable to an elementtype_var|selector|element|variable
verify_textVerify that text exists within an elementverify_text|selector|element|text

Element and Selector

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.

Examples

# 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.

Actions to Consider Adding

  • open_base: Open a URL without appending to the base URL
  • is_hidden
  • is_visible
  • assert: Assert the return value of a boolean action

About

Selenium Test Harness using Selenium WebDriver's Python API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%