-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
1,218 additions
and
8 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
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
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
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
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,22 @@ | ||
namespace UiTests; | ||
|
||
/// <summary> | ||
/// Defines how the application under test should be started by the test fixture. | ||
/// </summary> | ||
public enum ApplicationStartMode | ||
{ | ||
/// <summary> | ||
/// Do not start or stop the application as this is done outside. | ||
/// </summary> | ||
None, | ||
|
||
/// <summary> | ||
/// Start the application before each test and close it after each test. | ||
/// </summary> | ||
OncePerTest, | ||
|
||
/// <summary> | ||
/// Start the application once for the whole test fixture and close it when all tests are finished. | ||
/// </summary> | ||
OncePerFixture | ||
} |
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,116 @@ | ||
namespace UiTests; | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using FlaUI.Core.AutomationElements; | ||
using FlaUI.Core.Input; | ||
using FlaUI.Core.WindowsAPI; | ||
using FlaUI.UIA3; | ||
using FluentAssertions; | ||
using UiTests.Extensions; | ||
using UiTests.Framework; | ||
using UiTests.RepoM; | ||
using UiTests.Utils; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
[SetTestName] | ||
public class NotePadTest | ||
{ | ||
private readonly ITestOutputHelper _outputHelper; | ||
|
||
public NotePadTest(ITestOutputHelper outputHelper) | ||
{ | ||
_outputHelper = outputHelper ?? throw new ArgumentNullException(nameof(outputHelper)); | ||
} | ||
|
||
// make sure no vs code instance is running. | ||
|
||
[Fact] | ||
public async Task NotepadLaunchTest() | ||
{ | ||
using var appVsCode = ApplicationFactory.LaunchVsCode(@"C:\Users\Munckhof CJJ\AppData\Roaming\RepoM\RepositoryActionsV2.yaml"); | ||
using var appRepoM = ApplicationFactory.LaunchRepoM(); | ||
|
||
using (var automationRepoM = new UIA3Automation()) | ||
// using (var automationVsCode = new UIA3Automation()) | ||
{ | ||
var automationVsCode = automationRepoM; | ||
|
||
await Task.Delay(20_000); | ||
appRepoM.WaitWhileMainHandleIsMissing(TimeSpan.FromSeconds(5)); | ||
appRepoM.WaitWhileBusy(TimeSpan.FromSeconds(5)); | ||
appVsCode.WaitWhileMainHandleIsMissing(TimeSpan.FromSeconds(20)); | ||
appVsCode.WaitWhileBusy(TimeSpan.FromSeconds(20)); | ||
|
||
VsCodeWindow vsCodeWindow = appVsCode.GetMainWindow(automationVsCode).As<VsCodeWindow>(_outputHelper); | ||
vsCodeWindow.Should().NotBeNull(); | ||
|
||
await RepoMWindow.ShowRepoM(); | ||
await Task.Delay(100); | ||
|
||
await RepoMWindow.KeepRepoMOpenAsync(); | ||
await Task.Delay(100); | ||
|
||
RepoMWindow repoM = await RepoMWindow.GetRepoMWindowAsync(appRepoM, automationRepoM, _outputHelper); | ||
|
||
// undo keep open | ||
await RepoMWindow.KeepRepoMOpenAsync(); | ||
|
||
_ = repoM.Hide(); | ||
|
||
await Task.Delay(100); | ||
|
||
await vsCodeWindow.FocusUsingMouseAsync(); | ||
|
||
vsCodeWindow.NotificationButton.Click(); | ||
await Task.Delay(100); | ||
vsCodeWindow.NotificationButton.Click(); | ||
|
||
await vsCodeWindow.FocusActiveEditorGroupAsync(); | ||
await vsCodeWindow.GoToLineAsync(6); | ||
|
||
Position pos = await vsCodeWindow.GetCurrentCursorPositionAsync(p => p.Line == 6); | ||
_outputHelper.WriteLine($"L{pos.Line} C{pos.Column}"); | ||
pos.Line.Should().Be(6); | ||
|
||
|
||
await vsCodeWindow.SelectLineAsync(); | ||
await Task.Delay(1000); | ||
Keyboard.Type(VirtualKeyShort.DELETE); | ||
await Task.Delay(1000); | ||
Keyboard.Type("end"); | ||
await Task.Delay(1000); | ||
await vsCodeWindow.GoToStartOfLineAsync(); | ||
await Task.Delay(1000); | ||
// await vsCodeWindow.GoToEndOfLineAsync(); | ||
// Keyboard.Type("Hello World"); | ||
|
||
await repoM.ShowAsync(); | ||
await repoM.SearchTextBox.FocusByMouseAsync(); | ||
await repoM.SearchTextBox.TypeTextAsync("RepoM", Delays.DefaultKeyPressDelay); | ||
|
||
await Delays.DelayMediumAsync(); | ||
|
||
|
||
repoM.RepositoryList.Items.Should().NotBeEmpty(); | ||
ListBoxItem firstItem = repoM.RepositoryList.Items[0]; | ||
|
||
await firstItem.MoveMouseAndClick(MouseButton.Right, Delays.DefaultWaitUntilClick); | ||
await Delays.DelayMediumAsync(); | ||
|
||
var ctxMenuItem = repoM.ContextMenu.Items[1].AsMenuItem(); | ||
_outputHelper.WriteLine($"ctxMenuItem item text {ctxMenuItem.Text}"); | ||
await ctxMenuItem.MoveMouseAndClick(MouseButton.Left, Delays.DefaultWaitUntilClick); | ||
|
||
var txt = firstItem.Text; | ||
_outputHelper.WriteLine($"Selected item text {txt}"); | ||
|
||
repoM.Title.Should().Be("RepoM"); | ||
} | ||
|
||
await Task.Delay(1000); | ||
appRepoM.Close(); | ||
appVsCode.Close(); | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
tests/UiTests/Extensions/AutomationElementExtensionsExtensions.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,89 @@ | ||
namespace UiTests.Extensions; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.Threading.Tasks; | ||
using FlaUI.Core.AutomationElements; | ||
using FlaUI.Core.Input; | ||
using UiTests; | ||
using UiTests.Utils; | ||
|
||
public static class AutomationElementExtensionsExtensions | ||
{ | ||
public static T As<T>(this AutomationElement self, params object[] args) where T : AutomationElement | ||
{ | ||
if (self == null) | ||
{ | ||
return default!; | ||
} | ||
|
||
var args2 = new List<object> | ||
{ | ||
self.FrameworkAutomationElement, | ||
}; | ||
args2.AddRange(args); | ||
|
||
return (T)Activator.CreateInstance(typeof(T), args2.ToArray())!; | ||
} | ||
|
||
public static async Task MoveMouseAsync(this AutomationElement element) | ||
{ | ||
Point point = element.GetClickablePoint(); | ||
await Delays.DelaySmallAsync(); | ||
Mouse.MoveTo(point); | ||
await Delays.DelaySmallAsync(); | ||
} | ||
|
||
public static async Task MoveMouseAndClick(this AutomationElement element, MouseButton btn = MouseButton.Left, TimeSpan? delayBeforeClick = null) | ||
{ | ||
await element.MoveMouseAsync(); | ||
|
||
if (delayBeforeClick.HasValue) | ||
{ | ||
await Task.Delay(delayBeforeClick.Value); | ||
} | ||
|
||
Mouse.Click(btn); | ||
await Delays.DelaySmallAsync(); | ||
} | ||
|
||
public static Task FocusByMouseAsync(this AutomationElement element, TimeSpan? delayBeforeClick = null) | ||
{ | ||
return MoveMouseAndClick(element, MouseButton.Left, delayBeforeClick); | ||
} | ||
|
||
public static Task TypeTextAsync(this TextBox textBox, string text) | ||
{ | ||
return textBox.TypeTextAsync(text, TimeSpan.Zero); | ||
} | ||
|
||
public static async Task TypeTextAsync(this TextBox textBox, string text, TimeSpan delayBetweenChars) | ||
{ | ||
if (!textBox.IsEnabled) | ||
{ | ||
throw new Exception("TextBox is not enabled"); | ||
} | ||
|
||
if (text == string.Empty) | ||
{ | ||
await Delays.DelaySmallAsync(); | ||
return; | ||
} | ||
|
||
if (delayBetweenChars > TimeSpan.Zero) | ||
{ | ||
foreach (var character in text) | ||
{ | ||
Keyboard.Type(character); | ||
await Task.Delay(delayBetweenChars); | ||
} | ||
} | ||
else | ||
{ | ||
Keyboard.Type(text); | ||
} | ||
|
||
await Delays.DelaySmallAsync(); | ||
} | ||
} |
Oops, something went wrong.