Skip to content

Commit 090c735

Browse files
ElSnoManCarlos Kidman
andauthored
Bug fixes including Browser Version and SeleniumWire flag (#302)
Co-authored-by: Carlos Kidman <carlos@qap.dev>
1 parent 4f11020 commit 090c735

File tree

19 files changed

+1651
-362
lines changed

19 files changed

+1651
-362
lines changed

.flake8

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[flake8]
2+
extend-ignore = E203
3+
exclude =
4+
.git,
5+
__pycache__,
6+
docs/source/conf.py,
7+
old,
8+
build,
9+
dist
10+
max-complexity = 10
11+
max-line-length = 160

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ allure-report
55
test_env
66
tests/data
77
data
8-
poetry.lock
98

109
# LambdaTest
1110
.hyperexecute

.vscode/settings.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
"**/*__pycache__": true
1616
},
1717
"python.linting.enabled": true,
18-
"python.formatting.provider": "black",
19-
"workbench.iconTheme": "material-icon-theme"
18+
"flake8.args": ["--rcfile=.flake8"],
19+
"python.formatting.provider": "none",
20+
"workbench.iconTheme": "material-icon-theme",
21+
"[python]": {
22+
"editor.defaultFormatter": "ms-python.black-formatter"
23+
}
2024
}

conftest.py

Lines changed: 22 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,13 @@ def test_go_to_google(py):
2121
import copy
2222
import json
2323
import logging
24-
import os
2524
import shutil
26-
import sys
2725
from pathlib import Path
2826

2927
import allure
3028
import pytest
3129
import requests
3230
from faker import Faker
33-
from reportportal_client import RPLogger, RPLogHandler
3431

3532
from pylenium.a11y import PyleniumAxe
3633
from pylenium.config import PyleniumConfig, TestCase
@@ -49,28 +46,6 @@ def api():
4946
return requests
5047

5148

52-
@pytest.fixture(scope="session")
53-
def rp_logger(request):
54-
"""Report Portal Logger"""
55-
logger = logging.getLogger(__name__)
56-
logger.setLevel(logging.DEBUG)
57-
# Create handler for Report Portal if the service has been
58-
# configured and started.
59-
if hasattr(request.node.config, "py_test_service"):
60-
# Import Report Portal logger and handler to the test module.
61-
logging.setLoggerClass(RPLogger)
62-
rp_handler = RPLogHandler(request.node.config.py_test_service)
63-
# Add additional handlers if it is necessary
64-
console_handler = logging.StreamHandler(sys.stdout)
65-
console_handler.setLevel(logging.INFO)
66-
logger.addHandler(console_handler)
67-
else:
68-
rp_handler = logging.StreamHandler(sys.stdout)
69-
# Set INFO level for Report Portal handler.
70-
rp_handler.setLevel(logging.INFO)
71-
return logger
72-
73-
7449
@pytest.fixture(scope="session", autouse=True)
7550
def project_root() -> Path:
7651
"""The Project (or Workspace) root as a filepath.
@@ -141,9 +116,7 @@ def _load_pylenium_json(project_root, request) -> PyleniumConfig:
141116
_json = json.load(file)
142117
config = PyleniumConfig(**_json)
143118
except FileNotFoundError:
144-
logging.warning(
145-
f"The config_filepath was not found, so PyleniumConfig will load with default values. File not found: {config_filepath.absolute()}"
146-
)
119+
logging.warning(f"The config_filepath was not found, so PyleniumConfig will load with default values. File not found: {config_filepath.absolute()}")
147120
config = PyleniumConfig()
148121

149122
return config
@@ -180,6 +153,12 @@ def _override_pylenium_config_values(_load_pylenium_json: PyleniumConfig, reques
180153
# with double quotes around each key. booleans are lowercase.
181154
config.driver.capabilities = json.loads(cli_capabilities)
182155

156+
cli_wire_enabled = request.config.getoption("--wire_enabled")
157+
if cli_wire_enabled:
158+
# --wire_enabled is false unless they specify "true"
159+
wire_enabled = cli_wire_enabled.lower() == "true"
160+
config.driver.seleniumwire_enabled = wire_enabled
161+
183162
cli_wire_options = request.config.getoption("--wire_options")
184163
if cli_wire_options:
185164
# --wire_options must be in '{"name": "value", "boolean": true}' format
@@ -230,7 +209,7 @@ def pys_config(_override_pylenium_config_values) -> PyleniumConfig:
230209

231210

232211
@pytest.fixture(scope="function")
233-
def test_case(test_results_dir: Path, py_config, request) -> TestCase:
212+
def test_case(test_results_dir: Path, request) -> TestCase:
234213
"""Manages data pertaining to the currently running Test Function or Case.
235214
236215
* Creates the test-specific logger.
@@ -243,12 +222,11 @@ def test_case(test_results_dir: Path, py_config, request) -> TestCase:
243222
"""
244223
test_name = request.node.name
245224
test_result_path = test_results_dir.joinpath(test_name)
246-
py_config.driver.capabilities.update({"name": test_name})
247225
return TestCase(name=test_name, file_path=test_result_path)
248226

249227

250228
@pytest.fixture(scope="function")
251-
def py(test_case: TestCase, py_config: PyleniumConfig, request, rp_logger):
229+
def py(test_case: TestCase, py_config: PyleniumConfig, request):
252230
"""Initialize a Pylenium driver for each test.
253231
254232
Pass in this `py` fixture into the test function.
@@ -265,23 +243,16 @@ def test_go_to_google(py):
265243
# if the test failed, execute code in this block
266244
if py_config.logging.screenshots_on:
267245
screenshot = py.screenshot(str(test_case.file_path.joinpath("test_failed.png")))
268-
allure.attach(py.webdriver.get_screenshot_as_png(), "test_failed.png", allure.attachment_type.PNG)
246+
allure.attach(screenshot, "test_failed.png", allure.attachment_type.PNG)
269247

270-
with open(screenshot, "rb") as image_file:
271-
rp_logger.debug(
272-
"Test Failed - Attaching Screenshot",
273-
attachment={"name": "test_failed.png", "data": image_file, "mime": "image/png"},
274-
)
275248
elif request.node.report.passed:
276249
# if the test passed, execute code in this block
277250
pass
278251
else:
279252
# if the test has another result (ie skipped, inconclusive), execute code in this block
280253
pass
281-
except AttributeError:
282-
rp_logger.error("Unable to access request.node.report.failed, unable to take screenshot.")
283-
except TypeError:
284-
rp_logger.debug("Report Portal is not connected to this test run.")
254+
except Exception:
255+
logging.error("Failed to take screenshot on test failure.")
285256
py.quit()
286257

287258

@@ -302,7 +273,7 @@ def pyc(pyc_config: PyleniumConfig, request):
302273
# if the test has another result (ie skipped, inconclusive), execute code in this block
303274
pass
304275
except Exception:
305-
...
276+
logging.error("Failed to take screenshot on test failure.")
306277
py.quit()
307278

308279

@@ -323,7 +294,7 @@ def pys(pys_config: PyleniumConfig, request):
323294
# if the test has another result (ie skipped, inconclusive), execute code in this block
324295
pass
325296
except Exception:
326-
...
297+
logging.error("Failed to take screenshot on test failure.")
327298
py.quit()
328299

329300

@@ -354,7 +325,9 @@ def pytest_addoption(parser):
354325
default="",
355326
help="The filepath of the pylenium.json file to use (ie dev-pylenium.json)",
356327
)
357-
parser.addoption("--pylog_level", action="store", default="INFO", help="Set the logging level: 'DEBUG' | 'COMMAND' | 'INFO' | 'USER' | 'WARNING' | 'ERROR' | 'CRITICAL'")
328+
parser.addoption(
329+
"--pylog_level", action="store", default="INFO", help="Set the logging level: 'DEBUG' | 'COMMAND' | 'INFO' | 'USER' | 'WARNING' | 'ERROR' | 'CRITICAL'"
330+
)
358331
parser.addoption(
359332
"--options",
360333
action="store",
@@ -373,8 +346,12 @@ def pytest_addoption(parser):
373346
default="",
374347
help="The amount of time to wait for a page load before raising an error. Default is 0.",
375348
)
349+
parser.addoption("--extensions", action="store", default="", help='Comma-separated list of extension paths. Ex. "*.crx, *.crx"')
376350
parser.addoption(
377-
"--extensions", action="store", default="", help='Comma-separated list of extension paths. Ex. "*.crx, *.crx"'
351+
"--wire_enabled",
352+
action="store",
353+
default=False,
354+
help="Should the Wire Protocol be enabled? true | false",
378355
)
379356
parser.addoption(
380357
"--wire_options",

0 commit comments

Comments
 (0)