Closed gonza-mol closed 7 months ago
This looks like a user error, driver is none in the local conftest
Please copy and paste text, screenshots of code and tracebacks are very rude
Hey Ronny, yes sure: This is the code of one from my test:
`import time import pytest import unittest import sys import os sys.path.append(os.path.join(os.path.dirname(file),"..","..")) import HtmlTestRunner from Utils import Utils as Utils from Utils.BaseClass import BaseClass from POM.HomePage import HomePage from POM.AccordionsPage import AccordionsPage
@pytest.mark.usefixtures("test_setup") class TestAccordions(BaseClass):
def test_Accordions(self):
log = self.get_Logger()
driver = self.driver
hp = HomePage(driver)
time.sleep(1)
hp.closeCookiesWindows()
time.sleep(1)
driver.execute_script("window.scrollTo(0, 300)")
time.sleep(1)
hp.clickBtnAccordions()
ap = AccordionsPage(driver)
time.sleep(1)
ap.selectAccordion()
time.sleep(1)
assert ap.getTitleFromAccordion() == "This is an accordion item."
time.sleep(2)`
This is the code of conftest
`import time import warnings import json import pytest from Utils import Utils from selenium.common.exceptions import NoSuchElementException driver = None
def pytest_addoption(parser): parser.addoption("--browser", action="store", default="chrome")
@pytest.fixture() def test_setup(request): global driver from selenium import webdriver browser = request.config.getoption("--browser") if browser == 'chrome': driver = webdriver.Chrome("C:\Users\admin\PycharmProjects\Practice-Automation\Drivers\chromedriver.exe") elif browser == 'firefox': driver = webdriver.Firefox("C:\Users\admin\PycharmProjects\Practice-Automation\Drivers\geckodriver.exe") warnings.simplefilter('ignore', ResourceWarning)
driver.implicitly_wait(10)
driver.maximize_window()
request.cls.driver = driver
driver.get(Utils.URL)
#time.sleep(3)
#driver.switch_to.frame("framelive")
yield
driver.close()
driver.quit()
@pytest.mark.hookwrapper def pytest_runtest_makereport(item): """ Extends the PyTest Plugin to take and embed screenshot in html report, whenever test fails. :param item: """ pytest_html = item.config.pluginmanager.getplugin('html') outcome = yield report = outcome.get_result() extra = getattr(report, 'extra', [])
if report.when == 'call' or report.when == "setup":
xfail = hasattr(report, 'wasxfail')
if (report.skipped and xfail) or (report.failed and not xfail):
file_name = report.nodeid.replace("::", "_") + ".png"
_capture_screenshot(file_name)
if file_name:
html = '<div><img src="%s" alt="screenshot" style="width:304px;height:228px;" ' \
'onclick="window.open(this.src)" align="right"/></div>' % file_name
extra.append(pytest_html.extras.html(html))
report.extra = extra
def _capture_screenshot(name):
driver.get_screenshot_as_file("C:\\Users\\admin\\PycharmProjects\\Practice-Automation\\Screenshots\\"+name)`
this is the content from the BaseClass:
`import inspect import pytest from selenium.webdriver.common.by import By from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import logging
class BaseClass:
def get_Logger(self):
loggername = inspect.stack()[1][3]
logger = logging.getLogger(loggername)
fileHandler = logging.FileHandler("C:\\Users\\admin\\PycharmProjects\\Practice-Automation\\Data\\logfile.log")
formatter = logging.Formatter("%(asctime)s :%(levelname)s : %(name)s :%(message)s")
fileHandler.setFormatter(formatter)
logger.addHandler(fileHandler)
#logger = logging.FileHandler(filemode='w')
logger.setLevel(logging.DEBUG)
return logger`
and the file from the utils file, where i alocate the url:
URL = "https://practice-automation.com/"
And one of the files that i am used on the Page Object Model for this object:
`import time
from selenium.webdriver import ActionChains from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.select import Select from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as ec
class AccordionsLocators: arrowAccordion = (By.CSS_SELECTOR, "#post-1261 > div summary") titleFromAccordion = (By.CSS_SELECTOR, "#post-1261 details > div > p")
class AccordionsPage:
def __init__(self, driver):
self.driver = driver
def selectAccordion(self):
return self.driver.find_element(*AccordionsLocators.arrowAccordion).click()
def getTitleFromAccordion(self):
return self.driver.find_element(*AccordionsLocators.titleFromAccordion).text`
I have a framework with selenium and python (using pycharm), the issue was that it worked well for me, and I had to format the PC, and reinstall pycharm, python and everything necessary. And when I want to run the different projects again, it now gives me the following error and none of my tests work in any way, neither using the commands nor the interface. I have already changed all kinds of settings and I have not been able to find the error. Could you tell me if there is a solution, or if you know the problem? Python: 3.8.0 pytest 4.1.1