Skip to content
Open
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 @@ -70,6 +70,14 @@ public interface ITestInfraFunctions
/// <returns>Task</returns>
public Task FillAsync(string selector, string value);

/// <summary>
/// Presses a key on an element
/// </summary>
/// <param name="selector">Selector to find element</param>
/// <param name="key">Key to press (e.g., 'Enter', 'Tab', etc.)</param>
/// <returns>Task</returns>
public Task PressAsync(string selector, string key);

/// <summary>
/// Clicks an element
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,12 @@ public async Task FillAsync(string selector, string value)
await Page.FillAsync(selector, value);
}

public async Task PressAsync(string selector, string value)
{
ValidatePage();
await Page.PressAsync(selector, value);
}

public async Task ClickAsync(string selector)
{
ValidatePage();
Expand Down
8 changes: 8 additions & 0 deletions src/docs/PowerFX/TestEngine.PlaywrightAction.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The following actions are supported
| exists | Returns True or False is locator exist |
| navigate | Navigate to the url |
| wait | Wait for locator items to exist |
| press | Send a keyboard press to the locator (use via PlaywrightActionValue) |

## Examples

Expand All @@ -34,3 +35,10 @@ The following actions are supported
` Preview.PlaywrightAction("https://www.microsoft.com", "navigate")`

` Preview.PlaywrightAction("//button", "wait")`

## Sending keyboard keys (Enter, Tab, etc.)

Use `Preview.PlaywrightActionValue` when you need to send keyboard keys to an element. The third parameter is the key name (for example "Enter"). If empty, the default key is "Enter".

` Preview.PlaywrightActionValue("//input[@id='search']", "press", "Enter")`

Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ private void RunTestScenario(string id)
case "fill":
MockTestInfraFunctions.Setup(x => x.FillAsync("//foo", "xyz")).Returns(Task.CompletedTask);
break;
case "press-in-iframe":
var mockPressFrame = new Mock<IFrame>();
MockPage.SetupGet(x => x.Frames).Returns(new List<IFrame>() { mockPressFrame.Object });
mockPressFrame.Setup(x => x.Locator("//foo", null)).Returns(MockLocator.Object);

MockLocator.Setup(x => x.IsVisibleAsync(null)).Returns(Task.FromResult(true));
MockLocator.Setup(x => x.PressAsync("Enter", It.IsAny<LocatorPressOptions>())).Returns(Task.CompletedTask);
break;
case "press":
MockTestInfraFunctions.Setup(x => x.PressAsync("//foo", "Enter")).Returns(Task.CompletedTask);
break;
case "screenshot":
MockSingleTestInstanceState.Setup(x => x.GetTestResultsDirectory()).Returns(@"c:\");
MockFileSystem.Setup(x => x.Exists(@"c:\")).Returns(true);
Expand All @@ -85,13 +96,18 @@ private void RunTestCheckScenario(string id)
case "fill-in-iframe":
MockLocator.Verify(x => x.PressSequentiallyAsync("xyz", It.Is<LocatorPressSequentiallyOptions>(o => o.Delay >= 100)));
break;
case "press-in-iframe":
MockLocator.Verify(x => x.PressAsync("Enter", It.IsAny<LocatorPressOptions>()));
break;
}
}

[Theory]
[InlineData("//foo", "click-in-iframe", "", null, new string[] { }, true)]
[InlineData("//foo", "fill-in-iframe", "xyz", null, new string[] { }, true)]
[InlineData("//foo", "fill", "xyz", null, new string[] { }, true)]
[InlineData("//foo", "press", "Enter", null, new string[] { }, true)]
[InlineData("//foo", "press-in-iframe", "Enter", null, new string[] { }, true)]
[InlineData("//foo", "screenshot", @"test.jpg", null, new string[] { }, true)]
public void PlaywrightExecute(string locator, string action, string value, string? scenario, string[] messages, bool standardEnd)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ public BooleanValue Execute(StringValue locator, StringValue action, StringValue
case "fill":
_testInfraFunctions.FillAsync(locator.Value, value.Value).Wait();
break;
case "press-in-iframe":
foreach (var frame in page.Frames)
{
if (frame.Locator(locator.Value).IsVisibleAsync().Result)
{
var key = string.IsNullOrEmpty(value.Value) ? "Enter" : value.Value;
frame.Locator(locator.Value).PressAsync(key).Wait();
}
}
break;
case "press":
{
var key = string.IsNullOrEmpty(value.Value) ? "Enter" : value.Value;
_testInfraFunctions.PressAsync(locator.Value, key).Wait();
}
break;
case "screenshot":
var testResultDirectory = _singleTestInstanceState.GetTestResultsDirectory();
if (!_fileSystem.Exists(testResultDirectory))
Expand Down
Loading