Skip to content

Commit

Permalink
Mark tests methods with [Test]
Browse files Browse the repository at this point in the history
  • Loading branch information
jnyrup committed Jul 19, 2024
1 parent 5451cd0 commit 9e18877
Show file tree
Hide file tree
Showing 19 changed files with 76 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public async Task ShouldIsolatePermissionsBetweenBrowserContexts()
await otherContext.CloseAsync();
}

[Test]
public async Task AllEnumsdAreValid()
{
await Page.GoToAsync(TestConstants.EmptyPage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void ShouldListDevicesAsTheyArrive()
client.OnMessage(new ConnectionResponse()
{
Method = "DeviceAccess.deviceRequestPrompted",
Params = WaitForDevicePromptTests.ToJToken(promptData),
Params = promptData.ToJToken(),
});

Assert.That(prompt.Devices, Has.Count.EqualTo(1));
Expand All @@ -59,7 +59,7 @@ public void ShouldListDevicesAsTheyArrive()
client.OnMessage(new ConnectionResponse()
{
Method = "DeviceAccess.deviceRequestPrompted",
Params = WaitForDevicePromptTests.ToJToken(promptData),
Params = promptData.ToJToken(),
});

Assert.That(prompt.Devices, Has.Count.EqualTo(2));
Expand All @@ -80,7 +80,7 @@ public void ShouldNotListDevicesFromEventsOfAnotherPrompt()
client.OnMessage(new ConnectionResponse()
{
Method = "DeviceAccess.deviceRequestPrompted",
Params = WaitForDevicePromptTests.ToJToken(promptData),
Params = promptData.ToJToken(),
});

Assert.That(prompt.Devices, Is.Empty);
Expand All @@ -104,7 +104,7 @@ public void ShouldNotListDevicesFromEventsOfAnotherPrompt()
client.OnMessage(new ConnectionResponse()
{
Method = "DeviceAccess.deviceRequestPrompted",
Params = WaitForDevicePromptTests.ToJToken(promptData),
Params = promptData.ToJToken(),
});

Assert.That(prompt.Devices, Is.Empty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task ShouldSucceedWithListedDevice()
client.OnMessage(new ConnectionResponse()
{
Method = "DeviceAccess.deviceRequestPrompted",
Params = WaitForDevicePromptTests.ToJToken(promptData),
Params = promptData.ToJToken(),
});

var device = await deviceTask;
Expand Down Expand Up @@ -84,7 +84,7 @@ public async Task ShouldFailWhenSelectingPromptTwice()
client.OnMessage(new ConnectionResponse()
{
Method = "DeviceAccess.deviceRequestPrompted",
Params = WaitForDevicePromptTests.ToJToken(promptData),
Params = promptData.ToJToken(),
});

var device = await deviceTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task ShouldReturnFirstMatchingDevice()
client.OnMessage(new ConnectionResponse()
{
Method = "DeviceAccess.deviceRequestPrompted",
Params = WaitForDevicePromptTests.ToJToken(promptData),
Params = promptData.ToJToken(),
});

promptData = new DeviceAccessDeviceRequestPromptedResponse()
Expand All @@ -59,7 +59,7 @@ public async Task ShouldReturnFirstMatchingDevice()
client.OnMessage(new ConnectionResponse()
{
Method = "DeviceAccess.deviceRequestPrompted",
Params = WaitForDevicePromptTests.ToJToken(promptData),
Params = promptData.ToJToken(),
});

var device = await promptTask;
Expand Down Expand Up @@ -120,7 +120,7 @@ public async Task ShouldReturnDeviceInTheDevicesList()
client.OnMessage(new ConnectionResponse()
{
Method = "DeviceAccess.deviceRequestPrompted",
Params = WaitForDevicePromptTests.ToJToken(promptData),
Params = promptData.ToJToken(),
});

var device = await promptTask;
Expand Down Expand Up @@ -204,7 +204,7 @@ public async Task ShouldWorkWithNoTimeout()
client.OnMessage(new ConnectionResponse()
{
Method = "DeviceAccess.deviceRequestPrompted",
Params = WaitForDevicePromptTests.ToJToken(promptData),
Params = promptData.ToJToken(),
});

promptData = new DeviceAccessDeviceRequestPromptedResponse()
Expand All @@ -222,7 +222,7 @@ public async Task ShouldWorkWithNoTimeout()
client.OnMessage(new ConnectionResponse()
{
Method = "DeviceAccess.deviceRequestPrompted",
Params = WaitForDevicePromptTests.ToJToken(promptData),
Params = promptData.ToJToken(),
});

await deviceTask;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Newtonsoft.Json.Linq;
using PuppeteerSharp.Cdp.Messaging;

namespace PuppeteerSharp.Tests.DeviceRequestPromptTests;

internal static class PromptDataConverter
{
public static JToken ToJToken(this DeviceAccessDeviceRequestPromptedResponse promptData)
{
var jObject = new JObject { { "id", promptData.Id } };
var devices = new JArray();
foreach (var device in promptData.Devices)
{
var deviceObject = new JObject { { "name", device.Name }, { "id", device.Id } };
devices.Add(deviceObject);
}
jObject.Add("devices", devices);
return jObject;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public async Task ShouldReturnPrompt()
client.OnMessage(new ConnectionResponse()
{
Method = "DeviceAccess.deviceRequestPrompted",
Params = ToJToken(promptData),
Params = promptData.ToJToken(),
});

await promptTask;
Expand Down Expand Up @@ -120,7 +120,7 @@ public async Task ShouldWorkWithNoTimeout()
client.OnMessage(new ConnectionResponse()
{
Method = "DeviceAccess.deviceRequestPrompted",
Params = ToJToken(promptData),
Params = promptData.ToJToken(),
});

await promptTask;
Expand All @@ -142,24 +142,11 @@ public async Task ShouldReturnTheSamePromptWhenThereAreManyWatchdogsSimultaneous
client.OnMessage(new ConnectionResponse()
{
Method = "DeviceAccess.deviceRequestPrompted",
Params = ToJToken(promptData),
Params = promptData.ToJToken(),
});

await Task.WhenAll(promptTask, promptTask2);
Assert.That(promptTask2.Result, Is.EqualTo(promptTask.Result));
}

internal static JToken ToJToken(DeviceAccessDeviceRequestPromptedResponse promptData)
{
var jObject = new JObject { { "id", promptData.Id } };
var devices = new JArray();
foreach (var device in promptData.Devices)
{
var deviceObject = new JObject { { "name", device.Name }, { "id", device.Id } };
devices.Add(deviceObject);
}
jObject.Add("devices", devices);
return jObject;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public async Task ShouldWork()
Assert.That(frame, Is.EqualTo(Page.FirstChildFrame()));
}

[Test]
public async Task ShouldWorkHeadful()
{
await using var Browser = await Puppeteer.LaunchAsync(_headfulOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ await Page.AddScriptTagAsync(new AddTagOptions
Assert.That(await Page.EvaluateExpressionAsync("window.e"), Is.Null);
}

[Test]
public async Task ShouldWorkWithExpressions()
{
await Page.EvaluateExpressionOnNewDocumentAsync("window.injected = 123;");
Expand Down
5 changes: 5 additions & 0 deletions lib/PuppeteerSharp.Tests/EvaluationTests/PageEvaluateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ public void ShouldThrowErrorWithDetailedInformationOnExceptionInsidePromise()
Assert.That(exception.Message, Does.Contain("Error in promise"));
}

[Test]
public async Task ShouldWorkWithDifferentSerializerSettings()
{
var result = await Page.EvaluateFunctionAsync<ComplexObjectTestClass>("() => { return { foo: 'bar' }}");
Expand Down Expand Up @@ -346,6 +347,9 @@ public async Task ShouldAcceptObjectHandleAsAnArgument()
Assert.That(text, Is.EqualTo("42"));
}

#pragma warning disable NUnit2021 // Incompatible types for EqualTo constraint
[Test]
[Ignore("I'm not sure how this ever worked?")]
public async Task ShouldWorkWithoutGenerics()
{
Assert.That(await Page.EvaluateExpressionAsync("var obj = {}; obj;"), Is.Not.Null);
Expand All @@ -366,6 +370,7 @@ public async Task ShouldWorkWithoutGenerics()
Assert.That(await Page.EvaluateExpressionAsync("11111111111111"), Is.EqualTo(11111111111111));
Assert.That(await Page.EvaluateExpressionAsync("1.1"), Is.EqualTo(1.1));
}
#pragma warning restore NUnit2021 // Incompatible types for EqualTo constraint

public class ComplexObjectTestClass
{
Expand Down
1 change: 1 addition & 0 deletions lib/PuppeteerSharp.Tests/FixturesTests/FixturesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public void ShouldDumpBrowserProcessStderr()
Assert.That(success, Is.True);
}

[Test]
public async Task ShouldCloseTheBrowserWhenTheConnectedProcessCloses()
{
var browserClosedTaskWrapper = new TaskCompletionSource<bool>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public async Task ShouldSupportTargetFilter()
await browser.CloseAsync();
}

[Test]
public async Task ShouldBeAbleToSetBrowserPropertiesUsingConnectOptions()
{
var initActionExecuted = false;
Expand Down Expand Up @@ -195,6 +196,7 @@ public async Task ShouldBeAbleToReconnect()
await browserTwo.CloseAsync();
}

[Test]
public async Task ShouldSupportCustomWebSocket()
{
var customSocketCreated = false;
Expand All @@ -214,6 +216,7 @@ public async Task ShouldSupportCustomWebSocket()
}
}

[Test]
public async Task ShouldSupportCustomTransport()
{
var customTransportCreated = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ public async Task ChromeShouldBeClosed(bool useDisposeAsync)
Assert.That(launcher.Process.HasExited, Is.True);
}

[Test]
public async Task ChromeShouldBeClosedOnDispose()
{
var options = TestConstants.DefaultBrowserOptions();
Expand All @@ -226,6 +227,7 @@ public async Task ChromeShouldBeClosedOnDispose()
Assert.That(launcher.Process.HasExited, Is.True);
}

[Test]
public async Task ShouldNotOpenTwoChromesUsingTheSameLauncher()
{
var launcher = new Launcher(TestConstants.LoggerFactory);
Expand Down
28 changes: 19 additions & 9 deletions lib/PuppeteerSharp.Tests/PageTests/CloseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,31 @@ public class CloseTests : PuppeteerPageBaseTest
{
public CloseTests() : base() { }

// [Test, Retry(2), PuppeteerTest("page.spec", "Page Page.close", "should reject all promises when page is closed")]
// [Ignore("TODO: See how to refactor this on nunit")]
public void ShouldRejectAllPromisesWhenPageIsClosed()
[Test, Retry(2), PuppeteerTest("page.spec", "Page Page.close", "should reject all promises when page is closed")]
public async Task ShouldRejectAllPromisesWhenPageIsClosed()
{
/*
var exceptionTask = Assert.ThrowsAsync<TargetClosedException>(() => Page.EvaluateFunctionAsync("() => new Promise(r => {})"));
TargetClosedException exception = null;

var exceptionTask = Assert.ThatAsync(async () =>
{
try
{
await Page.EvaluateFunctionAsync("() => new Promise(r => {})");
}
catch (TargetClosedException e)
{
exception = e;
throw;
}
}, Throws.InstanceOf<TargetClosedException>());

await Task.WhenAll(
exceptionTask,
Page.CloseAsync()
);

var exception = await exceptionTask;
StringAssert.Contains("Protocol error", exception.Message);
Assert.AreEqual("Target.detachedFromTarget", exception.CloseReason);
*/
Assert.That(exception.Message, Does.Contain("Protocol error"));
Assert.That(exception.CloseReason, Is.EqualTo("Target.detachedFromTarget"));
}

[Test, Retry(2), PuppeteerTest("page.spec", "Page Page.close", "should not be visible in browser.pages")]
Expand All @@ -36,6 +45,7 @@ public async Task ShouldNotBeVisibleInBrowserPages()
Assert.That(await browser.PagesAsync(), Does.Not.Contains(page));
}

[Test]
public async Task ShouldNotBeVisibleInBrowserPagesWithDisposeAsync()
{
await using var browser = await Puppeteer.LaunchAsync(TestConstants.DefaultBrowserOptions());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ await Page.EvaluateFunctionAsync(@"async () =>
await popupTarget.PageAsync();
}

[Test]
public async Task ShouldNotFailForNullArgument()
{
var consoleTcs = new TaskCompletionSource<string>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ await Page.EvaluateExpressionAsync(@"
Assert.That(sum, Is.EqualTo(500500));
}

[Test]
public async Task ShouldWorkWithAwaitedElements()
{
await Page.SetContentAsync("<div>hello</div><div>beautiful</div><div>world!</div>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public async Task ShouldWork()
Assert.That(idAttribute, Is.EqualTo("testAttribute"));
}

[Test]
public async Task ShouldWorkWithAwaitedElements()
{
await Page.SetContentAsync("<section id='testAttribute'>43543</section>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public async Task ShouldStringifyInterceptedRequestResponseHeaders()
Assert.That(await Page.EvaluateExpressionAsync<string>("document.body.textContent"), Is.EqualTo("Yo, page!"));
}

[Test]
public async Task ShouldAllowMultipleInterceptedRequestResponseHeaders()
{
await Page.SetRequestInterceptionAsync(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ await e.Request.RespondAsync(new ResponseData
Assert.That(await Page.EvaluateExpressionAsync<string>("document.body.textContent"), Is.EqualTo("Yo, page!"));
}

[Test]
public async Task ShouldAllowMultipleInterceptedRequestResponseHeaders()
{
await Page.SetRequestInterceptionAsync(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace PuppeteerSharp.Tests.ScreenshotTests
{
public class PageScreenshotTests : PuppeteerBrowserContextBaseTest
{
[Test]
public async Task ShouldWorkWithFile()
{
var outputFile = Path.Combine(BaseDirectory, "output.png");
Expand Down Expand Up @@ -123,6 +124,7 @@ await page.SetViewportAsync(new ViewPortOptions
Assert.That(ScreenshotHelper.PixelMatch("screenshot-clip-rect-scale2.png", screenshot), Is.True);
}

[Test]
public async Task ShouldClipScale()
{
await using var page = await Context.NewPageAsync();
Expand Down Expand Up @@ -359,6 +361,7 @@ await page.SetViewportAsync(new ViewPortOptions
Assert.That(screenshot, Is.Not.Empty);
}

[Test]
public void ShouldInferScreenshotTypeFromName()
{
Assert.That(ScreenshotOptions.GetScreenshotTypeFromFile("Test.jpg"), Is.EqualTo(ScreenshotType.Jpeg));
Expand All @@ -368,6 +371,7 @@ public void ShouldInferScreenshotTypeFromName()
Assert.That(ScreenshotOptions.GetScreenshotTypeFromFile("Test.exe"), Is.Null);
}

[Test]
public async Task ShouldWorkWithQuality()
{
await using var page = await Context.NewPageAsync();
Expand Down

0 comments on commit 9e18877

Please sign in to comment.