Skip to content

Commit

Permalink
Playwright driver (#231)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
adiel authored Jan 2, 2024
1 parent 522922a commit c18b339
Show file tree
Hide file tree
Showing 76 changed files with 7,298 additions and 6,176 deletions.
2,012 changes: 1,008 additions & 1,004 deletions History.md

Large diffs are not rendered by default.

318 changes: 213 additions & 105 deletions README.md

Large diffs are not rendered by default.

317 changes: 159 additions & 158 deletions src/Coypu.AcceptanceTests/Examples/ApiExamples.cs
Original file line number Diff line number Diff line change
@@ -1,158 +1,159 @@
using System;
using Coypu.Drivers;
using Coypu.Drivers.Selenium;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;

namespace Coypu.AcceptanceTests.Examples
{
/// <summary>
/// Simple examples for each API method - to show usage and check everything is wired up properly
/// </summary>
[TestFixture]
public class ApiExamples : WaitAndRetryExamples
{
public class CustomFirefoxOptionsSeleniumWebDriver : SeleniumWebDriver
{
public CustomFirefoxOptionsSeleniumWebDriver(Browser browser) : base(CustomOptions(), browser) { }

private static IWebDriver CustomOptions()
{
return new FirefoxDriver(new FirefoxOptions());
}
}

[Test]
public void Attributes_on_stale_scope_example()
{
var field = Browser.FindField("find-this-field");
Assert.That(field.Value, Is.EqualTo("This value is what we are looking for"));

ReloadTestPage();
Assert.That(field.Value, Is.EqualTo("This value is what we are looking for"));
Assert.That(field.Id, Is.EqualTo("find-this-field"));
Assert.That(field["id"], Is.EqualTo("find-this-field"));
}

[Test]
public void Choose_example()
{
Browser.Choose("chooseRadio1");
Assert.IsTrue(Browser.FindField("chooseRadio1")
.Selected);

Browser.Choose("chooseRadio2");
Assert.IsTrue(Browser.FindField("chooseRadio2")
.Selected);
Assert.IsFalse(Browser.FindField("chooseRadio1")
.Selected);
}

[Test]
public void ConsideringInvisibleElements()
{
Browser.FindButton("firstInvisibleInputId", new Options {ConsiderInvisibleElements = true})
.Now();
}

[Test]
public void ConsideringOnlyVisibleElements()
{
Assert.Throws<MissingHtmlException>(() => Browser.FindButton("firstInvisibleInputId")
.Now());
}

[Test]
public void CustomOptions()
{
var configuration = new SessionConfiguration {Driver = typeof(CustomFirefoxOptionsSeleniumWebDriver)};
using (var custom = new BrowserSession(configuration))
{
custom.Visit("https://www.relishapp.com/");
Assert.That(custom.ExecuteScript("return 0;"), Is.EqualTo(0));
}
}

[Test]
public void DisabledButton_example()
{
Assert.That(Browser.FindButton("Disabled button")
.Disabled,
Is.True,
"Expected button to be disabled");
Assert.That(Browser.FindButton("Click me")
.Disabled,
Is.False,
"Expected button to be enabled");
}

[Test]
public void ExecuteScript_example()
{
ReloadTestPage();
Assert.That(Browser.ExecuteScript("return document.getElementById('firstButtonId').innerHTML;"),
Is.EqualTo("first button"));
}

[Test]
public void ExecuteScriptWithArgs_example()
{
ReloadTestPage();
Assert.That(Browser.ExecuteScript("return arguments[0].innerHTML;", Browser.FindId("firstButtonId")),
Is.EqualTo("first button"));
}

[Test]
public void Hover_example()
{
Assert.That(Browser.FindId("hoverOnMeTest")
.Text,
Is.EqualTo("Hover on me"));
Browser.FindId("hoverOnMeTest")
.Hover();
Assert.That(Browser.FindId("hoverOnMeTest")
.Text,
Is.EqualTo("Hover on me - hovered"));
}

[Test]
public void Multiple_interactions_within_iframe_example()
{
var iframe = Browser.FindFrame("I am iframe one");
iframe.FillIn("text input in iframe")
.With("filled in");
Assert.That(iframe.FindField("text input in iframe")
.Value,
Is.EqualTo("filled in"));
}

[Test]
public void Native_example()
{
var button = (IWebElement) Browser.FindButton("clickMeTest")
.Native;
button.Click();
Assert.That(Browser.FindButton("clickMeTest")
.Value,
Is.EqualTo("Click me - clicked"));
}

[Test]
public void Title_example()
{
Assert.That(Browser.Title, Is.EqualTo("Coypu interaction tests page"));
}

[Test]
public void TryUntil_example()
{
var tryThisButton = Browser.FindButton("try this");
Assert.That(tryThisButton.Exists());
Browser.TryUntil(() => tryThisButton.Click(),
() => Browser.HasContent("try until 5"),
TimeSpan.FromMilliseconds(50),
new Options {Timeout = TimeSpan.FromMilliseconds(10000)});
}
}
}
using System;
using Coypu.Drivers;
using Coypu.Drivers.Selenium;
using Microsoft.Playwright;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;

namespace Coypu.AcceptanceTests.Examples
{
/// <summary>
/// Simple examples for each API method - to show usage and check everything is wired up properly
/// </summary>
[TestFixture]
public class ApiExamples : WaitAndRetryExamples
{
public class CustomFirefoxOptionsSeleniumWebDriver : SeleniumWebDriver
{
public CustomFirefoxOptionsSeleniumWebDriver(Browser browser, bool headless) : base(CustomOptions(), browser) { }

private static IWebDriver CustomOptions()
{
return new FirefoxDriver(new FirefoxOptions());
}
}

[Test]
public void Attributes_on_stale_scope_example()
{
var field = Browser.FindField("find-this-field");
Assert.That(field.Value, Is.EqualTo("This value is what we are looking for"));

ReloadTestPage();
Assert.That(field.Value, Is.EqualTo("This value is what we are looking for"));
Assert.That(field.Id, Is.EqualTo("find-this-field"));
Assert.That(field["id"], Is.EqualTo("find-this-field"));
}

[Test]
public void Choose_example()
{
Browser.Choose("chooseRadio1");
Assert.IsTrue(Browser.FindField("chooseRadio1")
.Selected);

Browser.Choose("chooseRadio2");
Assert.IsTrue(Browser.FindField("chooseRadio2")
.Selected);
Assert.IsFalse(Browser.FindField("chooseRadio1")
.Selected);
}

[Test]
public void ConsideringInvisibleElements()
{
Browser.FindButton("firstInvisibleInputId", new Options {ConsiderInvisibleElements = true})
.Now();
}

[Test]
public void ConsideringOnlyVisibleElements()
{
Assert.Throws<MissingHtmlException>(() => Browser.FindButton("firstInvisibleInputId")
.Now());
}

[Test]
public void CustomOptions()
{
var configuration = new SessionConfiguration {Driver = typeof(CustomFirefoxOptionsSeleniumWebDriver)};
using (var custom = new BrowserSession(configuration))
{
custom.Visit("https://www.relishapp.com/");
Assert.That(custom.ExecuteScript("return 0;"), Is.EqualTo(0));
}
}

[Test]
public void DisabledButton_example()
{
Assert.That(Browser.FindButton("Disabled button")
.Disabled,
Is.True,
"Expected button to be disabled");
Assert.That(Browser.FindButton("Click me")
.Disabled,
Is.False,
"Expected button to be enabled");
}

[Test]
public void ExecuteScript_example()
{
ReloadTestPage();
Assert.That(Browser.ExecuteScript("return document.getElementById('firstButtonId').innerHTML;"),
Is.EqualTo("first button"));
}

[Test]
public void ExecuteScriptWithArgs_example()
{
ReloadTestPage();
Assert.That(Browser.ExecuteScript("return arguments[0].innerHTML;", Browser.FindId("firstButtonId")),
Is.EqualTo("first button"));
}

[Test]
public void Hover_example()
{
Assert.That(Browser.FindId("hoverOnMeTest")
.Text,
Is.EqualTo("Hover on me"));
Browser.FindId("hoverOnMeTest")
.Hover();
Assert.That(Browser.FindId("hoverOnMeTest")
.Text,
Is.EqualTo("Hover on me - hovered"));
}

[Test]
public void Multiple_interactions_within_iframe_example()
{
var iframe = Browser.FindFrame("I am iframe one");
iframe.FillIn("text input in iframe")
.With("filled in");
Assert.That(iframe.FindField("text input in iframe")
.Value,
Is.EqualTo("filled in"));
}

[Test]
public void Native_example()
{
var button = (IElementHandle) Browser.FindButton("clickMeTest")
.Native;
button.ClickAsync().Sync();
Assert.That(Browser.FindButton("clickMeTest")
.Value,
Is.EqualTo("Click me - clicked"));
}

[Test]
public void Title_example()
{
Assert.That(Browser.Title, Is.EqualTo("Coypu interaction tests page"));
}

[Test]
public void TryUntil_example()
{
var tryThisButton = Browser.FindButton("try this");
Assert.That(tryThisButton.Exists());
Browser.TryUntil(() => tryThisButton.Click(),
() => Browser.HasContent("try until 5"),
TimeSpan.FromMilliseconds(50),
new Options {Timeout = TimeSpan.FromMilliseconds(10000)});
}
}
}
25 changes: 15 additions & 10 deletions src/Coypu.AcceptanceTests/Examples/ClickExamples.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Diagnostics;
using System.Threading;
using NUnit.Framework;
using OpenQA.Selenium.DevTools.V85.Network;

namespace Coypu.AcceptanceTests.Examples
{
Expand Down Expand Up @@ -48,28 +50,31 @@ public void ClickButton_WaitBeforeClick()
[Test]
public void ClickLink()
{
Browser.ClickLink("Trigger a confirm");
Browser.CancelModalDialog();
Browser.CancelConfirm(() => {
Browser.ClickLink("Trigger a confirm");
});
}

[Test]
public void ClickLink_WaitBeforeClick()
{
var stopWatch = Stopwatch.StartNew();

Browser.ClickLink("Trigger a confirm", _optionsWaitBeforeClick);
var actualWait = stopWatch.ElapsedMilliseconds;
Console.WriteLine($"\t-> Actual wait before click {actualWait} milliseconds");
Browser.CancelModalDialog();
long actualWait = 0;
Browser.CancelConfirm(() => {
Browser.ClickLink("Trigger a confirm", _optionsWaitBeforeClick);
actualWait = stopWatch.ElapsedMilliseconds;
Console.WriteLine($"\t-> Actual wait before click {actualWait} milliseconds");
});

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

[Test]
public void ClickLink_WithTitle()
{
Browser.ClickLink("Link with title");
Browser.CancelModalDialog();
Browser.CancelConfirm(() => {
Browser.ClickLink("Link with title");
});
}

[Test]
Expand All @@ -85,4 +90,4 @@ public void Click_WaitBeforeClick()
Assert.That(actualWait > WaitBeforeClickInSec.TotalMilliseconds, "\tDidn't wait enough!");
}
}
}
}
Loading

0 comments on commit c18b339

Please sign in to comment.