Skip to main content

UI utilities in order to abstract selenium commands

Project description

Automaton Tools module

The automaton tools module provide an abstraction of the selenium web driver through a "BrowserServer" object.

Note on documentation

The documentation is build upon the doctest's files. It includes some weird sections such as "Teardown" section: Don't be afraid is testing part ;)

Documentation is on ReadTheDocs

System requirements

This module has been developed with Python 3.7 and uses selenium version 3.14.

All code is accessible on GitHub

BrowserServer object

The BrowserServer is packaged with the webdriver-manager. You can require:

  • chrome
  • headless-chrome
  • firefox
  • edge
  • opera
  • safari (it's not managed by webdriver-manager: you have to provide the path to the webdriver)

Serve the webdriver

When everything is set you can call "serve()" method which open the browser of the specified type.

You can stop the webdriver by invoking the "close()" method.

Interacting with the browser

The main feature is unifying the way you choose to interact with the browser.

An element is described by a dictionary in which we give a type and a value.

The type is one of the following:

  • id: the element identifier,
  • name: the element name,
  • class_name: the element class name,
  • css: the element css path,
  • link_text: the link full text,
  • partial_link_text: the link partial text,
  • tag_name: the element tag name
  • xpath: the element xpath

The value contains the actual value for the type. For example an element with the "id" type must have
the id's value to be correctly defined. In the same way an element with the "tag_name" type and a value "div" may return all div on the web page.

To avoid, as much as possible, this multi-definition you can add a text dictionary key which try to locate the element with this exact text. You may find an element with an empty text so use it with care.

Although the BrowserServer class is a must have, you can use the module spaces separately. I will quickly present here only the BrowserServer class method but the module spaces functions only add a "driver" attribute which hold the selemium web driver to use.

finders

This module space is about finding and returning web element.

  • find_element(field,[web_element]): return the first element which match the criteria. Use the web_element as base element in order to find nested element.
  • find_elements(field, [web_element]): return all elements which match the criteria in a list. Use the web_element as base element in order to find nested element.
  • find_from_elements(field,text, [web_element]): return the first element which match the criteria and has the text. Use the web_element as base element in order to find nested element.

information

This module space is about retrieving data from the web page or the browser.

  • is_field_exist(field,until): return the first element which match the criteria within "until" second. Return None otherwise.
  • is_field_contains_text(field,text): return true if the field contains the text even in the value, false otherwise.
  • is_alert_present(until): return true if an alert is present within "until" second.
  • element_text(field): return the field text.
  • how_many_windows(): return the number of opened windows.
  • is_field_displayed(field): return true if the field is displayed.
  • is_field_enabled(field): return true if the field is enabled.

navigators

This module space is about browsing tag and web browsing.

  • go_to_url(url): return 0 if successful and go to the specified url.
  • enter_frame(field): return 0 if successful and enter the page frame/iframe.
  • go_to_window(handle,title): return 0 if successful and gain focus on the window defined by its handle ot its title.

alerts

This module space is about the alert popups.

  • intercept_alert(messages, accept, value): return 0 if successful. You can specify a list of message which one must be displayed on the alert, accept or reject the alert (Ok or dimiss) and enter a value where the alert prompt for a user input.
  • alert_message(): return the alert message if an alert is displayed.

actions

This module space is about filling, selecting and clicking on web element.

  • fill_element(field,value): return 0 if successful, fill the field with the value
  • fill_elements(fields, data): return 0 if successful, fill each field in the fields dictionary with the value hold in the data dictionary. You can have a larger fields dictionary than the data but each data entry must be found in the fields dictionary.
  • select_in_dropdown(field,visible_text,value): return 0 if successful, select in the field dropdown the element either described by its visible text or its hidden value.
  • click_element(field): return 0 if successful, perform a left click on the field.
  • set_checked(field,is_checked): return 0 if successful, set the check box field so that the is_checked value is always true i.e. checked if is_checked set to true and not checked if is_checked set to false.

Other documentation

Please find in the test folder doctest files which describe almost all methods here.

Moreover don't hesitate to use the python help(method/class) directly from the python console in order to access the docstring.

To Do

  • Add a multi-selection for dropdown
  • Add a drag & drop functionality
  • Add a get handles functionality

Release Notes

  • version 1.0.8:
    • add avoid_move_to option on find_element in order to retrieve an element without moving to it
    • add minor tests
  • version 1.0.7:
    • add caller_message to move_to method in order to track down issue in the logs
    • add execute_script method to BrowserServer
    • is_displayed polls every 0.2s for 10s in order to check if field is displayed
    • is_field_exist polls even with StaleElementReferenceException
    • use polling2 instead of webdriver wait where applicable
  • version 1.0.6:
    • new test server: now using flask as a test server
    • use mkdocs and the doctest test repository in order to build the documentation
    • add diver option setter
    • add a generic move_to web element method
  • version 1.0.5: Sorry for the interruption
    • use webdriver manager in order to retrieve webdrivers.
    • Enhance the webdriver handling.
    • Allow providing a WebElement to find nested element(s).
    • Enhance doctest coverage.
    • Minor refactoring
  • version 0.1: first release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

eaiautomatontools-1.0.10.tar.gz (47.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

eaiautomatontools-1.0.10-py3-none-any.whl (40.9 kB view details)

Uploaded Python 3

File details

Details for the file eaiautomatontools-1.0.10.tar.gz.

File metadata

  • Download URL: eaiautomatontools-1.0.10.tar.gz
  • Upload date:
  • Size: 47.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2

File hashes

Hashes for eaiautomatontools-1.0.10.tar.gz
Algorithm Hash digest
SHA256 6ed83a20d9ac259fcfa3d45e19711b8a96a6659dc5280d78ad6b4a657478f59e
MD5 a7fda4c18252dfb2bd72630ceacf3f21
BLAKE2b-256 faa8e4f9ae32e4a54415119dfaee8dd0891ffc92f508414f31dad850380fcdcd

See more details on using hashes here.

File details

Details for the file eaiautomatontools-1.0.10-py3-none-any.whl.

File metadata

  • Download URL: eaiautomatontools-1.0.10-py3-none-any.whl
  • Upload date:
  • Size: 40.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2

File hashes

Hashes for eaiautomatontools-1.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 a0df6c1f8b7b96bc82c32b415d7cf17f21be423603e869dfdd0a8081cc0bf6e7
MD5 181c7942fc76d45319fa37e8688b62a6
BLAKE2b-256 665817e848c4ca13c0c58b004a827ef96d0c031621540699d018a07c35834930

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page