Skip to content

Replace Selenium with Playwright - #79

Open
Vansh1419 wants to merge 6 commits into
django:mainfrom
Vansh1419:replace-selenium-with-playwright
Open

Vansh1419 wants to merge 6 commits into
django:mainfrom
Vansh1419:replace-selenium-with-playwright

Conversation

@Vansh1419

Copy link
Copy Markdown

Summary

Replaces Selenium with Playwright for running Django's user interface tests.

Changes

  • docker-compose.yml:
    • Replaced the x-selenium-base anchor with x-playwright-base
      (image: mcr.microsoft.com/playwright)
    • Removed selenium-hub service and its port mapping — Playwright
      has no hub/grid model, so there's no direct equivalent
    • Replaced selenium-chrome / selenium-edge / selenium-firefox
      with playwright-chrome / playwright-edge / playwright-firefox
    • chrome, edge, firefox command services keep their names,
      now depend on the corresponding playwright-* service instead
      of the hub
    • Updated entrypoint flags from --selenium=<browser> --selenium-hub=http://selenium-hub:4444/wd/hub to
      --playwright=<browser>
  • README.md: updated references to Selenium (Highlights section,
    User Interface Tests section, Other Versions section) to Playwright

Notes

  • No specific Playwright image version was pinned (matches prior
    behavior of always using the latest Selenium tag)
  • The --playwright=<browser> flag assumes runtests.py will support
    this option — will need to be confirmed/implemented on the Django
    side since entrypoint.bash just forwards args
  • The link [8] in the README still points to Django's own docs page
    titled "Running the Selenium tests" (external URL, unchanged)

Closes : #78

@varunkasyap varunkasyap left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for picking this. Could you please verify that you are able to run Playwright tests after changes?

Comment thread README.md Outdated
regressions, the `--screenshots` flag can be passed.

More information about [running the Selenium tests][8] for Django can be found
More information about [running the Playground tests][8] for Django can be found

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I believe this is a typo

Suggested change
More information about [running the Playground tests][8] for Django can be found
More information about [running the Playwright tests][8] for Django can be found

I think reference hyperlink should be available from Django 6.2 onwards in https://docs.djangoproject.com/en/stable/internals/contributing/writing-code/unit-tests/#running-the-playwright-tests

Comment thread compose.yml Outdated
/django/entrypoint.bash
--selenium=edge
--selenium-hub=http://selenium-hub:4444/wd/hub
--playwright=edge

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

only these browsers are available

--playwright=chromium,firefox,webkit

we no longer have edge

Comment thread compose.yml Outdated
working_dir: /django/source/docs
environment:
BUILDDIR: /django/output/docs
BUILDDIR: /django/output/docs No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

new line at the end

Suggested change
BUILDDIR: /django/output/docs
BUILDDIR: /django/output/docs

Comment thread compose.yml

x-selenium-base: &selenium-base
x-playwright-base: &playwright-base
image: mcr.microsoft.com/playwright

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this is Node.js image i think

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

its not only node image it has multiple things inside:

  • Node.js runtime
  • Playwright library pre-installed
  • Chromium, Firefox, and WebKit browsers already downloaded
  • All the OS-level dependencies those browsers need (fonts, codecs, etc.)

@varunkasyap varunkasyap Aug 26, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

not sure, why nodejs based image for a python project

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

because this is necessay for playwright environment to get setup in our system to perform the test. Its just nodejs runtime

Comment thread README.md Outdated
- :test\_tube: Test supported core database backends — MariaDB, MySQL, Oracle, PostgreSQL, SQLite
- :earth\_africa: Test supported core geospatial backends — MariaDB, MySQL, Oracle, PostGIS, SpatiaLite
- :globe\_with\_meridians: Test user interfaces in different browsers using Selenium — Chrome, Edge, Firefox
- :globe\_with\_meridians: Test user interfaces in different browsers using Playwright — Chrome, Edge, Firefox

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
- :globe\_with\_meridians: Test user interfaces in different browsers using Playwright — Chrome, Edge, Firefox
- :globe\_with\_meridians: Test user interfaces in different browsers using Playwright — Chromium, Firefox, Webkit

@Vansh1419

Copy link
Copy Markdown
Author

Thanks @varunkasyap, for the suggestion. I will apply the suggested changes

@varunkasyap

Copy link
Copy Markdown

@Vansh1419 Could you please verify that you are able to run Playwright tests?

@Vansh1419

Copy link
Copy Markdown
Author

Hi @varunkasyap, I have made some changes the containerfile and compose.yml for playwright tests to work and out of all tests 2 tests are failing in case of chromium no testcase failed in case of firefox

======================================================================
FAIL: test_collapse_filter_with_unescaped_title (admin_changelist.tests.PlaywrightTests.test_collapse_filter_with_unescaped_title)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/django/source/tests/admin_changelist/tests.py", line 2185, in test_collapse_filter_with_unescaped_title
    ).not_to_have_attribute("open")
      ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "/usr/local/lib/python3.14/site-packages/playwright/sync_api/_generated.py", line 22144, in not_to_have_attribute
    self._sync(
    ~~~~~~~~~~^
        self._impl_obj.not_to_have_attribute(
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<4 lines>...
        )
        ^
    )
    ^
  File "/usr/local/lib/python3.14/site-packages/playwright/_impl/_sync_base.py", line 115, in _sync
    return task.result()
           ~~~~~~~~~~~^^
  File "/usr/local/lib/python3.14/site-packages/playwright/_impl/_assertions.py", line 367, in not_to_have_attribute
    await self._not.to_have_attribute(
        name, value, ignoreCase=ignoreCase, timeout=timeout
    )
  File "/usr/local/lib/python3.14/site-packages/playwright/_impl/_assertions.py", line 340, in to_have_attribute
    await self._expect_impl(
    ...<5 lines>...
    )
  File "/usr/local/lib/python3.14/site-packages/playwright/_impl/_assertions.py", line 128, in _expect_impl
    _record_soft_or_raise(
    ~~~~~~~~~~~~~~~~~~~~~^
        AssertionError(
        ^^^^^^^^^^^^^^^
    ...<2 lines>...
        self._is_soft,
        ^^^^^^^^^^^^^^
    )
    ^
  File "/usr/local/lib/python3.14/site-packages/playwright/_impl/_assertions.py", line 60, in _record_soft_or_raise
    raise error
AssertionError: Locator expected not to have attribute
Actual value: attribute present 
Call log:
  - Expect "not_to_have_attribute" with timeout 5000ms
  - waiting for locator("[data-filter-title='It\\'s OK']")
    14 × locator resolved to <details open="" data-filter-title="It's OK">…</details>
       - unexpected value "attribute present"

Aria snapshot:
- group:
  - text: ↓ By It's OK
  - list

======================================================================
FAIL: test_collapse_filters (admin_changelist.tests.PlaywrightTests.test_collapse_filters)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/django/source/tests/admin_changelist/tests.py", line 2154, in test_collapse_filters
    ).not_to_have_attribute("open")
      ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "/usr/local/lib/python3.14/site-packages/playwright/sync_api/_generated.py", line 22144, in not_to_have_attribute
    self._sync(
    ~~~~~~~~~~^
        self._impl_obj.not_to_have_attribute(
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<4 lines>...
        )
        ^
    )
    ^
  File "/usr/local/lib/python3.14/site-packages/playwright/_impl/_sync_base.py", line 115, in _sync
    return task.result()
           ~~~~~~~~~~~^^
  File "/usr/local/lib/python3.14/site-packages/playwright/_impl/_assertions.py", line 367, in not_to_have_attribute
    await self._not.to_have_attribute(
        name, value, ignoreCase=ignoreCase, timeout=timeout
    )
  File "/usr/local/lib/python3.14/site-packages/playwright/_impl/_assertions.py", line 340, in to_have_attribute
    await self._expect_impl(
    ...<5 lines>...
    )
  File "/usr/local/lib/python3.14/site-packages/playwright/_impl/_assertions.py", line 128, in _expect_impl
    _record_soft_or_raise(
    ~~~~~~~~~~~~~~~~~~~~~^
        AssertionError(
        ^^^^^^^^^^^^^^^
    ...<2 lines>...
        self._is_soft,
        ^^^^^^^^^^^^^^
    )
    ^
  File "/usr/local/lib/python3.14/site-packages/playwright/_impl/_assertions.py", line 60, in _record_soft_or_raise
    raise error
AssertionError: Locator expected not to have attribute
Actual value: attribute present 
Call log:
  - Expect "not_to_have_attribute" with timeout 5000ms
  - waiting for locator("[data-filter-title='superuser status']")
    14 × locator resolved to <details open="" data-filter-title="superuser status">…</details>
       - unexpected value "attribute present"

Aria snapshot:
- group:
  - text: ↓ By superuser status
  - list

----------------------------------------------------------------------
Ran 107 tests in 91.132s

FAILED (failures=2)

I have added the failed tests

could u suggest me where i am doing wrong

@Vansh1419
Vansh1419 force-pushed the replace-selenium-with-playwright branch from ffd08a4 to ab4794f Compare August 26, 2026 14:26
@varunkasyap

Copy link
Copy Markdown

out of all tests 2 tests are failing
could u suggest me where i am doing wrong

i dont know, but, you may not need to think about failing tests.

Comment thread compose.yml Outdated
--selenium=chrome
--selenium-hub=http://selenium-hub:4444/wd/hub
--playwright=chromium
--parallel=1

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

i see this was not there earlier🤔
--parallel=1

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

yeah i have added this because i am getting a error while running the docker. I have 2 option

  1. Is to use --parallel=1 everytime running docker
  2. is to add in the compose .yml

so i have gone for the 2nd option so person running for the first time won't bother about it

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Okay @varunkasyap, i will add this reference in the readme.md

@varunkasyap varunkasyap Aug 27, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍
for your understanding, parallelism is not supported in spawn and forkserver start methods. but, for systems which do not fall in this category can run parallelly.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

thanks @varunkasyap, for clarification i have added these and already made a commit

Comment thread README.md Outdated
Comment on lines +310 to +311
[7]: https://docs.djangoproject.com/en/stable/internals/contributing/writing-code/unit-tests/#running-the-unit-tests
[8]: https://docs.djangoproject.com/en/stable/internals/contributing/writing-code/unit-tests/#running-the-selenium-tests
[9]: https://docs.djangoproject.com/en/stable/ref/contrib/gis/testing/#geodjango-tests
[9]: https://docs.djangoproject.com/en/stable/ref/contrib/gis/testing/#geodjango-tests No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

8th link is missing

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Because there is no dedicated reference link available for playwright testing in djangoproject

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Exactly thats why i havn't put any of these.

Could we put both of them in this case or for now we add reference to the stable one

@Vansh1419

Copy link
Copy Markdown
Author

In that case @varunkasyap, the tests are working fine in all three chromium, firefox and webkit

@Vansh1419

Copy link
Copy Markdown
Author

hi @varunkasyap, I have update the readme to add 8 link with its reference to stable one and removed --parallel=1 from compose.yml as suggested

@Vansh1419
Vansh1419 requested a review from varunkasyap August 26, 2026 18:25
Comment thread compose.yml

x-selenium-base: &selenium-base
x-playwright-base: &playwright-base
image: mcr.microsoft.com/playwright

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I see an issue. The browsers come along with PW Docker image, and you're also running playwright install --with-deps chromium firefox webkit. 🤔

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

yeah i got it, by doing so it becoming retundent

@varunkasyap

Copy link
Copy Markdown

are you able to run tests now?

varunkasyap

This comment was marked as duplicate.

@Vansh1419

Copy link
Copy Markdown
Author

are you able to run tests now?

Yes i am able to run the tests

@varunkasyap

varunkasyap commented Aug 27, 2026 •

Copy link
Copy Markdown

The sidecar is unused, and system without a cached browser will get this.

BrowserType.launch: Executable doesn't exist
╔════════════════════════════════════════════════════════════╗
║ Looks like Playwright was just installed or updated.       ║
║ Please run the following command to download new browsers: ║
║                                                            ║
║     playwright install                                     ║
║                                                            ║
║ <3 Playwright Team                                         ║
╚════════════════════════════════════════════════════════════╝

@vansh1003

Copy link
Copy Markdown

The sidecar is unused, and system without a cached browser will get this.

BrowserType.launch: Executable doesn't exist
╔════════════════════════════════════════════════════════════╗
║ Looks like Playwright was just installed or updated.       ║
║ Please run the following command to download new browsers: ║
║                                                            ║
║     playwright install                                     ║
║                                                            ║
║ <3 Playwright Team                                         ║
╚════════════════════════════════════════════════════════════╝

Hi @varunkasyap, could you tell me how can i recreate this error in my system. I had already uninstalled the playwright completely and after that is have tested it with this command

docker compose run --rm webkit --parallel=1

My tests run completely fine

vansh@vanshs-MacBook-Air django-docker-box % docker compose run --rm webkit --parallel=1
[+]  1/1t 1/1
 ✔ Container django-docker-box-playwright-webkit-1 Started                                                                             0.0s
Container django-docker-box-webkit-run-bff21bb97dba Creating 
Container django-docker-box-webkit-run-bff21bb97dba Created 
Testing against Django installed in '/django/source/django'
Found 107 test(s).
Creating test database for alias 'default'...
System check identified no issues (46 silenced).
................................ssss.......................................................................
----------------------------------------------------------------------
Ran 107 tests in 86.763s

OK (skipped=4)
Destroying test database for alias 'default'...

@varunkasyap

Copy link
Copy Markdown

Hi,
If you are only deleting playwright python package, the browser binaries may stay. Could you please try deleting the browser binaries and previous docker images as well?

@varunkasyap

Copy link
Copy Markdown
image

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

Successfully merging this pull request may close these issues.

Replace selenium with playwright

3 participants