了解启动 Playwright 时的 With-As 命令

发布于 2025-01-10 20:07:21 字数 995 浏览 0 评论 0原文

在与 Selenium + RobotFW 合作多年后,我正在尝试将 Playwright 和 RobotFW 集成在一起。

我的测试用例非常简单:

TEST_1 Check correctness of showing Login screen
    [Tags]   ui     automated
    Go to login screen normally

我定义了关键字如下:

with sync_playwright() as p:
    browser = p.chromium.launch()

@keyword('Go to login screen normally')
def go_to_login_screen_normally():
    page = browser.new_page()
    page.goto("https://my.page.com/login")
    print(page.title())
    browser.close()

但它总是返回错误 Event Loop is close

但是,这个有效:

@keyword('Go to login screen normally')
def go_to_login_screen_normally():
    with sync_playwright() as p:
        browser = p.chromium.launch()
        page = browser.new_page()
        page.goto("https://my.page.com/login")
        print(page.title())
        browser.close()

意味着我必须将 With > 进入函数部分。

我尝试跳过 With-As 但它不起作用。

感谢您的建议!

I'm trying to integrate Playwright and RobotFW together after spending years working with Selenium + RobotFW.

My test case is very simple:

TEST_1 Check correctness of showing Login screen
    [Tags]   ui     automated
    Go to login screen normally

I defined the keyword as below:

with sync_playwright() as p:
    browser = p.chromium.launch()

@keyword('Go to login screen normally')
def go_to_login_screen_normally():
    page = browser.new_page()
    page.goto("https://my.page.com/login")
    print(page.title())
    browser.close()

But it always return the error Event loop is closed

However, this one works:

@keyword('Go to login screen normally')
def go_to_login_screen_normally():
    with sync_playwright() as p:
        browser = p.chromium.launch()
        page = browser.new_page()
        page.goto("https://my.page.com/login")
        print(page.title())
        browser.close()

Means I have to put the With section into the function.

I tried to skip the With-As but it does not work as well.

Thanks for your advices!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文