Pylenium.io
GitHub ↗️
  • Welcome to Pylenium
  • Getting Started
    • 1. Virtual Environments
    • 2. Setup pytest
    • 3. Project Structure with pytest
    • 4. Writing Tests with Pylenium
  • Guides
    • πŸ“ŠVisualize Test Results with Allure
    • πŸ“Logging
    • 🟨Run Tests in Containers
    • πŸ”€Run Tests in Parallel
    • πŸ§ͺShould / Expected Conditions
    • 🌐Script with Standalone Pylenium
  • CLI
    • πŸ’»Pylenium CLI
    • πŸ“ŠAllure CLI
  • Configuration
    • πŸ“„pylenium.json
    • πŸš—Driver
    • πŸ–₯️Viewport
  • Fixtures
    • ↗️api
    • πŸͺ“axe
    • πŸ₯Έfake
    • βœ…py
    • β˜‘οΈpyc
    • ❌pys
  • Driver Commands
    • Overview
    • πŸ—ΊοΈNavigation
      • go
      • quit
      • reload
      • visit
    • πŸ”Find Elements
      • contains
      • find
      • findx
      • get
      • getx
    • ⏱️Driver.should()
    • 🌐Browser
      • execute_script
      • execute_async_script
      • maximize_window
      • screenshot
      • scroll_to
      • title
      • url
      • window_handles
      • window_size
      • viewport
    • πŸͺCookies
      • delete_all_cookies
      • delete_cookie
      • get_all_cookies
      • get_cookie
      • set_cookie
    • πŸ”„Switch To
      • default_content
      • frame
      • frame_by_element
      • parent_frame
      • window
      • new_window
      • new_tab
    • πŸ“ŠWeb Performance
      • Performance API
      • CDP Performance
    • fake
    • wait
    • webdriver
  • Element Commands
    • πŸ”Find Elements
    • ⏱️Element.should()
    • πŸ‘Actions
      • check
      • clear
      • click
      • deselect
      • double_click
      • drag_to
      • drag_to_element
      • focus
      • hover
      • right_click
      • scroll_into_view
      • select_by_index
      • select_by_text
      • select_by_value
      • submit
      • type
      • uncheck
      • upload
    • πŸ”’Element Data
      • css_value
      • get_attribute
      • get_property
      • tag_name
      • text
      • is_checked
      • is_displayed
      • is_enabled
      • is_selected
    • πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦Family
      • children
      • parent
      • siblings
    • open_shadow_dom
    • screenshot
    • webelement
  • Elements Commands
    • ⏱️Elements.should()
    • first
    • length
    • last
    • is_empty
  • Contribute
    • Clone and Setup the Project
Powered by GitBook
On this page
  • Usage
  • Arguments
  • Yields
  • pyc_config
  • Access by Fixture
  • Access Directly (recommended)
  1. Fixtures

pyc

An instance of Pylenium for a Test Class

PreviouspyNextpys

Last updated 1 year ago

Usage

The pyc fixture is used if you want a single instance of Pylenium that is shared across tests within a Test Class.

from pylenium.driver import Pylenium

class TestSauceDemo:
    def test_land_on_products_page_after_login(self, pyc: Pylenium):
        pyc.visit("https://www.saucedemo.com/")
        pyc.get("#user-name").type("standard_user")
        pyc.get("#password").type("secret_sauce")
        pyc.get("#login-button").click()
        assert pyc.contains("Products").should().be_visible()
        
    def test_add_item_to_cart_increments_counter_by_1(self, pyc: Pylenium):
        pyc.get("[id*='add-to-cart']").click()
        assert pyc.get("a.shopping_cart_link").should().have_text("1")

Import Pylenium and add the type hint to your tests (as shown above) so you get intellisense and autocomplete when writing tests

Arguments

  • none

Yields

  • Pylenium - an instance of Pylenium driver that interacts with the web

pyc_config

When using pyc, an instance of PyleniumConfig is also created and can be managed per test class. You can access pyc_config as a fixture or directly from pyc.config

Access by Fixture

from pylenium.driver import Pylenium
from pylenium.config import PyleniumConfig

class TestSauceDemo:
    def test_land_on_products_page_after_login(self, pyc: Pylenium, pyc_config: PyleniumConfig):
        pyc_config.custom["user"] = "standard_user" # Set a value in one test...
        
        pyc.visit("https://www.saucedemo.com/")
        pyc.get("#user-name").type("standard_user")
        pyc.get("#password").type("secret_sauce")
        pyc.get("#login-button").click()
        assert pyc.contains("Products").should().be_visible()
        
    def test_add_item_to_cart_increments_counter_by_1(self, pyc: Pylenium, pyc_config: PyleniumConfig):
        print(pyc_config.custom.get("user")) # And use it in another test
        pyc.get("[id*='add-to-cart']").click()
        assert pyc.get("a.shopping_cart_link").should().have_text("1")

Access Directly (recommended)

Recommended because it's fewer lines of code and you already have access via Pylenium

from pylenium.driver import Pylenium

class TestSauceDemo:
    def test_land_on_products_page_after_login(self, pyc: Pylenium):
        pyc.config.custom["user"] = "standard_user" # Set a value in one test...
        
        pyc.visit("https://www.saucedemo.com/")
        pyc.get("#user-name").type("standard_user")
        pyc.get("#password").type("secret_sauce")
        pyc.get("#login-button").click()
        assert pyc.contains("Products").should().be_visible()
        
    def test_add_item_to_cart_increments_counter_by_1(self, pyc: Pylenium):
        print(pyc.config.custom.get("user")) # And use it in another test
        pyc.get("[id*='add-to-cart']").click()
        assert pyc.get("a.shopping_cart_link").should().have_text("1")
β˜‘οΈ
πŸ’ͺ