Skip to content

Commit c18b339

Browse files
authored
Playwright driver (#231)
* Add playwright driver to project, implement visit * PlaywrightElement - 117/194 Driver tests passing * PlaywrightWindow - 133/194 Driver tests * Set fields. 147/194 driver tests * Typing in fields * Windows 166/194 DriverSpecs * Frames 181/191 driver specs * Improve headless section of readme * Implement dialog handling wrappers as per Capy+PW * Fix a few test on pw+firefox * Fix readme link
1 parent 522922a commit c18b339

File tree

76 files changed

+7298
-6176
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+7298
-6176
lines changed

History.md

Lines changed: 1008 additions & 1004 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 213 additions & 105 deletions
Large diffs are not rendered by default.
Lines changed: 159 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -1,158 +1,159 @@
1-
using System;
2-
using Coypu.Drivers;
3-
using Coypu.Drivers.Selenium;
4-
using NUnit.Framework;
5-
using OpenQA.Selenium;
6-
using OpenQA.Selenium.Firefox;
7-
8-
namespace Coypu.AcceptanceTests.Examples
9-
{
10-
/// <summary>
11-
/// Simple examples for each API method - to show usage and check everything is wired up properly
12-
/// </summary>
13-
[TestFixture]
14-
public class ApiExamples : WaitAndRetryExamples
15-
{
16-
public class CustomFirefoxOptionsSeleniumWebDriver : SeleniumWebDriver
17-
{
18-
public CustomFirefoxOptionsSeleniumWebDriver(Browser browser) : base(CustomOptions(), browser) { }
19-
20-
private static IWebDriver CustomOptions()
21-
{
22-
return new FirefoxDriver(new FirefoxOptions());
23-
}
24-
}
25-
26-
[Test]
27-
public void Attributes_on_stale_scope_example()
28-
{
29-
var field = Browser.FindField("find-this-field");
30-
Assert.That(field.Value, Is.EqualTo("This value is what we are looking for"));
31-
32-
ReloadTestPage();
33-
Assert.That(field.Value, Is.EqualTo("This value is what we are looking for"));
34-
Assert.That(field.Id, Is.EqualTo("find-this-field"));
35-
Assert.That(field["id"], Is.EqualTo("find-this-field"));
36-
}
37-
38-
[Test]
39-
public void Choose_example()
40-
{
41-
Browser.Choose("chooseRadio1");
42-
Assert.IsTrue(Browser.FindField("chooseRadio1")
43-
.Selected);
44-
45-
Browser.Choose("chooseRadio2");
46-
Assert.IsTrue(Browser.FindField("chooseRadio2")
47-
.Selected);
48-
Assert.IsFalse(Browser.FindField("chooseRadio1")
49-
.Selected);
50-
}
51-
52-
[Test]
53-
public void ConsideringInvisibleElements()
54-
{
55-
Browser.FindButton("firstInvisibleInputId", new Options {ConsiderInvisibleElements = true})
56-
.Now();
57-
}
58-
59-
[Test]
60-
public void ConsideringOnlyVisibleElements()
61-
{
62-
Assert.Throws<MissingHtmlException>(() => Browser.FindButton("firstInvisibleInputId")
63-
.Now());
64-
}
65-
66-
[Test]
67-
public void CustomOptions()
68-
{
69-
var configuration = new SessionConfiguration {Driver = typeof(CustomFirefoxOptionsSeleniumWebDriver)};
70-
using (var custom = new BrowserSession(configuration))
71-
{
72-
custom.Visit("https://www.relishapp.com/");
73-
Assert.That(custom.ExecuteScript("return 0;"), Is.EqualTo(0));
74-
}
75-
}
76-
77-
[Test]
78-
public void DisabledButton_example()
79-
{
80-
Assert.That(Browser.FindButton("Disabled button")
81-
.Disabled,
82-
Is.True,
83-
"Expected button to be disabled");
84-
Assert.That(Browser.FindButton("Click me")
85-
.Disabled,
86-
Is.False,
87-
"Expected button to be enabled");
88-
}
89-
90-
[Test]
91-
public void ExecuteScript_example()
92-
{
93-
ReloadTestPage();
94-
Assert.That(Browser.ExecuteScript("return document.getElementById('firstButtonId').innerHTML;"),
95-
Is.EqualTo("first button"));
96-
}
97-
98-
[Test]
99-
public void ExecuteScriptWithArgs_example()
100-
{
101-
ReloadTestPage();
102-
Assert.That(Browser.ExecuteScript("return arguments[0].innerHTML;", Browser.FindId("firstButtonId")),
103-
Is.EqualTo("first button"));
104-
}
105-
106-
[Test]
107-
public void Hover_example()
108-
{
109-
Assert.That(Browser.FindId("hoverOnMeTest")
110-
.Text,
111-
Is.EqualTo("Hover on me"));
112-
Browser.FindId("hoverOnMeTest")
113-
.Hover();
114-
Assert.That(Browser.FindId("hoverOnMeTest")
115-
.Text,
116-
Is.EqualTo("Hover on me - hovered"));
117-
}
118-
119-
[Test]
120-
public void Multiple_interactions_within_iframe_example()
121-
{
122-
var iframe = Browser.FindFrame("I am iframe one");
123-
iframe.FillIn("text input in iframe")
124-
.With("filled in");
125-
Assert.That(iframe.FindField("text input in iframe")
126-
.Value,
127-
Is.EqualTo("filled in"));
128-
}
129-
130-
[Test]
131-
public void Native_example()
132-
{
133-
var button = (IWebElement) Browser.FindButton("clickMeTest")
134-
.Native;
135-
button.Click();
136-
Assert.That(Browser.FindButton("clickMeTest")
137-
.Value,
138-
Is.EqualTo("Click me - clicked"));
139-
}
140-
141-
[Test]
142-
public void Title_example()
143-
{
144-
Assert.That(Browser.Title, Is.EqualTo("Coypu interaction tests page"));
145-
}
146-
147-
[Test]
148-
public void TryUntil_example()
149-
{
150-
var tryThisButton = Browser.FindButton("try this");
151-
Assert.That(tryThisButton.Exists());
152-
Browser.TryUntil(() => tryThisButton.Click(),
153-
() => Browser.HasContent("try until 5"),
154-
TimeSpan.FromMilliseconds(50),
155-
new Options {Timeout = TimeSpan.FromMilliseconds(10000)});
156-
}
157-
}
158-
}
1+
using System;
2+
using Coypu.Drivers;
3+
using Coypu.Drivers.Selenium;
4+
using Microsoft.Playwright;
5+
using NUnit.Framework;
6+
using OpenQA.Selenium;
7+
using OpenQA.Selenium.Firefox;
8+
9+
namespace Coypu.AcceptanceTests.Examples
10+
{
11+
/// <summary>
12+
/// Simple examples for each API method - to show usage and check everything is wired up properly
13+
/// </summary>
14+
[TestFixture]
15+
public class ApiExamples : WaitAndRetryExamples
16+
{
17+
public class CustomFirefoxOptionsSeleniumWebDriver : SeleniumWebDriver
18+
{
19+
public CustomFirefoxOptionsSeleniumWebDriver(Browser browser, bool headless) : base(CustomOptions(), browser) { }
20+
21+
private static IWebDriver CustomOptions()
22+
{
23+
return new FirefoxDriver(new FirefoxOptions());
24+
}
25+
}
26+
27+
[Test]
28+
public void Attributes_on_stale_scope_example()
29+
{
30+
var field = Browser.FindField("find-this-field");
31+
Assert.That(field.Value, Is.EqualTo("This value is what we are looking for"));
32+
33+
ReloadTestPage();
34+
Assert.That(field.Value, Is.EqualTo("This value is what we are looking for"));
35+
Assert.That(field.Id, Is.EqualTo("find-this-field"));
36+
Assert.That(field["id"], Is.EqualTo("find-this-field"));
37+
}
38+
39+
[Test]
40+
public void Choose_example()
41+
{
42+
Browser.Choose("chooseRadio1");
43+
Assert.IsTrue(Browser.FindField("chooseRadio1")
44+
.Selected);
45+
46+
Browser.Choose("chooseRadio2");
47+
Assert.IsTrue(Browser.FindField("chooseRadio2")
48+
.Selected);
49+
Assert.IsFalse(Browser.FindField("chooseRadio1")
50+
.Selected);
51+
}
52+
53+
[Test]
54+
public void ConsideringInvisibleElements()
55+
{
56+
Browser.FindButton("firstInvisibleInputId", new Options {ConsiderInvisibleElements = true})
57+
.Now();
58+
}
59+
60+
[Test]
61+
public void ConsideringOnlyVisibleElements()
62+
{
63+
Assert.Throws<MissingHtmlException>(() => Browser.FindButton("firstInvisibleInputId")
64+
.Now());
65+
}
66+
67+
[Test]
68+
public void CustomOptions()
69+
{
70+
var configuration = new SessionConfiguration {Driver = typeof(CustomFirefoxOptionsSeleniumWebDriver)};
71+
using (var custom = new BrowserSession(configuration))
72+
{
73+
custom.Visit("https://www.relishapp.com/");
74+
Assert.That(custom.ExecuteScript("return 0;"), Is.EqualTo(0));
75+
}
76+
}
77+
78+
[Test]
79+
public void DisabledButton_example()
80+
{
81+
Assert.That(Browser.FindButton("Disabled button")
82+
.Disabled,
83+
Is.True,
84+
"Expected button to be disabled");
85+
Assert.That(Browser.FindButton("Click me")
86+
.Disabled,
87+
Is.False,
88+
"Expected button to be enabled");
89+
}
90+
91+
[Test]
92+
public void ExecuteScript_example()
93+
{
94+
ReloadTestPage();
95+
Assert.That(Browser.ExecuteScript("return document.getElementById('firstButtonId').innerHTML;"),
96+
Is.EqualTo("first button"));
97+
}
98+
99+
[Test]
100+
public void ExecuteScriptWithArgs_example()
101+
{
102+
ReloadTestPage();
103+
Assert.That(Browser.ExecuteScript("return arguments[0].innerHTML;", Browser.FindId("firstButtonId")),
104+
Is.EqualTo("first button"));
105+
}
106+
107+
[Test]
108+
public void Hover_example()
109+
{
110+
Assert.That(Browser.FindId("hoverOnMeTest")
111+
.Text,
112+
Is.EqualTo("Hover on me"));
113+
Browser.FindId("hoverOnMeTest")
114+
.Hover();
115+
Assert.That(Browser.FindId("hoverOnMeTest")
116+
.Text,
117+
Is.EqualTo("Hover on me - hovered"));
118+
}
119+
120+
[Test]
121+
public void Multiple_interactions_within_iframe_example()
122+
{
123+
var iframe = Browser.FindFrame("I am iframe one");
124+
iframe.FillIn("text input in iframe")
125+
.With("filled in");
126+
Assert.That(iframe.FindField("text input in iframe")
127+
.Value,
128+
Is.EqualTo("filled in"));
129+
}
130+
131+
[Test]
132+
public void Native_example()
133+
{
134+
var button = (IElementHandle) Browser.FindButton("clickMeTest")
135+
.Native;
136+
button.ClickAsync().Sync();
137+
Assert.That(Browser.FindButton("clickMeTest")
138+
.Value,
139+
Is.EqualTo("Click me - clicked"));
140+
}
141+
142+
[Test]
143+
public void Title_example()
144+
{
145+
Assert.That(Browser.Title, Is.EqualTo("Coypu interaction tests page"));
146+
}
147+
148+
[Test]
149+
public void TryUntil_example()
150+
{
151+
var tryThisButton = Browser.FindButton("try this");
152+
Assert.That(tryThisButton.Exists());
153+
Browser.TryUntil(() => tryThisButton.Click(),
154+
() => Browser.HasContent("try until 5"),
155+
TimeSpan.FromMilliseconds(50),
156+
new Options {Timeout = TimeSpan.FromMilliseconds(10000)});
157+
}
158+
}
159+
}

src/Coypu.AcceptanceTests/Examples/ClickExamples.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Diagnostics;
3+
using System.Threading;
34
using NUnit.Framework;
5+
using OpenQA.Selenium.DevTools.V85.Network;
46

57
namespace Coypu.AcceptanceTests.Examples
68
{
@@ -48,28 +50,31 @@ public void ClickButton_WaitBeforeClick()
4850
[Test]
4951
public void ClickLink()
5052
{
51-
Browser.ClickLink("Trigger a confirm");
52-
Browser.CancelModalDialog();
53+
Browser.CancelConfirm(() => {
54+
Browser.ClickLink("Trigger a confirm");
55+
});
5356
}
5457

5558
[Test]
5659
public void ClickLink_WaitBeforeClick()
5760
{
5861
var stopWatch = Stopwatch.StartNew();
59-
60-
Browser.ClickLink("Trigger a confirm", _optionsWaitBeforeClick);
61-
var actualWait = stopWatch.ElapsedMilliseconds;
62-
Console.WriteLine($"\t-> Actual wait before click {actualWait} milliseconds");
63-
Browser.CancelModalDialog();
62+
long actualWait = 0;
63+
Browser.CancelConfirm(() => {
64+
Browser.ClickLink("Trigger a confirm", _optionsWaitBeforeClick);
65+
actualWait = stopWatch.ElapsedMilliseconds;
66+
Console.WriteLine($"\t-> Actual wait before click {actualWait} milliseconds");
67+
});
6468

6569
Assert.That(actualWait > WaitBeforeClickInSec.TotalMilliseconds, "\tDidn't wait enough!");
6670
}
6771

6872
[Test]
6973
public void ClickLink_WithTitle()
7074
{
71-
Browser.ClickLink("Link with title");
72-
Browser.CancelModalDialog();
75+
Browser.CancelConfirm(() => {
76+
Browser.ClickLink("Link with title");
77+
});
7378
}
7479

7580
[Test]
@@ -85,4 +90,4 @@ public void Click_WaitBeforeClick()
8590
Assert.That(actualWait > WaitBeforeClickInSec.TotalMilliseconds, "\tDidn't wait enough!");
8691
}
8792
}
88-
}
93+
}

0 commit comments

Comments
 (0)