Skip to content

Commit

Permalink
Fix some builds
Browse files Browse the repository at this point in the history
  • Loading branch information
kblok committed Nov 14, 2023
1 parent c5587b4 commit e03f130
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -1,34 +1,22 @@
using System;
using System.Configuration;
using System.Diagnostics;
using System.Linq;
using System.Reflection.Metadata;
using System.Reflection.PortableExecutable;
using System.Threading.Tasks;
using System.Xml.Linq;
using Microsoft.AspNetCore.Hosting.Server;
using PuppeteerSharp.Tests.Attributes;
using PuppeteerSharp.Nunit;
using SixLabors.ImageSharp;
using static System.Net.Mime.MediaTypeNames;
using NUnit.Framework;

namespace PuppeteerSharp.Tests.AriaQueryHandlerTests
{
public class WaitForSelectorAriaTests : PuppeteerPageBaseTest
{
public WaitForSelectorAriaTests(): base()
{
}

const string addElement = @"(tag) => document.body.appendChild(document.createElement(tag))";
private const string AddElement = @"(tag) => document.body.appendChild(document.createElement(tag))";

[PuppeteerTest("ariaqueryhandler.spec.ts", "waitForSelector (aria)", "should immediately resolve promise if node exists")]
[Skip(SkipAttribute.Targets.Firefox)]
public async Task ShouldImmediatelyResolvePromiseIfNodeExists()
{
await Page.GoToAsync(TestConstants.EmptyPage);
await Page.EvaluateFunctionAsync(addElement, "button");
await Page.EvaluateFunctionAsync(AddElement, "button");
await Page.WaitForSelectorAsync("aria/[role=\"button\"]");
}

Expand All @@ -50,10 +38,10 @@ await Page.EvaluateFunctionAsync(
public async Task ShouldPersistQueryHandlerBindingsAcrossReloads()
{
await Page.GoToAsync(TestConstants.EmptyPage);
await Page.EvaluateFunctionAsync(addElement, "button");
await Page.EvaluateFunctionAsync(AddElement, "button");
await Page.WaitForSelectorAsync("aria/[role=\"button\"]");
await Page.ReloadAsync();
await Page.EvaluateFunctionAsync(addElement, "button");
await Page.EvaluateFunctionAsync(AddElement, "button");
await Page.WaitForSelectorAsync("aria/[role=\"button\"]");
}

Expand All @@ -62,10 +50,10 @@ public async Task ShouldPersistQueryHandlerBindingsAcrossReloads()
public async Task ShouldPersistQueryHandlerBindingsAcrossNavigations()
{
await Page.GoToAsync("data:text/html,");
await Page.EvaluateFunctionAsync(addElement, "button");
await Page.EvaluateFunctionAsync(AddElement, "button");
await Page.WaitForSelectorAsync("aria/[role=\"button\"]");
await Page.GoToAsync("data:text/html,");
await Page.EvaluateFunctionAsync(addElement, "button");
await Page.EvaluateFunctionAsync(AddElement, "button");
await Page.WaitForSelectorAsync("aria/[role=\"button\"]");
}

Expand All @@ -75,7 +63,7 @@ public async Task ShouldWorkIndependentlyOfExposeFunction()
{
await Page.GoToAsync(TestConstants.EmptyPage);
await Page.ExposeFunctionAsync("ariaQuerySelector", new Func<int, int, int>((a, b) => a + b));
await Page.EvaluateFunctionAsync(addElement, "button");
await Page.EvaluateFunctionAsync(AddElement, "button");
await Page.WaitForSelectorAsync("aria/[role=\"button\"]");
var result = await Page.EvaluateExpressionAsync<int>("globalThis.ariaQuerySelector(2,8)");
Assert.AreEqual(10, result);
Expand All @@ -101,8 +89,8 @@ public async Task ShouldResolvePromiseWhenNodeIsAdded()
await Page.GoToAsync(TestConstants.EmptyPage);
var frame = Page.MainFrame;
var watchdog = frame.WaitForSelectorAsync("aria/[role=\"heading\"]");
await frame.EvaluateFunctionAsync(addElement, "br");
await frame.EvaluateFunctionAsync(addElement, "h1");
await frame.EvaluateFunctionAsync(AddElement, "br");
await frame.EvaluateFunctionAsync(AddElement, "h1");
var elementHandle = await watchdog;
var tagName = await (
await elementHandle.GetPropertyAsync("tagName")
Expand All @@ -112,11 +100,11 @@ await elementHandle.GetPropertyAsync("tagName")

[PuppeteerTest("ariaqueryhandler.spec.ts", "waitForSelector (aria)", "should work when node is added through innerHTML")]
[Skip(SkipAttribute.Targets.Firefox)]
public async Task ShouldWorkWhenNodeIsAddedThroughInnerHTML()
public async Task ShouldWorkWhenNodeIsAddedThroughInnerHtml()
{
await Page.GoToAsync(TestConstants.EmptyPage);
var watchdog = Page.WaitForSelectorAsync("aria/name");
await Page.EvaluateFunctionAsync(addElement, "span");
await Page.EvaluateFunctionAsync(AddElement, "span");
await Page.EvaluateFunctionAsync(@"() => {
return (document.querySelector('span').innerHTML =
'<h3><div aria-label=""name""></div></h3>');
Expand All @@ -132,10 +120,10 @@ public async Task PageWaitForSelectorIsShortcutForMainFrame()
await FrameUtils.AttachFrameAsync(Page, "frame1", TestConstants.EmptyPage);
var otherFrame = Page.FirstChildFrame();
var watchdog = Page.WaitForSelectorAsync("aria/[role=\"button\"]");
await otherFrame.EvaluateFunctionAsync(addElement, "button");
await Page.EvaluateFunctionAsync(addElement, "button");
await otherFrame.EvaluateFunctionAsync(AddElement, "button");
await Page.EvaluateFunctionAsync(AddElement, "button");
var elementHandle = await watchdog;
Assert.AreSame(elementHandle.ExecutionContext.Frame, Page.MainFrame);
Assert.AreSame(elementHandle.Frame, Page.MainFrame);
}

[PuppeteerTest("ariaqueryhandler.spec.ts", "waitForSelector (aria)", "should run in specified frame")]
Expand All @@ -147,10 +135,10 @@ public async Task ShouldRunInSpecifiedFrame()
var frame1 = Page.Frames.First(frame => frame.Name == "frame1");
var frame2 = Page.Frames.First(frame => frame.Name == "frame2");
var waitForSelectorTask = frame2.WaitForSelectorAsync("aria/[role=\"button\"]");
await frame1.EvaluateFunctionAsync(addElement, "button");
await frame2.EvaluateFunctionAsync(addElement, "button");
await frame1.EvaluateFunctionAsync(AddElement, "button");
await frame2.EvaluateFunctionAsync(AddElement, "button");
var elementHandle = await waitForSelectorTask;
Assert.AreSame(elementHandle.ExecutionContext.Frame, frame2);
Assert.AreSame(elementHandle.Frame, frame2);
}
}
}
33 changes: 14 additions & 19 deletions lib/PuppeteerSharp.Tests/Issues/Issue1447.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
using System.Linq;
using System.Threading.Tasks;
using NUnit.Framework;
using PuppeteerSharp.Tests.Attributes;

namespace PuppeteerSharp.Tests.Issues
{
public class Issue1447 : PuppeteerPageBaseTest
{
public Issue1447(): base() { }

[Ignore("It's an example")]
public async Task Example()
{
Expand All @@ -19,24 +16,22 @@ public async Task Example()
IgnoredDefaultArgs = new[] { "--enable-automation" }
};

await using (var browser = await new Launcher().LaunchAsync(opts))
{
var pages = await browser.PagesAsync();
await using var browser = await new Launcher().LaunchAsync(opts);
var pages = await browser.PagesAsync();

var page = pages.ElementAt(0);
var page = pages.ElementAt(0);

for (int i = 0; i < 20; i++)
{
await Navigate(page, "https://distilnetworks.com");
await Navigate(page, "https://mail.com");
await Navigate(page, "https://distilnetworks.com");
await Navigate(page, "https://vk.com");
await Navigate(page, "https://distilnetworks.com");
await Navigate(page, "https://mail.com");
await Navigate(page, "https://distilnetworks.com");
await Navigate(page, "https://mail.com");
await Navigate(page, "about:blank");
}
for (var i = 0; i < 20; i++)
{
await Navigate(page, "https://distilnetworks.com");
await Navigate(page, "https://mail.com");
await Navigate(page, "https://distilnetworks.com");
await Navigate(page, "https://vk.com");
await Navigate(page, "https://distilnetworks.com");
await Navigate(page, "https://mail.com");
await Navigate(page, "https://distilnetworks.com");
await Navigate(page, "https://mail.com");
await Navigate(page, "about:blank");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ namespace PuppeteerSharp.Tests.WaitTaskTests
{
public class FrameWaitForSelectorTests : PuppeteerPageBaseTest
{
const string AddElement = "tag => document.body.appendChild(document.createElement(tag))";

public FrameWaitForSelectorTests(): base()
{
}
private const string AddElement = "tag => document.body.appendChild(document.createElement(tag))";

[PuppeteerTest("waittask.spec.ts", "Frame.waitForSelector", "should immediately resolve promise if node exists")]
[PuppeteerTimeout]
Expand Down Expand Up @@ -57,7 +53,7 @@ public async Task ShouldResolveTaskWhenNodeIsAdded()

[PuppeteerTest("waittask.spec.ts", "Frame.waitForSelector", "should work when node is added through innerHTML")]
[PuppeteerTimeout]
public async Task ShouldWorkWhenNodeIsAddedThroughInnerHTML()
public async Task ShouldWorkWhenNodeIsAddedThroughInnerHtml()
{
await Page.GoToAsync(TestConstants.EmptyPage);
var watchdog = Page.WaitForSelectorAsync("h3 div");
Expand All @@ -77,7 +73,7 @@ public async Task PageWaitForSelectorAsyncIsShortcutForMainFrame()
await otherFrame.EvaluateFunctionAsync(AddElement, "div");
await Page.EvaluateFunctionAsync(AddElement, "div");
var eHandle = await watchdog;
Assert.AreEqual(Page.MainFrame, eHandle.ExecutionContext.Frame);
Assert.AreEqual(Page.MainFrame, eHandle.Frame);
}

[PuppeteerTest("waittask.spec.ts", "Frame.waitForSelector", "should run in specified frame")]
Expand All @@ -92,7 +88,7 @@ public async Task ShouldRunInSpecifiedFrame()
await frame1.EvaluateFunctionAsync(AddElement, "div");
await frame2.EvaluateFunctionAsync(AddElement, "div");
var eHandle = await waitForSelectorPromise;
Assert.AreEqual(frame2, eHandle.ExecutionContext.Frame);
Assert.AreEqual(frame2, eHandle.Frame);
}

[PuppeteerTest("waittask.spec.ts", "Frame.waitForSelector", "should throw when frame is detached")]
Expand Down Expand Up @@ -162,7 +158,7 @@ public async Task ShouldWaitForVisibleVisibility()
public async Task ShouldWaitForVisibleBoundingBox()
{
var divFound = false;
var waitForSelector = Page.WaitForSelectorAsync("div", new WaitForSelectorOptions { Visible = true })
var _ = Page.WaitForSelectorAsync("div", new WaitForSelectorOptions { Visible = true })
.ContinueWith(_ => divFound = true);
await Page.SetContentAsync("<div style='width: 0;'>text</div>");
await Task.Delay(100);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ namespace PuppeteerSharp.Tests.WaitTaskTests
{
public sealed class FrameWaitForXPathTests : PuppeteerPageBaseTest
{
const string AddElement = "tag => document.body.appendChild(document.createElement(tag))";
private const string AddElement = "tag => document.body.appendChild(document.createElement(tag))";
private PollerInterceptor _pollerInterceptor;

public FrameWaitForXPathTests(): base()
public FrameWaitForXPathTests()
{
DefaultOptions = TestConstants.DefaultBrowserOptions();

Expand Down Expand Up @@ -59,7 +59,7 @@ public async Task ShouldRunInSpecifiedFrame()
await frame1.EvaluateFunctionAsync(AddElement, "div");
await frame2.EvaluateFunctionAsync(AddElement, "div");
var eHandle = await waitForXPathPromise;
Assert.AreEqual(frame2, eHandle.ExecutionContext.Frame);
Assert.AreEqual(frame2, eHandle.Frame);
}

[PuppeteerTest("waittask.spec.ts", "Frame.waitForXPath", "should throw when frame is detached")]
Expand Down Expand Up @@ -130,4 +130,4 @@ public void ShouldRespectTimeout()
}
}
}
#pragma warning restore CS0618
#pragma warning restore CS0618

0 comments on commit e03f130

Please sign in to comment.