Skip to content

Commit

Permalink
Revert "chore(generator): use new .NET test attributes (microsoft#17172
Browse files Browse the repository at this point in the history
…)"

This reverts commit 15add13.
  • Loading branch information
mxschmitt committed Sep 14, 2022
1 parent e295eea commit f00a850
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 44 deletions.
12 changes: 6 additions & 6 deletions docs/src/api-testing-csharp.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public class TestGitHubAPI : PlaywrightTest

private IAPIRequestContext Request = null;

[PlaywrightTest]
[Test]
public async Task ShouldCreateBugReport()
{
var data = new Dictionary<string, string>();
Expand All @@ -127,7 +127,7 @@ public class TestGitHubAPI : PlaywrightTest
Assert.AreEqual("Bug description", issue?.GetProperty("body").GetString());
}

[PlaywrightTest]
[Test]
public async Task ShouldCreateFeatureRequests()
{
var data = new Dictionary<string, string>();
Expand Down Expand Up @@ -224,7 +224,7 @@ public class TestGitHubAPI : PlaywrightTest

private IAPIRequestContext Request = null;

[PlaywrightTest]
[Test]
public async Task ShouldCreateBugReport()
{
var data = new Dictionary<string, string>();
Expand All @@ -251,7 +251,7 @@ public class TestGitHubAPI : PlaywrightTest
Assert.AreEqual("Bug description", issue?.GetProperty("body").GetString());
}

[PlaywrightTest]
[Test]
public async Task ShouldCreateFeatureRequests()
{
var data = new Dictionary<string, string>();
Expand Down Expand Up @@ -337,7 +337,7 @@ The following test creates a new issue via API and then navigates to the list of
project to check that it appears at the top of the list. The check is performed using [LocatorAssertions].

```csharp
[PlaywrightTest]
[Test]
public async Task LastCreatedIssueShouldBeFirstInTheList()
{
var data = new Dictionary<string, string>();
Expand All @@ -360,7 +360,7 @@ The following test creates a new issue via user interface in the browser and the
it was created:

```csharp
[PlaywrightTest]
[Test]
public async Task LastCreatedIssueShouldBeOnTheServer()
{
await Page.GotoAsync("https://github.com/" + USER + "/" + REPO + "/issues");
Expand Down
3 changes: 1 addition & 2 deletions docs/src/api/class-locatorassertions.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ using NUnit.Framework;

namespace PlaywrightTests;

[TestFixture]
public class ExampleTests : PageTest
{
[PlaywrightTest]
[Test]
public async Task StatusBecomesSubmitted()
{
// ..
Expand Down
3 changes: 1 addition & 2 deletions docs/src/api/class-pageassertions.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ using NUnit.Framework;

namespace PlaywrightTests;

[TestFixture]
public class ExampleTests : PageTest
{
[PlaywrightTest]
[Test]
public async Task NavigatetoLoginPage()
{
// ..
Expand Down
3 changes: 1 addition & 2 deletions docs/src/api/class-playwrightassertions.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ using NUnit.Framework;

namespace PlaywrightTests;

[TestFixture]
public class ExampleTests : PageTest
{
[PlaywrightTest]
[Test]
public async Task StatusBecomesSubmitted()
{
await Page.Locator("#submit-button").ClickAsync();
Expand Down
5 changes: 2 additions & 3 deletions docs/src/intro-csharp.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,9 @@ using NUnit.Framework;
namespace PlaywrightTests;

[Parallelizable(ParallelScope.Self)]
[TestFixture]
public class Tests : PageTest
{
[PlaywrightTest]
[Test]
public async Task HomepageHasPlaywrightInTitleAndGetStartedLinkLinkingtoTheIntroPage()
{
await Page.GotoAsync("https://playwright.dev");
Expand Down Expand Up @@ -136,7 +135,7 @@ namespace PlaywrightTests;
[TestClass]
public class UnitTest1 : PageTest
{
[PlaywrightTestMethod]
[TestMethod]
public async Task HomepageHasPlaywrightInTitleAndGetStartedLinkLinkingtoTheIntroPage()
{
await Page.GotoAsync("https://playwright.dev");
Expand Down
3 changes: 1 addition & 2 deletions docs/src/release-notes-csharp.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,9 @@ using NUnit.Framework;

namespace PlaywrightTests;

[TestFixture]
public class ExampleTests : PageTest
{
[PlaywrightTest]
[Test]
public async Task StatusBecomesSubmitted()
{
await Expect(Page.Locator(".status")).ToHaveTextAsync("Submitted");
Expand Down
18 changes: 6 additions & 12 deletions docs/src/test-runners-csharp.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,16 @@ using Microsoft.Playwright.NUnit;
namespace PlaywrightTests;

[Parallelizable(ParallelScope.Self)]
[TestFixture]
public class MyTest : PageTest
{
[PlaywrightTest]
[Test]
public async Task ShouldHaveTheCorrectSlogan()
{
await Page.GotoAsync("https://playwright.dev");
await Expect(Page.Locator("text=enables reliable end-to-end testing for modern web apps")).ToBeVisibleAsync();
}

[PlaywrightTest]
[Test]
public async Task ShouldHaveTheCorrectTitle()
{
await Page.GotoAsync("https://playwright.dev");
Expand Down Expand Up @@ -122,10 +121,9 @@ using Microsoft.Playwright.NUnit;
namespace PlaywrightTests;

[Parallelizable(ParallelScope.Self)]
[TestFixture]
public class MyTest : PageTest
{
[PlaywrightTest]
[Test]
public async Task TestWithCustomContextOptions()
{
// The following Page (and BrowserContext) instance has the custom colorScheme, viewport and baseURL set:
Expand Down Expand Up @@ -217,10 +215,6 @@ There are a few base classes available to you in `Microsoft.Playwright.NUnit` na
|BrowserTest |Each test will get a browser and can create as many contexts as it likes. Each test is responsible for cleaning up all the contexts it created.|
|PlaywrightTest|This gives each test a Playwright object so that the test could start and stop as many browsers as it likes.|

### 'No test is available'

You need to add `[TestFixture]` to your test class. NUnit does not discover tests without it, if the `TestAttribute` comes from a different assembly.

## MSTest

Playwright provides base classes to write tests with MSTest via the [`Microsoft.Playwright.MSTest`](https://www.nuget.org/packages/Microsoft.Playwright.MSTest) package.
Expand Down Expand Up @@ -250,14 +244,14 @@ namespace PlaywrightTests;
[TestClass]
public class UnitTest1: PageTest
{
[PlaywrightTestMethod]
[TestMethod]
public async Task ShouldHaveTheCorrectSlogan()
{
await Page.GotoAsync("https://playwright.dev");
await Expect(Page.Locator("text=enables reliable end-to-end testing for modern web apps")).ToBeVisibleAsync();
}

[PlaywrightTestMethod]
[TestMethod]
public async Task ShouldHaveTheCorrectTitle()
{
await Page.GotoAsync("https://playwright.dev");
Expand Down Expand Up @@ -335,7 +329,7 @@ namespace PlaywrightTests;
[TestClass]
public class UnitTest1 : PageTest
{
[PlaywrightTestMethod]
[TestMethod]
public async Task TestWithCustomContextOptions()
{
// The following Page (and BrowserContext) instance has the custom colorScheme, viewport and baseURL set:
Expand Down
15 changes: 6 additions & 9 deletions docs/src/writing-tests-csharp.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ using Microsoft.Playwright.NUnit;
namespace PlaywrightTests;

[Parallelizable(ParallelScope.Self)]
[TestFixture]
public class Tests : PageTest
{
[PlaywrightTest]
[Test]
public async Task HomepageHasPlaywrightInTitleAndGetStartedLinkLinkingtoTheIntroPage()
{
await Page.GotoAsync("https://playwright.dev");
Expand Down Expand Up @@ -62,7 +61,7 @@ namespace PlaywrightTests;
[TestClass]
public class UnitTest1 : PageTest
{
[PlaywrightTestMethod]
[TestMethod]
public async Task HomepageHasPlaywrightInTitleAndGetStartedLinkLinkingtoTheIntroPage()
{
await Page.GotoAsync("https://playwright.dev");
Expand Down Expand Up @@ -137,10 +136,9 @@ using NUnit.Framework;
namespace PlaywrightTests;

[Parallelizable(ParallelScope.Self)]
[TestFixture]
public class Tests : PageTest
{
[PlaywrightTest]
[Test]
public async Task BasicTest()
{
await Page.GotoAsync("https://playwright.dev");
Expand All @@ -159,7 +157,7 @@ namespace PlaywrightTests;
[TestClass]
public class UnitTest1 : PageTest
{
[PlaywrightTestMethod]
[TestMethod]
public async Task BasicTest()
{
await Page.GotoAsync("https://playwright.dev");
Expand Down Expand Up @@ -192,10 +190,9 @@ using NUnit.Framework;
namespace PlaywrightTests;

[Parallelizable(ParallelScope.Self)]
[TestFixture]
public class Tests : PageTest
{
[PlaywrightTest]
[Test]
public async Task MainNavigation()
{
// Assertions use the expect API.
Expand All @@ -221,7 +218,7 @@ namespace PlaywrightTests;
[TestClass]
public class UnitTest1 : PageTest
{
[PlaywrightTestMethod]
[TestMethod]
public async Task MainNavigation()
{
// Assertions use the expect API.
Expand Down
5 changes: 2 additions & 3 deletions packages/playwright-core/src/server/recorder/csharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ export class CSharpLanguageGenerator implements LanguageGenerator {
using Microsoft.Playwright.${this._mode === 'nunit' ? 'NUnit' : 'MSTest'};
using Microsoft.Playwright;
${this._mode === 'nunit' ? `[Parallelizable(ParallelScope.Self)]
[TestFixture]` : '[TestClass]'}
${this._mode === 'nunit' ? '[Parallelizable(ParallelScope.Self)]' : '[TestClass]'}
public class Tests : PageTest
{`);
const formattedContextOptions = formatContextOptions(options.contextOptions, options.deviceName);
Expand All @@ -207,7 +206,7 @@ export class CSharpLanguageGenerator implements LanguageGenerator {
}`);
formatter.newLine();
}
formatter.add(` [${this._mode === 'nunit' ? 'PlaywrightTest' : 'PlaywrightTestMethod'}]
formatter.add(` [${this._mode === 'nunit' ? 'Test' : 'TestMethod'}]
public async Task MyTest()
{`);
return formatter.format();
Expand Down
5 changes: 2 additions & 3 deletions tests/library/inspector/cli-codegen-csharp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public class Tests : PageTest
};
}
[PlaywrightTestMethod]
[TestMethod]
public async Task MyTest()
{
// Go to ${emptyHTML}
Expand All @@ -250,7 +250,6 @@ test(`should print a valid basic program in nunit`, async ({ runCLI }) => {
using Microsoft.Playwright;
[Parallelizable(ParallelScope.Self)]
[TestFixture]
public class Tests : PageTest
{
public override BrowserNewContextOptions ContextOptions()
Expand All @@ -261,7 +260,7 @@ public class Tests : PageTest
};
}
[PlaywrightTest]
[Test]
public async Task MyTest()
{
// Go to ${emptyHTML}
Expand Down

0 comments on commit f00a850

Please sign in to comment.