-
Notifications
You must be signed in to change notification settings - Fork 240
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
[Feature] Set ContextOptions via runsettings file #2555
Comments
You can do the following, would that work for you? using Microsoft.Playwright.NUnit;
using Microsoft.Playwright;
namespace PlaywrightTestsN;
[Parallelizable(ParallelScope.Self)]
[TestFixture]
public class MyTest : PageTest
{
[Test]
public async Task TestWithCustomContextOptions()
{
// The following Page (and BrowserContext) instance has the custom baseURL set:
await Page.GotoAsync("/login");
}
public override BrowserNewContextOptions ContextOptions()
{
var baseURL = Environment.GetEnvironmentVariable("BASE_URL");
if (string.IsNullOrEmpty(baseURL))
{
throw new Exception("BASE_URL environment variable is not set.");
}
return new BrowserNewContextOptions()
{
BaseURL = baseURL,
};
}
} |
Sure, I can, I've already done this: public class CustomContextTest: ContextTest
{
public override BrowserNewContextOptions ContextOptions() =>
new()
{
BaseURL = ContextHelper.TestSettings.Host
};
} And have two other classes inheriting from it for my equivalent of a That being said, I don't think it should be necessary. I think setting a BaseURL for automation testing in a Playwright already supports this, I think it's just a case of adding it to the NUnit setup in the same way as we look for |
Arguably, anything in |
sounds reasonable! I changed the PR title to reflect this feature request. |
Hey @mxschmitt, any update on that, it is on the table :) |
We use MSTest, and I wrote a TestContext extension method to set BaseUrl and such from the runsettings:
|
@Exoow can you share your TestContext extension in an example? So it's easy to maybe implement the same workaround like you did. |
See attachment, just rename the file to .cs :) |
One of the big benefits of using the nunit package is not having to worry about lots of setup boilerplate.
However, I can't seem to set the BaseUrl with an env var, which seems pretty crucial to me...
Can we get this added please?
The text was updated successfully, but these errors were encountered: