Skip to content
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

seldom结合其他测试库比如playwright使用时,如何截图生成到测试报告中 #202

Closed
git-tree opened this issue Nov 16, 2023 · 3 comments

Comments

@git-tree
Copy link

No description provided.

@defnngj
Copy link
Collaborator

defnngj commented Nov 16, 2023

我自己试了一下是可以的,方法如下:

import seldom
import base64
from playwright.sync_api import sync_playwright
from playwright.sync_api import expect


class Playwright(seldom.TestCase):

    def start(self):
        p = sync_playwright().start()
        self.browser = p.chromium.launch()
        self.page = self.browser.new_page()

    def end(self):
        self.browser.close()

    def test_start(self):
        page = self.page
        page.goto("http://playwright.dev")
        expect(page).to_have_title("Fast and reliable end-to-end testing for modern web apps | Playwright")

        get_started = page.locator('text=Get Started')
        expect(get_started).to_have_attribute('href', '/docs/intro')
        get_started.click()

        expect(page).to_have_url('http://playwright.dev/docs/intro')
        # playwright 实现截图
        screenshot_bytes = page.screenshot()
        self.images.append(base64.b64encode(screenshot_bytes).decode())

因为没有做封装,有点麻烦而已。

image

@defnngj
Copy link
Collaborator

defnngj commented Nov 26, 2023

seldom 3.4.1 版本简化了playwright截图的使用, 直接使用self.screenshots() 方法。

        # playwright 实现截图
        screenshot_bytes = page.screenshot()
        self.screenshots(image=screenshot_bytes)

@git-tree
Copy link
Author

好的,多谢!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants