I have created a couple of custom widgets and it would be great to test them. I have seen that some of the tests are ui tests, and they have a page variable that allows them to simulate clicks and test the outcome.
I dag through the conftest.py file but I am still quite new to pytest and was unable to find how this page variable is set up.
Welcome to the community. That is a great question.
Panel is using Playwright for its unit tests. Its a really great framework. The page argument is a so called fixture that it provides you to help with your testing.
The port fixture is one that Panel has configured in a conftest.py file.
You can check out the guide Test UI rendering. Let me know what you think - I wrote the guide
I can only accept one as a solution, so I accepted the one pointing specifically to the UI testing page.
Nice and clean descriptions. This, in combination of looking at your GitHub to learn how you yourselves are testing proved to be the best combination.
Hi @Marc ,
Thanks for writing the Test UI rendering guide. It helped me to start with testing.
Iβm very new to frontend, so to me itβs not very clear whatβs going on. Where can I find more details? What are the prerequisite knowledge to be able to write test for Panel apps?
To be more specific, when I run pytest test_my_app_frontend.py --headed --slowmo 1000 I get the following error.
E playwright._impl._errors.TargetClosedError: Target page, context or browser has been closed
E Browser logs:
E
E ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
E β Looks like you launched a headed browser without having a XServer running. β
E β Set either βheadless: trueβ or use βxvfb-run β before running Playwright. β
E β β
E β <3 Playwright Team β
E ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Iβve installed xvfb, but Iβm not sure what the expected setup is.
I eliminated the --headed --slowmo 1000 part, and the test passed. So Iβm not able to see whatβs happening in the browser.