Open Cyrus-Sushiant opened 6 days ago
@Cyrus-Sushiant thanks for contacting us.
That likely is caused by you running the build output in Production without explicitly setting up static web assets.
Static Web Assets are only loaded in Developmnet environment. You need to call StaticWebAssetsLoader.UseStaticWebAssets
if you are not running in development.
The environment has been set to development, so I assume calling StaticWebAssetsLoader.UseStaticWebAssets
is not required (Even though I called it without success)
Note that if we set Sdk of test project to Microsoft.NET.Sdk.Web
the staticwebassets.development.json
file gets generated, but for some reason, aspnetcore doesn't use it.
As @ysmoradi said, the environment has been set to development. You can see in this class: https://github.com/Cyrus-Sushiant/PlaywrightIssue/blob/master/PlaywrightIssue.Tests/MyTest.cs
@ysmoradi You need to call this one StaticWebAssetsLoader.UseStaticWebAssets(builder.Environment, builder.Configuration);
not the one you called.
You also need to pass in the file to load, since otherwise is going to try and load the one from the test project, not the one from your host project.
You have all the logic https://github.com/dotnet/aspnetcore/blob/main/src/Hosting/Hosting/src/StaticWebAssets/StaticWebAssetsLoader.cs
Hi @Cyrus-Sushiant. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
Thanks for your efforts, I really appreciate it. Two notes to consider:
1- Changing test project sdk to Microsoft.NET.Sdk.Web
will result into generating all required files such as staticwebassets.development.json
, so we don't have to look for these files in host project (aspnetcore project)
2- Event though calling StaticWebAssetsLoader.UseStaticWebAssets(builder.Environment, builder.Configuration);
is not required if dev environment, but even if you call it, it won't work! you can easily test that in the sample source code.
The builder.Environment.ApplicationName
is testhost
(for the builder that is being built in mstest method)
Assigning appropriate ApplicationName resolved the issue
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.
See our Issue Management Policies for more information.
Is there an existing issue for this?
Describe the bug
I'm encountering an issue when trying to open the test server app in the browser. Some assets (e.g., CSS, JS, images, etc.) are returning 404 errors, which prevents the application from loading correctly.
As a result, the app does not display with full functionality, and I am unable to properly check the UI for testing purposes. This issue makes it difficult to run effective UI tests.
Expected Behavior
The assets should load correctly, allowing the app to display and function as expected to proceed with UI testing.
Steps To Reproduce
Example steps:
GotoCounterPage
test in theMyTest
class in the tests projecthttp://127.0.0.1:2001
in your browserExceptions (if any)
No response
.NET Version
8.0.401
Anything else?
No response