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")