Skip to content

Show extras with screenshot for passed tests as well #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
shat00n opened this issue Jul 14, 2015 · 13 comments
Closed

Show extras with screenshot for passed tests as well #11

shat00n opened this issue Jul 14, 2015 · 13 comments
Assignees
Labels
bug This issue/PR relates to a bug.

Comments

@shat00n
Copy link

shat00n commented Jul 14, 2015

Hi, Dave!
Is it possible to show a screenshots for the passed tests as well?
This is my code:

def pytest_runtest_makereport(__multicall__, item):
    _driver = item.funcargs['app'].driver
    browser_type = _driver.capabilities['browserName']
    pytest_html = item.config.pluginmanager.getplugin('html')
    report = __multicall__.execute()
    extra = getattr(report, 'extra', [])
    if report.when == 'call':
        url = _driver.current_url
        extra.append(pytest_html.extras.url(url))
        screenshot = _driver.get_screenshot_as_base64()
        extra.append(pytest_html.extras.image(screenshot, ''))
        report.extra = extra
    return report

Both passed and failed tests has an URL field,
however, only failed tests are displayed with screenshot.

BR and thanks for the great plugin :)
Michael

@davehunt
Copy link
Collaborator

Are you using the latest version (1.3.1)? I fixed this in davehunt@0940097 so any extra content is shown, regardless of the result.

@shat00n
Copy link
Author

shat00n commented Jul 18, 2015

Hi Dave,
Yes, I saw this commit and I'm using the latest version:
pip freeze | grep pytest-html
pytest-html==1.3.1

I'm working on:
Python 3.4.3 -- py-1.4.30 -- pytest-2.7.2

Regards,
Michael

On Thu, Jul 16, 2015 at 4:31 PM, Dave Hunt [email protected] wrote:

Are you using the latest version (1.3.1)? I fixed this in 0940097
davehunt@0940097
so any extra content is shown, regardless of the result.


Reply to this email directly or view it on GitHub
https://github.com/davehunt/pytest-html/issues/11#issuecomment-121956144
.

@davehunt
Copy link
Collaborator

I also updated all of the tests for the plugin that send extras to the report to pass, and they appear to be okay. Can you try running from the master branch instead of PyPI to see if that fixes it for you? Also, perhaps try fully uninstalling the plugin or creating a fresh virtual environment. I've had issues before when two versions of the same package have been installed, and pip freeze shows the latest one but not the one being used.

@shat00n
Copy link
Author

shat00n commented Jul 24, 2015

Hi,
Thanks for suggestoins, I've tried both (virtual env and plugin from
master), without success though.
I noticed then, when I'm opening a report, all screenshots appear for a
half second and then disappear except the one for failed test.

It seems like plugin does save a screenshot for the passed tests, but
"extra" table is not displayed for them.

Here is a test report https://www.dropbox.com/s/113sq9n4pndtevq/report.html
generated by 2 tests:

class TestExtra:
    def test_1(self, app):
        app.page.get_url('http://google.com')
        assert True

    def test_2(self, app):
        app.page.get_url('http://google.com')
        assert False

So first one always passes, the second one always fails.
If you take a look on html code of the report, you'll find that both tests
have a screenshot: [HTML REMOVED]

But only second one is displayed.

Can you please maybe share your example of pytest_runtest_makereport ?

Thanks a lot,
Michael

On Mon, Jul 20, 2015 at 1:25 PM, Dave Hunt [email protected] wrote:

I also updated all of the tests for the plugin that send extras to the
report to pass, and they appear to be okay. Can you try running from the
master branch instead of PyPI to see if that fixes it for you? Also,
perhaps try fully uninstalling the plugin or creating a fresh virtual
environment. I've had issues before when two versions of the same package
have been installed, and pip freeze shows the latest one but not the one
being used.


Reply to this email directly or view it on GitHub
https://github.com/davehunt/pytest-html/issues/11#issuecomment-122842059
.

@davehunt
Copy link
Collaborator

I've removed the HTML from your comment as it made it impossible to read. This does look like a genuine bug in the CSS. See https://github.com/davehunt/pytest-html/blob/master/pytest_html/resources/style.css#L110 could you perhaps try removing that line and see how it looks?

@davehunt davehunt added bug This issue/PR relates to a bug. help wanted labels Jul 24, 2015
@shat00n
Copy link
Author

shat00n commented Jul 24, 2015

Sorry for HTML, I've replied from google without checking how it looks like on git.
Anyway, I removed line 110-113:

/*if the result is passed or xpassed don't show extra row*/
.passed + .extra, .xpassed + .extra {
    display: none;
}

But the result is the same - https://www.dropbox.com/s/vix2fio7gllhf89/report_L110.html

I'm not familiar with js,
but I found the following code in my html report:

function split_extra_onto_two_rows() {
    find_all('tr.results-table-row').forEach(function(elem) {
        var new_row = document.createElement("tr")
        new_row.className = "extra";
        elem.parentNode.insertBefore(new_row, elem.nextSibling);
        find_all(".extra", elem).forEach(function (td_elem) {
            if (find(".log", td_elem)) {
                new_row.appendChild(td_elem);
                td_elem.colSpan=5;
            } else {
                td_elem.parentNode.removeChild(td_elem);
            }
        });
    });
}

If I understand it properly,
Since passed result does not have a .log, so empty td class created instead of two rows with log and picture?

@shat00n
Copy link
Author

shat00n commented Jul 24, 2015

Well,
All pictures are displayed regardless result after removing

/*if the result is passed or xpassed don't show extra row*/
.passed + .extra, .xpassed + .extra {
    display: none;
}

And replacing

function split_extra_onto_two_rows() {
    find_all('tr.results-table-row').forEach(function(elem) {
        var new_row = document.createElement("tr")
        new_row.className = "extra";
        elem.parentNode.insertBefore(new_row, elem.nextSibling);
        find_all(".extra", elem).forEach(function (td_elem) {
            if (find(".log", td_elem)) {
                new_row.appendChild(td_elem);
                td_elem.colSpan=5;
            } else {
                td_elem.parentNode.removeChild(td_elem);
            }
        });
    });
}

By

function split_extra_onto_two_rows() {
    find_all('tr.results-table-row').forEach(function(elem) {
        var new_row = document.createElement("tr")
        new_row.className = "extra";
        elem.parentNode.insertBefore(new_row, elem.nextSibling);
        find_all(".extra", elem).forEach(function (td_elem) {
                new_row.appendChild(td_elem);
                td_elem.colSpan=5;
        });
    });
}

@davehunt
Copy link
Collaborator

Okay, I'll take this and see if I can get it fixed today. Thanks for the details.

@davehunt davehunt self-assigned this Jul 24, 2015
davehunt added a commit that referenced this issue Jul 24, 2015
@davehunt
Copy link
Collaborator

@shat00n could you try installing from the issue11 branch and let me know if this solves it for you?

@shat00n
Copy link
Author

shat00n commented Jul 25, 2015

Hi,
Yeap when using branch 11, all screenshots are displayed regardless test result with "No log output captured." as a log message
And also putting extra.append(pytest_html.extras.image(screenshot, ''))
under if (report.skipped and xfail) or (report.failed and not xfail): works as before - shows a screenshot only for failed tests.

Thanks!

@davehunt
Copy link
Collaborator

Great, thanks! I'll merge this and make a release.

@davehunt
Copy link
Collaborator

@frimmy
Copy link

frimmy commented Jan 16, 2016

ahh --- this thread is helpful for issue #26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug.
Projects
None yet
Development

No branches or pull requests

3 participants