forked from hardkoded/puppeteer-sharp
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add shadow DOM support (hardkoded#1994)
- Loading branch information
Showing
3 changed files
with
163 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ if($env:APPVEYOR_REPO_TAG -eq 'True' -And $env:framework -eq 'net6.0' -And $env: | |
|
||
git config --global user.email "[email protected]" | ||
git config --global user.name "Dario Kondratiuk" | ||
git remote add pages https://github.com/kblok/puppeteer-sharp.git | ||
git remote add pages https://github.com/hardkoded/puppeteer-sharp.git | ||
git fetch pages | ||
git checkout master | ||
git subtree add --prefix docs pages/gh-pages | ||
|
98 changes: 98 additions & 0 deletions
98
lib/PuppeteerSharp.Tests/QuerySelectorTests/PierceHandlerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.Xml.Linq; | ||
using PuppeteerSharp.Tests.Attributes; | ||
using PuppeteerSharp.Xunit; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using static System.Net.Mime.MediaTypeNames; | ||
|
||
namespace PuppeteerSharp.Tests.QuerySelectorTests | ||
{ | ||
[Collection(TestConstants.TestFixtureCollectionName)] | ||
public class PierceHandlerTests : PuppeteerPageBaseTest | ||
{ | ||
public PierceHandlerTests(ITestOutputHelper output) : base(output) | ||
{ | ||
} | ||
|
||
public override async Task InitializeAsync() | ||
{ | ||
await base.InitializeAsync(); | ||
|
||
await Page.SetContentAsync(@" | ||
<script> | ||
const div = document.createElement('div'); | ||
const shadowRoot = div.attachShadow({mode: 'open'}); | ||
const div1 = document.createElement('div'); | ||
div1.textContent = 'Hello'; | ||
div1.className = 'foo'; | ||
const div2 = document.createElement('div'); | ||
div2.textContent = 'World'; | ||
div2.className = 'foo'; | ||
shadowRoot.appendChild(div1); | ||
shadowRoot.appendChild(div2); | ||
document.documentElement.appendChild(div); | ||
</script> | ||
"); | ||
} | ||
public override Task DisposeAsync() | ||
{ | ||
Browser.ClearCustomQueryHandlers(); | ||
return base.DisposeAsync(); | ||
} | ||
|
||
[PuppeteerTest("queryselector.spec.ts", "pierceHandler", "should find first element in shadow")] | ||
[PuppeteerFact] | ||
public async Task ShouldFindFirstElementInShadow() | ||
{ | ||
var div = await Page.QuerySelectorAsync("pierce/.foo"); | ||
var text = await div.EvaluateFunctionAsync<string>(@"(element) => { | ||
return element.textContent; | ||
}"); | ||
Assert.Equal("Hello", text); | ||
} | ||
|
||
[PuppeteerTest("queryselector.spec.ts", "pierceHandler", "should find all elements in shadow")] | ||
[PuppeteerFact] | ||
public async Task ShouldFindAllElementsInShadow() | ||
{ | ||
var divs = await Page.QuerySelectorAllAsync("pierce/.foo"); | ||
var text = await Task.WhenAll( | ||
divs.Select(div => { | ||
return div.EvaluateFunctionAsync<string>(@"(element) => { | ||
return element.textContent; | ||
}"); | ||
})); | ||
Assert.Equal("Hello World", string.Join(" ", text)); | ||
} | ||
|
||
[PuppeteerTest("queryselector.spec.ts", "pierceHandler", "should find first child element")] | ||
[PuppeteerFact] | ||
public async Task ShouldFindFirstChildElement() | ||
{ | ||
var parentElement = await Page.QuerySelectorAsync("html > div"); | ||
var childElement = await parentElement.QuerySelectorAsync("pierce/div"); | ||
var text = await childElement.EvaluateFunctionAsync<string>(@"(element) => { | ||
return element.textContent; | ||
}"); | ||
Assert.Equal("Hello", text); | ||
} | ||
|
||
[PuppeteerTest("queryselector.spec.ts", "pierceHandler", "should find all child elements")] | ||
[PuppeteerFact] | ||
public async Task ShouldFindAllChildElements() | ||
{ | ||
var parentElement = await Page.QuerySelectorAsync("html > div"); | ||
var childElements = await parentElement.QuerySelectorAllAsync("pierce/div"); | ||
var text = await Task.WhenAll( | ||
childElements.Select(div => { | ||
return div.EvaluateFunctionAsync<string>(@"(element) => { | ||
return element.textContent; | ||
}"); | ||
})); | ||
Assert.Equal("Hello World", string.Join(" ", text)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters