/hylium

Lighten up your UI automation. Get Hy on Selenium.

Primary LanguageHyMIT LicenseMIT

Hylium

Lighten up your UI automation. Get Hy on Selenium.

Hylium is a Hy / Python library that uses Selenium and the power of LISP to make UI tests easier to write.

This is in an alpha state right now and should probably not be used yet.

Getting Started

Hylium assumes you have the following installed:

  • Python 3.7
  • Pipenv
  • geckodriver (the Selenium Firefox driver)

You can set it up in two ways:

  • as a library
  • using a virtual environment

Install as a library

To use this as a library, we can install it using pip.

After cloning and navigating to the directory, install hylium as a package:

pip install .

This assumes that you are in a virtual environment for the project where you want to use Hylium.

You can now (import hylium) as you would any other libary.

Virtual Environment

In order to work on this, we need to set up a virtual environment. This project uses pipenv to manage packages and virtual environments.

After cloning and navigating to the directory, install the packages and setup/use the virtual environment:

pipenv install
pipenv shell

Examples

The following are examples of setting up the browser, navigating to duckduckgo.com, searching for “Hello World”, and then closing the browser:

Using the default selector

Hylium uses the CSS selector by default:

(setv driver (start))
(navigate "https://www.duckduckgo.com")
(write "#search_form_input_homepage" "Hello World")
(click "#search_button_homepage")
(.quit driver)

Using a specified selector

Use make-element to create an element with your chosen selector.

To use the ID selector:

(setv driver (start))
(navigate "https://www.duckduckgo.com")
(write (make-element by-id "search_form_input_homepage") "Hello World")
(click (make-element by-id "search_button_homepage"))
(.quit driver)

Using page objects

Hylium can help in the creation of page objects.

Use the defelement macro to create elements on a page:

(defclass DdgHomePage [object]
  "The DuckDuckGo home page"
  (defelement search-input by-id "search_form_input_homepage")
  (defelement search-button by-id "search_button_homepage")

  (defn goto [self]
    (navigate "https://www.duckduckgo.com"))

  (defn search [self search-term]
    (write self.search-input search-term)
    (click self.search-button)))

(setv driver (start))
(setv ddg-home (DdgHomePage))
(.goto ddg-home)
(.search ddg-home "Hello World")
(.quit driver)

License

MIT