Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,6 @@
"parameters": ["headful"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[elementhandle-convenience.spec.ts] *",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["headful"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[elementhandle-eval-on-selector.spec.ts] *",
"platforms": ["darwin", "linux", "win32"],
Expand Down
120 changes: 8 additions & 112 deletions src/PlaywrightSharp.Tests/ElementHandleConvenienceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public async Task GetAttributeShouldWork()
var handle = await Page.QuerySelectorAsync("#outer");

Assert.That(await handle.GetAttributeAsync("name"), Is.EqualTo("value"));
Assert.That(await handle.GetAttributeAsync("foo"), Is.Null);
Assert.That(await Page.GetAttributeAsync("#outer", "name"), Is.EqualTo("value"));
Assert.That(await Page.GetAttributeAsync("#outer", "foo"), Is.Null);
}

[PlaywrightTest("elementhandle-convenience.spec.ts", "innerHTML should work")]
Expand All @@ -57,7 +59,7 @@ public async Task InnerTextShouldWork()
Assert.That(await Page.InnerTextAsync("#inner"), Is.EqualTo("Text, more text"));
}

[PlaywrightTest("elementhandle-convenience.spec.ts", "'innerText should throw")]
[PlaywrightTest("elementhandle-convenience.spec.ts", "innerText should throw")]
[Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task InnerTextShouldThrow()
{
Expand All @@ -67,126 +69,18 @@ public async Task InnerTextShouldThrow()

var handle = await Page.QuerySelectorAsync("svg");
var exception2 = Assert.CatchAsync<PlaywrightSharpException>(() => handle.InnerTextAsync());
Assert.That(exception1.Message, Does.Contain("Not an HTMLElement"));
Assert.That(exception2.Message, Does.Contain("Not an HTMLElement"));
}

[PlaywrightTest("elementhandle-convenience.spec.ts", "textContent should work")]
[Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task TextContentShouldWork()
{
await Page.GoToAsync(TestConstants.ServerUrl + "/dom.html");
var handle = await Page.QuerySelectorAsync("#outer");
var handle = await Page.QuerySelectorAsync("#inner");

Assert.That(await handle.TextContentAsync(), Is.EqualTo("Text,\nmore text"));
Assert.That(await Page.TextContentAsync("#outer"), Is.EqualTo("Text,\nmore text"));
}

[PlaywrightTest("elementhandle-convenience.spec.ts", "Page.dispatchEvent(click)", "textContent should be atomic")]
[Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task TextContentShouldBeAtomic()
{
const string createDummySelector = @"({
create(root, target) { },
query(root, selector) {
const result = root.querySelector(selector);
if (result)
Promise.resolve().then(() => result.textContent = 'modified');
return result;
},
queryAll(root, selector) {
const result = Array.from(root.querySelectorAll(selector));
for (const e of result)
Promise.resolve().then(() => e.textContent = 'modified');
return result;
}
})";

await TestUtils.RegisterEngineAsync(Playwright, "textContent", createDummySelector);
await Page.SetContentAsync("<div>Hello</div>");
string tc = await Page.TextContentAsync("textContent=div");
Assert.That(tc, Is.EqualTo("Hello"));
Assert.That(await Page.EvaluateAsync<string>("() => document.querySelector('div').textContent"), Is.EqualTo("modified"));
}

[PlaywrightTest("elementhandle-convenience.spec.ts", "Page.dispatchEvent(click)", "innerText should be atomic")]
[Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task InnerTextShouldBeAtomic()
{
const string createDummySelector = @"({
create(root, target) { },
query(root, selector) {
const result = root.querySelector(selector);
if (result)
Promise.resolve().then(() => result.textContent = 'modified');
return result;
},
queryAll(root, selector) {
const result = Array.from(root.querySelectorAll(selector));
for (const e of result)
Promise.resolve().then(() => e.textContent = 'modified');
return result;
}
})";

await TestUtils.RegisterEngineAsync(Playwright, "innerText", createDummySelector);
await Page.SetContentAsync("<div>Hello</div>");
string tc = await Page.InnerTextAsync("innerText=div");
Assert.That(tc, Is.EqualTo("Hello"));
Assert.That(await Page.EvaluateAsync<string>("() => document.querySelector('div').textContent"), Is.EqualTo("modified"));
}

[PlaywrightTest("elementhandle-convenience.spec.ts", "Page.dispatchEvent(click)", "innerHTML should be atomic")]
[Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task InnerHtmlShouldBeAtomic()
{
const string createDummySelector = @"({
create(root, target) { },
query(root, selector) {
const result = root.querySelector(selector);
if (result)
Promise.resolve().then(() => result.textContent = 'modified');
return result;
},
queryAll(root, selector) {
const result = Array.from(root.querySelectorAll(selector));
for (const e of result)
Promise.resolve().then(() => e.textContent = 'modified');
return result;
}
})";

await TestUtils.RegisterEngineAsync(Playwright, "innerHtml", createDummySelector);
await Page.SetContentAsync("<div>Hello</div>");
string tc = await Page.InnerHTMLAsync("innerHtml=div");
Assert.That(tc, Is.EqualTo("Hello"));
Assert.That(await Page.EvaluateAsync<string>("() => document.querySelector('div').textContent"), Is.EqualTo("modified"));
}

[PlaywrightTest("elementhandle-convenience.spec.ts", "Page.dispatchEvent(click)", "getAttribute should be atomic")]
[Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task GetAttributeShouldBeAtomic()
{
const string createDummySelector = @"({
create(root, target) { },
query(root, selector) {
const result = root.querySelector(selector);
if (result)
Promise.resolve().then(() => result.setAttribute('foo', 'modified'));
return result;
},
queryAll(root, selector) {
const result = Array.from(root.querySelectorAll(selector));
for (const e of result)
Promise.resolve().then(() => e.setAttribute('foo', 'modified'));
return result;
}
})";

await TestUtils.RegisterEngineAsync(Playwright, "getAttribute", createDummySelector);
await Page.SetContentAsync("<div foo=Hello></div>");
string tc = await Page.GetAttributeAsync("getAttribute=div", "foo");
Assert.That(tc, Is.EqualTo("Hello"));
Assert.That(await Page.EvaluateAsync<string>("() => document.querySelector('div').getAttribute('foo')"), Is.EqualTo("modified"));
Assert.That(await Page.TextContentAsync("#inner"), Is.EqualTo("Text,\nmore text"));
}

[PlaywrightTest("elementhandle-convenience.spec.ts", "isVisible and isHidden should work")]
Expand All @@ -204,6 +98,8 @@ public async Task IsVisibleAndIsHiddenShouldWork()
Assert.That(await span.IsHiddenAsync(), Is.True);
Assert.That(await Page.IsVisibleAsync("span"), Is.False);
Assert.That(await Page.IsHiddenAsync("span"), Is.True);
Assert.That(await Page.IsVisibleAsync("no-such-element"), Is.False);
Assert.That(await Page.IsHiddenAsync("no-such-element"), Is.True);
}

[PlaywrightTest("elementhandle-convenience.spec.ts", "isEnabled and isDisabled should work")]
Expand Down
104 changes: 104 additions & 0 deletions src/PlaywrightSharp.Tests/SelectorsRegisterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,110 @@ public async Task ShouldWorkInMainAndIsolatedWorld()
Assert.That(await Page.EvalOnSelectorAsync<string>("main=ignored >> css=section", "e => e.nodeName"), Is.EqualTo("SECTION"));
}

[PlaywrightTest("selectors-register.spec.ts", "textContent should be atomic")]
[Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task TextContentShouldBeAtomic()
{
const string createDummySelector = @"({
query(root, selector) {
const result = root.querySelector(selector);
if (result)
Promise.resolve().then(() => result.textContent = 'modified');
return result;
},
queryAll(root, selector) {
const result = Array.from(root.querySelectorAll(selector));
for (const e of result)
Promise.resolve().then(() => e.textContent = 'modified');
return result;
}
})";

await TestUtils.RegisterEngineAsync(Playwright, "textContent", createDummySelector);
await Page.SetContentAsync("<div>Hello</div>");
string tc = await Page.TextContentAsync("textContent=div");
Assert.That(tc, Is.EqualTo("Hello"));
Assert.That(await Page.EvaluateAsync<string>("() => document.querySelector('div').textContent"), Is.EqualTo("modified"));
}

[PlaywrightTest("selectors-register.spec.ts", "innerText should be atomic")]
[Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task InnerTextShouldBeAtomic()
{
const string createDummySelector = @"({
query(root, selector) {
const result = root.querySelector(selector);
if (result)
Promise.resolve().then(() => result.textContent = 'modified');
return result;
},
queryAll(root, selector) {
const result = Array.from(root.querySelectorAll(selector));
for (const e of result)
Promise.resolve().then(() => e.textContent = 'modified');
return result;
}
})";

await TestUtils.RegisterEngineAsync(Playwright, "innerText", createDummySelector);
await Page.SetContentAsync("<div>Hello</div>");
string tc = await Page.InnerTextAsync("innerText=div");
Assert.That(tc, Is.EqualTo("Hello"));
Assert.That(await Page.EvaluateAsync<string>("() => document.querySelector('div').textContent"), Is.EqualTo("modified"));
}

[PlaywrightTest("selectors-register.spec.ts", "innerHTML should be atomic")]
[Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task InnerHtmlShouldBeAtomic()
{
const string createDummySelector = @"({
query(root, selector) {
const result = root.querySelector(selector);
if (result)
Promise.resolve().then(() => result.textContent = 'modified');
return result;
},
queryAll(root, selector) {
const result = Array.from(root.querySelectorAll(selector));
for (const e of result)
Promise.resolve().then(() => e.textContent = 'modified');
return result;
}
})";

await TestUtils.RegisterEngineAsync(Playwright, "innerHtml", createDummySelector);
await Page.SetContentAsync("<div>Hello</div>");
string tc = await Page.InnerHTMLAsync("innerHtml=div");
Assert.That(tc, Is.EqualTo("Hello"));
Assert.That(await Page.EvaluateAsync<string>("() => document.querySelector('div').textContent"), Is.EqualTo("modified"));
}

[PlaywrightTest("selectors-register.spec.ts", "getAttribute should be atomic")]
[Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task GetAttributeShouldBeAtomic()
{
const string createDummySelector = @"({
query(root, selector) {
const result = root.querySelector(selector);
if (result)
Promise.resolve().then(() => result.setAttribute('foo', 'modified'));
return result;
},
queryAll(root, selector) {
const result = Array.from(root.querySelectorAll(selector));
for (const e of result)
Promise.resolve().then(() => e.setAttribute('foo', 'modified'));
return result;
}
})";

await TestUtils.RegisterEngineAsync(Playwright, "getAttribute", createDummySelector);
await Page.SetContentAsync("<div foo=Hello></div>");
string tc = await Page.GetAttributeAsync("getAttribute=div", "foo");
Assert.That(tc, Is.EqualTo("Hello"));
Assert.That(await Page.EvaluateAsync<string>("() => document.querySelector('div').getAttribute('foo')"), Is.EqualTo("modified"));
}

[PlaywrightTest("selectors-register.spec.ts", "should handle errors")]
[Test, Timeout(TestConstants.DefaultTestTimeout)]
public async Task ShouldHandleErrors()
Expand Down
Loading