Skip to content

tests: added keyboard tests #146

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

Merged
merged 1 commit into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion playwright/element_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ async def type(
timeout: int = None,
noWaitAfter: bool = None,
) -> None:
await self._channel.send("text", locals_to_params(locals()))
await self._channel.send("type", locals_to_params(locals()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm so happy porting tests reveal this.


async def press(
self, key: str, delay: int = None, timeout: int = None, noWaitAfter: bool = None
Expand Down
6 changes: 6 additions & 0 deletions tests/async/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
from playwright import async_playwright


# Will mark all the tests as async
def pytest_collection_modifyitems(items):
for item in items:
item.add_marker(pytest.mark.asyncio)

Comment on lines +21 to +24
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain to me why this is needed? (I'm new to async in Python.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before it was in the global conftest.py. A conftest.py will be executed through the directory three and by that they can overwrite each other (which is nearest to the actual test).

This specific piece added asyncio support to the tests which was before available in all the tests. But since we split async and sync I limited the scope of it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! So async tests need to be explicitly (or programmatically) marked as async for pytest to run them?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly with: https://github.com/pytest-dev/pytest-asyncio

You can do it manually with the decorator per test or in our case just for all the tests in that directory.


@pytest.fixture(scope="session")
async def playwright():
async with async_playwright() as playwright_object:
Expand Down
1 change: 1 addition & 0 deletions tests/async/test_headful.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ async def test_headless_should_be_able_to_read_cookies_written_by_headful(
):
if is_chromium and is_win:
pytest.skip("see https://github.com/microsoft/playwright/issues/717")
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to add the return in the two cookie tests from yesterday. Good catch!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I'm not sure if we need it! It was flaky so I added it. But seems like its not needed: https://www.programcreek.com/python/example/25423/pytest.skip

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✨ Magic!

# Write a cookie in headful chrome
headful_context = await browser_type.launchPersistentContext(
tmpdir, **{**launch_arguments, "headless": False}
Expand Down
Loading