pyleniumio


Namepyleniumio JSON
Version 1.21.0 PyPI version JSON
download
home_pageNone
SummaryThe best of Selenium and Cypress in a single Python Package
upload_time2024-05-24 23:23:15
maintainerNone
docs_urlNone
authorCarlos
requires_python>=3.8.1
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Pylenium: Easy Python Web Test Automation

- [The Mission](#the-mission-is-simple)
    - [Test Example](#test-example)
    - [Purpose](#purpose)
- [Quickstart](#quick-start)
    - [1. Install](#1-install-pyleniumio)
    - [2. Initialize](#2-initialize-pylenium)
    - [3. Write a Test](#3-write-a-test)
    - [4. Run the Test](#4-run-the-test)
- [Contribute](#contribute)


## The mission is simple

> Bring the best of Selenium, Cypress and Python into one package.

This means:

* Automatic waiting and synchronization
* Quick setup to start writing tests
* Easy to use and clean syntax for amazing readability and maintainability
* Automatic driver installation so you don't need to manage drivers
* Leverage the awesome Python language
* and more!

### Test Example

Although Pylenium is a thin wrapper of Selenium, let's use this simple scenario to show the difference between using `Selenium` and `Pylenium`:

1. **Visit** the QA at the Point website: [https://qap.dev](https://qap.dev/)
2. **Hover** the About link to reveal a menu
3. **Click** the Leadership link in that menu
4. **Assert** Carlos Kidman is on the Leadership page

```python
def test_carlos_is_on_leadership(py):
    py.visit('https://qap.dev')
    py.get('a[href="/about"]').hover()
    py.get('a[href="/leadership"][class^="Header-nav"]').click()
    assert py.contains('Carlos Kidman')
```

```python
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait

# define your setup and teardown fixture
@pytest.fixture
def driver():
    driver = webdriver.Chrome()
    yield driver
    driver.quit()


def test_carlos_is_on_leadership_page_with_selenium(driver):
    wait = WebDriverWait(driver, timeout=10)
    driver.get('https://qap.dev')

    # hover About link
    about_link = driver.find_element(By.CSS_SELECTOR, "a[href='/about']")
    actions = ActionChains(driver)
    actions.move_to_element(about_link).perform()

    # click Leadership link in About menu
    wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "a[href='/leadership'][class^='Header-nav']"))).click()

    # check if 'Carlos Kidman' is on the page
    assert wait.until(lambda _: driver.find_element(By.XPATH, "//*[contains(text(), 'Carlos Kidman')]"))
```

### Purpose

I teach courses and do trainings for both **Selenium** and **Cypress**, but Selenium, out of the box, _feels_ clunky. When you start at a new place, you almost always need to "setup" the framework from scratch all over again. Instead of getting right to creating meaningful tests, you end up spending most of your time building a custom framework, maintaining it, and having to teach others to use it.

Also, many people blame Selenium for bad or flaky tests. This usually tells me that they have yet to experience someone that truly knows how to make Selenium amazing! This also tells me that they are not aware of the usual root causes that make Test Automation fail:

* Poor programming skills, test design and practices
* Flaky applications
* Complex frameworks

What if we tried to get the best from both worlds and combine it with an amazing language?

**Selenium** has done an amazing job of providing W3C bindings to many languages and makes scaling a breeze.

**Cypress** has done an amazing job of making the testing experience more enjoyable - especially for beginners.

**Pylenium** looks to bring more Cypress-like bindings and techniques to Selenium \(like automatic waits\) and still leverage Selenium's power along with the ease-of-use and power of **Python**.

## Quick Start

The [Official Pylenium Docs](https://elsnoman.gitbook.io/pylenium) are the best place to start, but you can quickly get going with the following steps:

### 1. Install **pyleniumio**

```python
pip install pyleniumio

---or---

pipenv install pyleniumio

---or---

poetry add pyleniumio
```

### 2. Initialize Pylenium

```bash
# execute at your Project Root
pylenium init
```

This creates three files:

* `conftest.py` - This has the fixtures needed for Pylenium
* `pylenium.json` - This is the config file for Pylenium
* `pytest.ini` - This is the config file for pytest

By default, Pylenium uses the Chrome browser. You have to install Chrome or update the `pylenium.json` file to use the browser of your choice.

### 3. Write a test

Create a directory called `tests` and then a test file called `test_google.py`

Define a new test called `test_google_search`

```python
def test_google_search(py)
```

Pylenium uses **pytest** as the Test Framework. You only need to pass in `py`to the function!

Now we can use **Pylenium Commands** to interact with the browser.

```python
def test_google_search(py):
    py.visit('https://google.com')
    py.get("[name='q']").type('puppies')
    py.get("[name='btnK']").submit()
    assert py.should().contain_title('puppies')
```

### 4. Run the Test

This will depend on your IDE, but you can always run tests from the CLI:

```bash
python -m pytest tests/test_google.py
```

You're all set! You should see the browser open and complete the commands we had in the test :\)

## Contribute

Pylenium uses [Gitpod](https://gitpod.io/) to make it easy to work on it from the _desktop or browser_ without having to worry about the setup like having the correct Python version installed after cloning the repo.

> ๐Ÿ’ก With a single click, you can open the repo in your browser, make your changes, then submit a pull request!

0. If you're new to Gitpod, check out their [Getting Started](https://www.gitpod.io/docs/introduction/getting-started) docs to see how to use it
1. Visit [Pylenium's repo](https://github.com/ElSnoMan/pyleniumio) and click the `Gitpod` button to open the repo in a VS Code browser window
2. Wait for Gitpod to set up the project. You'll see things get setup from the various `.gitpod*` files at the Project Root
3. Once complete, create a new branch and start making your changes
4. When ready, submit a Pull Request!
5. Reviewers will see your CI pipeline and even be able to open your Gitpod instance if needed - making collaboration much easier
6. Gitpod instances are ephemeral, so you can create, share, and delete them as needed

> ๐Ÿงช By default, UI tests executed in Gitpod are headless. If you'd like to see UI tests run, open port `6080` from the bottom right corner of VS Code.

For more details and other ways to contribute to Pylenium, visit the [CONTRIBUTING.md](/CONTRIBUTING.md) doc ๐Ÿ‘€


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pyleniumio",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8.1",
    "maintainer_email": null,
    "keywords": null,
    "author": "Carlos",
    "author_email": "carlos@qap.dev",
    "download_url": "https://files.pythonhosted.org/packages/19/7e/e1b56d48db30c0d68cb0082c005a0c184e33d6ff5b630a13f7b47a51db38/pyleniumio-1.21.0.tar.gz",
    "platform": null,
    "description": "# Pylenium: Easy Python Web Test Automation\n\n- [The Mission](#the-mission-is-simple)\n    - [Test Example](#test-example)\n    - [Purpose](#purpose)\n- [Quickstart](#quick-start)\n    - [1. Install](#1-install-pyleniumio)\n    - [2. Initialize](#2-initialize-pylenium)\n    - [3. Write a Test](#3-write-a-test)\n    - [4. Run the Test](#4-run-the-test)\n- [Contribute](#contribute)\n\n\n## The mission is simple\n\n> Bring the best of Selenium, Cypress and Python into one package.\n\nThis means:\n\n* Automatic waiting and synchronization\n* Quick setup to start writing tests\n* Easy to use and clean syntax for amazing readability and maintainability\n* Automatic driver installation so you don't need to manage drivers\n* Leverage the awesome Python language\n* and more!\n\n### Test Example\n\nAlthough Pylenium is a thin wrapper of Selenium, let's use this simple scenario to show the difference between using `Selenium` and `Pylenium`:\n\n1. **Visit** the QA at the Point website: [https://qap.dev](https://qap.dev/)\n2. **Hover** the About link to reveal a menu\n3. **Click** the Leadership link in that menu\n4. **Assert** Carlos Kidman is on the Leadership page\n\n```python\ndef test_carlos_is_on_leadership(py):\n    py.visit('https://qap.dev')\n    py.get('a[href=\"/about\"]').hover()\n    py.get('a[href=\"/leadership\"][class^=\"Header-nav\"]').click()\n    assert py.contains('Carlos Kidman')\n```\n\n```python\nfrom selenium import webdriver\nfrom selenium.webdriver.common.action_chains import ActionChains\nfrom selenium.webdriver.common.by import By\nfrom selenium.webdriver.support import expected_conditions as EC\nfrom selenium.webdriver.support.wait import WebDriverWait\n\n# define your setup and teardown fixture\n@pytest.fixture\ndef driver():\n    driver = webdriver.Chrome()\n    yield driver\n    driver.quit()\n\n\ndef test_carlos_is_on_leadership_page_with_selenium(driver):\n    wait = WebDriverWait(driver, timeout=10)\n    driver.get('https://qap.dev')\n\n    # hover About link\n    about_link = driver.find_element(By.CSS_SELECTOR, \"a[href='/about']\")\n    actions = ActionChains(driver)\n    actions.move_to_element(about_link).perform()\n\n    # click Leadership link in About menu\n    wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, \"a[href='/leadership'][class^='Header-nav']\"))).click()\n\n    # check if 'Carlos Kidman' is on the page\n    assert wait.until(lambda _: driver.find_element(By.XPATH, \"//*[contains(text(), 'Carlos Kidman')]\"))\n```\n\n### Purpose\n\nI teach courses and do trainings for both **Selenium** and **Cypress**, but Selenium, out of the box, _feels_ clunky. When you start at a new place, you almost always need to \"setup\" the framework from scratch all over again. Instead of getting right to creating meaningful tests, you end up spending most of your time building a custom framework, maintaining it, and having to teach others to use it.\n\nAlso, many people blame Selenium for bad or flaky tests. This usually tells me that they have yet to experience someone that truly knows how to make Selenium amazing! This also tells me that they are not aware of the usual root causes that make Test Automation fail:\n\n* Poor programming skills, test design and practices\n* Flaky applications\n* Complex frameworks\n\nWhat if we tried to get the best from both worlds and combine it with an amazing language?\n\n**Selenium** has done an amazing job of providing W3C bindings to many languages and makes scaling a breeze.\n\n**Cypress** has done an amazing job of making the testing experience more enjoyable - especially for beginners.\n\n**Pylenium** looks to bring more Cypress-like bindings and techniques to Selenium \\(like automatic waits\\) and still leverage Selenium's power along with the ease-of-use and power of **Python**.\n\n## Quick Start\n\nThe [Official Pylenium Docs](https://elsnoman.gitbook.io/pylenium) are the best place to start, but you can quickly get going with the following steps:\n\n### 1. Install **pyleniumio**\n\n```python\npip install pyleniumio\n\n---or---\n\npipenv install pyleniumio\n\n---or---\n\npoetry add pyleniumio\n```\n\n### 2. Initialize Pylenium\n\n```bash\n# execute at your Project Root\npylenium init\n```\n\nThis creates three files:\n\n* `conftest.py` - This has the fixtures needed for Pylenium\n* `pylenium.json` - This is the config file for Pylenium\n* `pytest.ini` - This is the config file for pytest\n\nBy default, Pylenium uses the Chrome browser. You have to install Chrome or update the `pylenium.json` file to use the browser of your choice.\n\n### 3. Write a test\n\nCreate a directory called `tests` and then a test file called `test_google.py`\n\nDefine a new test called `test_google_search`\n\n```python\ndef test_google_search(py)\n```\n\nPylenium uses **pytest** as the Test Framework. You only need to pass in `py`to the function!\n\nNow we can use **Pylenium Commands** to interact with the browser.\n\n```python\ndef test_google_search(py):\n    py.visit('https://google.com')\n    py.get(\"[name='q']\").type('puppies')\n    py.get(\"[name='btnK']\").submit()\n    assert py.should().contain_title('puppies')\n```\n\n### 4. Run the Test\n\nThis will depend on your IDE, but you can always run tests from the CLI:\n\n```bash\npython -m pytest tests/test_google.py\n```\n\nYou're all set! You should see the browser open and complete the commands we had in the test :\\)\n\n## Contribute\n\nPylenium uses [Gitpod](https://gitpod.io/) to make it easy to work on it from the _desktop or browser_ without having to worry about the setup like having the correct Python version installed after cloning the repo.\n\n> \ud83d\udca1 With a single click, you can open the repo in your browser, make your changes, then submit a pull request!\n\n0. If you're new to Gitpod, check out their [Getting Started](https://www.gitpod.io/docs/introduction/getting-started) docs to see how to use it\n1. Visit [Pylenium's repo](https://github.com/ElSnoMan/pyleniumio) and click the `Gitpod` button to open the repo in a VS Code browser window\n2. Wait for Gitpod to set up the project. You'll see things get setup from the various `.gitpod*` files at the Project Root\n3. Once complete, create a new branch and start making your changes\n4. When ready, submit a Pull Request!\n5. Reviewers will see your CI pipeline and even be able to open your Gitpod instance if needed - making collaboration much easier\n6. Gitpod instances are ephemeral, so you can create, share, and delete them as needed\n\n> \ud83e\uddea By default, UI tests executed in Gitpod are headless. If you'd like to see UI tests run, open port `6080` from the bottom right corner of VS Code.\n\nFor more details and other ways to contribute to Pylenium, visit the [CONTRIBUTING.md](/CONTRIBUTING.md) doc \ud83d\udc40\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "The best of Selenium and Cypress in a single Python Package",
    "version": "1.21.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a59a20011a03a110ec57d0a11b0ecc196f3a43d5cf78e35514d42a972d4ed90c",
                "md5": "b4049c2fadae803137294328a628ed51",
                "sha256": "5b7932c7bbd5a7cb4f519126ccc261f8b5867cc25126199c64795a5efc7c84d4"
            },
            "downloads": -1,
            "filename": "pyleniumio-1.21.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b4049c2fadae803137294328a628ed51",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8.1",
            "size": 40698,
            "upload_time": "2024-05-24T23:23:13",
            "upload_time_iso_8601": "2024-05-24T23:23:13.508514Z",
            "url": "https://files.pythonhosted.org/packages/a5/9a/20011a03a110ec57d0a11b0ecc196f3a43d5cf78e35514d42a972d4ed90c/pyleniumio-1.21.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "197ee1b56d48db30c0d68cb0082c005a0c184e33d6ff5b630a13f7b47a51db38",
                "md5": "7a1aaed68d970c917a526b58b5082725",
                "sha256": "496cf46448e2122f44227a55dde5ee9206b56b0f46ffb92d017da2ad44dd3dd4"
            },
            "downloads": -1,
            "filename": "pyleniumio-1.21.0.tar.gz",
            "has_sig": false,
            "md5_digest": "7a1aaed68d970c917a526b58b5082725",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8.1",
            "size": 36638,
            "upload_time": "2024-05-24T23:23:15",
            "upload_time_iso_8601": "2024-05-24T23:23:15.599468Z",
            "url": "https://files.pythonhosted.org/packages/19/7e/e1b56d48db30c0d68cb0082c005a0c184e33d6ff5b630a13f7b47a51db38/pyleniumio-1.21.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-24 23:23:15",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "pyleniumio"
}
        
Elapsed time: 4.60113s