When I run my Playwright test, I get the following error:
ImportError while importing test module 'C:\Users\fsdam\OneDrive\Documents\python_work\playwright-python-tutorial\tests\test_search.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
C:\Users\fsdam\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py:126: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
test_search.py:2: in <module>
from pages.search import DuckDuckGoSearchPage
E ModuleNotFoundError: No module named 'pages'
It complains that there is no module names pages
. But pages
is a package. I am following a tutorial and I do not see any difference in my code and folder structure when compared. Any help would be great.
Here is my folder structure:
.
└── playwright_python_tutorial /
├── pages/
│ ├── __init__.py
│ ├── result.py
│ └── search.py
└── tests/
└── test_search.py
Here is my code that contains the test containing the imports:
from playwright.sync_api import expect, Page
from pages.search import DuckDuckGoSearchPage
from pages.result import DuckDuckGoResultPage
def test_basic_duckduckgo_search(page: Page) -> None:
search_page = DuckDuckGoSearchPage(page)
result_page = DuckDuckGoResultPage(page)
#Given the DuckDuckGo home page is displayed
search_page.load()
#When the user searches for a phrase
page.locator('id=searchbox_input').fill('panda')
#page.fill('id=searchbox_input', 'panda')
page.locator('xpath=//button[@aria-label="Search"]').click()
#Then the search result query is the phrase
expect(result_page.search_input).to_have_value('panda')
# Alternative way: assert 'panda' == page.input_value('id=search_form_input')
#And the search result links pertain to the phrase
assert result_page.result_link_titles_contain_phrase('panda')
#And the search result title contains the phrase
expect(page).to_have_title('panda at DuckDuckGo')