Comments (2)
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
from pytest.
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 = webdriver.Chrome("C:\Users\admin\PycharmProjects\SegundoProyecto\Drivers\chromedriver.exe")
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(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
#ver si en esta clase base esta anotación de pytest.mark va también, porque ya la estamos usando en la clase
que contiene el test. Por lo tanto dentro de la clase del Test, lo único que hay que hacer es llamar
a esta clase base, para que pueda usar estos métodos heredados
#@pytest.mark.usefixtures("test_setup")
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`
from pytest.
Related Issues (20)
- 8.1.1 raises exception if `boto` is imported in environment HOT 3
- Pytest-watch with coverage (If not existent) HOT 1
- List of disabled plugins is not passed down to `runpytest()`
- Sporadically encountering SyntaxError HOT 7
- No output written to JUnit XML files
- AttributeError with import-mode importlib and doctest modules HOT 7
- log-disable as pytest.ini configuration option does not have any effect HOT 3
- Pytest keeps reference to attributes of failed test cases for too long HOT 4
- Conditional test parametrization HOT 3
- tmp_path_factory documentation has circular links HOT 3
- Pytest does not capture teardown logs if a fixture throws an exception
- ExceptionGroup traceback of session fixture unlimitedly grows from test to test HOT 1
- Missing `py.process` HOT 2
- 8.2.0 release planning
- Adding parameterized fixture in pytest_generate_test is not executing the fixture's code, even if it is marked as "indirect"
- setUpModule/tearDownModule not invoked HOT 4
- junit-xml output attribute can be too big to handle with -vv
- More granular scripting interface HOT 4
- support an alternate syntax for "not" (as in `pytest -m "not stuff"`) HOT 6
- Documentation request: types/shapes of options in `[tool.pytest.ini_options]` HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pytest.