From 8c257f4d3bc12b7244b23489fc60aa26e2a29b71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jim=20Br=C3=A4nnlund?= Date: Fri, 12 Jul 2019 10:12:58 +0200 Subject: [PATCH] Add tips and tricks section to user guide (#226) * Add tips and tricks section to user guide --- docs/conf.py | 4 ++-- docs/user_guide.rst | 27 +++++++++++++++++++++++++++ testing/conftest.py | 2 +- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 0a47b7ae..c1fc707f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -47,8 +47,8 @@ # General information about the project. project = u"pytest-selenium" -copyright = u"2015, Dave Hunt" -author = u"Dave Hunt" +copyright = u"2019, Dave Hunt" +author = u"Dave Hunt, Jim Brännlund" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the diff --git a/docs/user_guide.rst b/docs/user_guide.rst index 55b1f4a3..ab59f23f 100644 --- a/docs/user_guide.rst +++ b/docs/user_guide.rst @@ -660,6 +660,33 @@ or set the ``SELENIUM_EXCLUDE_DEBUG`` environment variable to a list of the For example, to exclude HTML, logs, and screenshots from the report, you could set ``SELENIUM_EXCLUDE_DEBUG`` to ``html:logs:screenshot``. +Tips & Tricks +************* + +Example solutions to common scenarios that sometimes gets reported as issues +to the project. + +Save screenshot to file +----------------------- + +To save a screenshot to the file system, especially when not using ``--html``, +you can place the ``pytest_selenium_capture_debug`` hook in ``conftest.py``. + +The example will create a png-file using the test name. + +.. code-block:: python + + import base64 + + + def pytest_selenium_capture_debug(item, report, extra): + for log_type in extra: + if log_type["name"] == "Screenshot": + content = base64.b64decode(log_type["content"].encode("utf-8")) + with open(item.name + ".png", "wb") as f: + f.write(content) + + .. _Jenkins CI: https://jenkins.io/ .. _using environment variables in Jenkins pipelines: https://jenkins.io/doc/pipeline/tour/environment/ .. _Firefox options API documentation: https://seleniumhq.github.io/selenium/docs/api/py/webdriver_firefox/selenium.webdriver.firefox.options.html diff --git a/testing/conftest.py b/testing/conftest.py index acf23960..351453ba 100644 --- a/testing/conftest.py +++ b/testing/conftest.py @@ -21,7 +21,7 @@ def httpserver_base_url(httpserver): @pytest.fixture(autouse=True) def testdir(request, httpserver_base_url): item = request.node - if "testdir" not in item.funcargnames: + if "testdir" not in item.fixturenames: return testdir = request.getfixturevalue("testdir")