Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -414,3 +414,5 @@ obj/Debug/net8.0/playwright-csharp.pdb
obj/Debug/net8.0/playwright-csharp.sourcelink.json
obj/Debug/net8.0/ref/playwright-csharp.dll
obj/Debug/net8.0/refint/playwright-csharp.dll
bin/Debug/net8.0/Faker.Net.6.0.dll
bin/Debug/net8.0/de-DE/Faker.Net.6.0.resources.dll
1 change: 1 addition & 0 deletions playwright-csharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Faker.Net" Version="2.0.163" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Microsoft.Playwright.NUnit" Version="1.43.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
Expand Down
56 changes: 56 additions & 0 deletions tests/Examples/APIExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System.Net;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.Playwright;
using Microsoft.Playwright.NUnit;
using NUnit.Framework;

namespace PlaywrightTests;

[TestFixture]
public class APIExample : PageTest
{
private IAPIRequestContext Request = null;

[Test]
public async Task APITestGetReturns200()
{
var headers = new Dictionary<string, string>();
headers.Add("Authorization", "Bearer ");

Request = await this.Playwright.APIRequest.NewContextAsync(new()
{
// All requests we send go to this API endpoint.
BaseURL = "http://127.0.0.1:7174",
ExtraHTTPHeaders = headers,
});

var Response = await Request.GetAsync("/api/employee/1");
Assert.AreEqual(200, Response.Status);
}

[Test]
public async Task AddEmployeeReturns201()
{
var headers = new Dictionary<string, string>();
headers.Add("Authorization", "Bearer ");

Request = await this.Playwright.APIRequest.NewContextAsync(new()
{
BaseURL = "http://127.0.0.1:7174",
ExtraHTTPHeaders = headers,
});

var data = new Dictionary<string, object>() {
{ "EmployeeId", 6 },
{ "FirstName", Faker.Name.First() },
{ "LastName", Faker.Name.Last()},
{ "Age", 41 },
{ "State", Faker.Address.UsStateAbbr() }
};

var Response = await Request.PostAsync("/api/employee", new() { DataObject = data });
Assert.AreEqual(201, Response.Status);

}
}
8 changes: 4 additions & 4 deletions tests/Examples/PlaywrightExample.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.Playwright;
using Microsoft.Playwright.NUnit;
using NUnit.Framework;

namespace PlaywrightTests;


[TestFixture]
public class PlaywrightExample : PageTest
{
Expand All @@ -20,14 +17,17 @@ public async Task HomepageHasPlaywrightInTitleAndGetStartedLinkLinkingtoTheIntro

// create a locator
var getStarted = Page.GetByRole(AriaRole.Link, new() { Name = "Get started" });


// Expect an attribute "to be strictly equal" to the value.
await Expect(getStarted).ToBeAttachedAsync();
await Expect(getStarted).ToHaveAttributeAsync("href", "/docs/intro");


// Click the get started link.
await getStarted.ClickAsync();

// Expects the URL to contain intro.
await Expect(Page).ToHaveURLAsync(new Regex(".*intro"));
await Expect(Page).ToHaveURLAsync("https://playwright.dev/docs/intro");
}
}