pytest-dev / pytest-selenium

Plugin for running Selenium with pytest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

extending the pytest-selenium methods?

chillum opened this issue · comments

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

commented

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

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.