Skip to content
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

Add a test mode for the web backend #1166

Open
freakboy3742 opened this issue Apr 7, 2023 · 1 comment · May be fixed by #1285
Open

Add a test mode for the web backend #1166

freakboy3742 opened this issue Apr 7, 2023 · 1 comment · May be fixed by #1285
Labels
enhancement New features, or improvements to existing features. web The issue relates to supporting the web as a platform.

Comments

@freakboy3742
Copy link
Member

freakboy3742 commented Apr 7, 2023

What is the problem or limitation you are having?

--test mode is supported on briefcase run on every platform except web. We need the ability to run test suites on web so that an app can validate runtime behavior on web.

Describe the solution you'd like

A default Briefcase helloworld project should produce test output from briefcase run web --test.

Describe alternatives you've considered

Don't test on web. YOLO. :-)

Additional context

There are 2 major technical problems to be solved:

  1. Passing in a different app startup arg to the PyScript startup (i.e., running python -m tests.myapp rather than python -m myapp)
  2. Reading test output outside the browser

(1) could be solved by:

  • re-writing index.html for test mode
  • making index.html reference an external configuration source (e.g., a variable in pyscript.toml) when looking for the startup module
  • Making the startup script something that is a file on disk, rather than something embedded in index.html

(2) is more complex - we need to be able to capture anything written to stdout by Python in the browser, and redirect it to a location that Briefcase can see. Some options:

  • Have the test harness in the browser open a web socket on a different URL on the server that Briefcase starts, and use that for communication between Briefcase and the test suite.
  • Install a handler in Python to redirect stdout to a socket, and adding a separate server to Briefcase to read that content
  • Use a headless browser or browser test framework (e.g., Playwright, Selenium) that outputs the javascript console to stdout
  • Keep the test content in the browser (maybe opening a separate window to report test progress); but provide some other external marker signal that Briefcase can read that indicates that the test suite has completed.
@freakboy3742 freakboy3742 added enhancement New features, or improvements to existing features. web The issue relates to supporting the web as a platform. labels Apr 7, 2023
@LunaMeadows
Copy link

https://gist.github.com/LunaMeadows/233d4d1386a6e464fb1d22c6befc1c13

I am having difficulties fully understanding the code and how to get part 1 done however I do believe I have the base needed for the 2nd part. Using Selenium, I was able to start Selenium and then start a logging loop that will constantly check for the latest logs. If a delay was needed it would grab all the logs from after the last run and print them out. I am not sure how the logger stuff works so I will leave that to someone who has more knowledge of the code but this should be a starting point.

I didn't do a headless at this point because in order to test the console output I needed an interface to access the dev console. Once stuff is being printed from python tho it should be able to be done headless from the testing I did.

I attempted to figure out how to do it with playwright but couldn't find much documentation on reading the console output as easily as you can with Selenium.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New features, or improvements to existing features. web The issue relates to supporting the web as a platform.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants