pytest-dev / pytest-selenium

Plugin for running Selenium with pytest
Other
335 stars 119 forks source link

extending the pytest-selenium methods? #276

Closed chillum closed 1 year ago

chillum commented 3 years ago

Hi,

I want to extend the pytest-selenium methods, but adding the new method in WebDriver class somehow doesn't work and still reports AttributeError: 'WebDriver' object has no attribute 'wait'.

I've tried to add the code in fixture override (as per docs) and just in my code.

I'm actually trying to add a method like this:

class WebDriver:
    def wait(self, func):
        WebDriverWait(self, timeout=10).until(func)

so I can use something like:

def test_something(selenium):
    selenium.find_element_by_id('navigation').click()
    selenium.wait(lambda s: s.find_element_by_link_text('Upload data').click())

Any advice for accomplishing this? Thanks

dosas commented 2 years ago

I think a better place to ask a question like this would be stack overflow.

If you look at the documentation it should be clear.

In pytest-selenium driver is selenium ;)

isaulv commented 1 year ago

You would probably want to write a fixture that wraps the driver fixture and adds your custom commands. Modifying the class is tricky under pytest can be tricky if you don't know when it's first imported.