Skip to content

BrowserContext.pages() causes "TypeError: 'list' object is not callable" #427

@yaboxi

Description

@yaboxi

I'm using the playwright-pytest plugin.
When I call BrowserContext.pages() to get the pages to switch tabs ,
I got the error "TypeError: 'list' object is not callable."
I can't identify the cause is whether on the pytest plugin or python implementation.

To be honest, it would be okay for me if I could realize switching tabs after opening target="_blank" links on the pytest plugin.
When I have tried by myself to re-implement the below in pytest, I have met the error.
https://playwright.dev/docs/multi-pages

To simplify, I attached the code not to open a target="_blank" link but to open a new page on the browser context.
Your assistance would help me.

Code:

from playwright.sync_api import Page, Browser, BrowserContext


class TestSwitchTabs:
    def test_switch_tabs(self, page: Page, browser: Browser, context: BrowserContext):
        page1 = context.newPage()
        page2 = context.newPage()

        pages = context.pages()  # causes an error

Output:

❯ pytest -s --headful test_switch_tabs.py
Test session starts (platform: darwin, Python 3.9.0, pytest 6.1.1, pytest-sugar 0.9.4)
rootdir: *******
plugins: playwright-0.0.7, base-url-1.4.2, allure-pytest-2.8.18, sugar-0.9.4, asyncio-0.14.0, Faker-4.14.0
collecting ... 

―――――――――――――――――――――――――――――――――――――――― TestSwitchTabs.test_switch_tabs[chromium] ―――――――――――――――――――――――――――――――――――――――――

self = <test_switch_tabs.TestSwitchTabs object at 0x10e4f5640>, page = <playwright.sync_api.Page object at 0x10e6c2280>
browser = <playwright.sync_api.Browser object at 0x10e6a9700>
context = <playwright.sync_api.ChromiumBrowserContext object at 0x10e6a9940>

    def test_switch_tabs(self, page: Page, browser: Browser, context: BrowserContext):
        page1 = context.newPage()
        page2 = context.newPage()
    
>       pages = context.pages()  # causes an error
E       TypeError: 'list' object is not callable

test_switch_tabs.py:9: TypeError

 test_switch_tabs.py ⨯                                                                                       100% ██████████
================================================= short test summary info ==================================================
FAILED test_switch_tabs.py::TestSwitchTabs::test_switch_tabs[chromium] - TypeError: 'list' object is not callable

Results (1.77s):
       1 failed
         - test_switch_tabs.py:5 TestSwitchTabs.test_switch_tabs[chromium]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions