SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.77k stars 8.2k forks source link

[🐛 Bug]: Unable to access methods of WebDriver class when the WebDriver instance is passed to test class from conftest.py #14340

Open Shipinpk opened 3 months ago

Shipinpk commented 3 months ago

What happened?

Not getting any suggestion regarding the webdriver in test class. ( Both in pycharm and vscode ) The code is working fine but its very difficult to type all the code manually without giving the suggestions.

How can we reproduce the issue?

Created conftest.py

code :
import pytest
from selenium import webdriver

@pytest.fixture(scope="class", autouse=True)
def driverInit(request):
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.implicitly_wait(10)
    driver.get("https://opensource-demo.orangehrmlive.com/web/index.php/auth/login")
    request.cls.driver = driver
    yield
    driver.close

Test class file

Code :

import pytest
from selenium.webdriver.common.by import By

@pytest.mark.usefixtures("driverInit")
class TestOne:

    def test_loginScenario(self):
        self.driver.find_element(By.XPATH, "//input[@name='username']").send_keys("Admin")
        self.driver.find_element(By.XPATH, "//input[@name='password']").send_keys("admin")
        self.driver.

here after the self.driver. no suggestion?

Details : 
pycharm community edition Version: 2024.1.4
python version : Python 3.12.4
pytest version : pytest 8.3.2

Relevant log output

No suggestions for webdriver is showing in test class level

Operating System

windows

Selenium version

4.23.0

What are the browser(s) and version(s) where you see this issue?

Chrome and firefox

What are the browser driver(s) and version(s) where you see this issue?

Chrome Version 127.0.6533.89 (Official Build) (64-bit)

Are you using Selenium Grid?

No response

github-actions[bot] commented 3 months ago

@Shipinpk, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

diemol commented 3 months ago

I am not able to reproduce. Can you share a complete project so we can check it?

Also, how come it works for the first two find_element and not anymore?

Shipinpk commented 3 months ago

PythonVsCode.zip Hi @diemol The issue is am not getting any suggestions after self.driver. ? The above 2 lines of code were written manually without any suggestions. Note : The execution is working fine no issue for that

But according to the suggestion of self.driver. is the probelm. In future we have to write a lots of code, so without suggestion or auto completion manually writing all the codes like find_element is very difficult and it will leads to make confusion.

Here I attached a sample code for this. Please let me know if you need more details.

shbenzer commented 2 months ago

Would this not be an IDE issue? I'm not 100% sure what can even be done from this end.

Shipinpk commented 2 months ago

Tried with VScode and pycharm edition, the same issue is still there irrespective of IDE. So its not an IDE issue