From 16245a372e59529626aafd7ea42a64b22211b452 Mon Sep 17 00:00:00 2001 From: Gordana Zafirova Date: Mon, 30 Dec 2024 14:17:10 +0000 Subject: [PATCH] test(BRIDGE-248): Additional Bridge UI e2e automation tests --- .../ui_tests/windows_os/Results/HomeResult.cs | 10 +++- .../windows_os/Tests/LoginLogoutTests.cs | 35 ++++++------ .../ui_tests/windows_os/Windows/HomeWindow.cs | 57 ++++++++++++++++++- 3 files changed, 79 insertions(+), 23 deletions(-) diff --git a/tests/e2e/ui_tests/windows_os/Results/HomeResult.cs b/tests/e2e/ui_tests/windows_os/Results/HomeResult.cs index cb0bc857..a176b32e 100644 --- a/tests/e2e/ui_tests/windows_os/Results/HomeResult.cs +++ b/tests/e2e/ui_tests/windows_os/Results/HomeResult.cs @@ -22,7 +22,8 @@ namespace ProtonMailBridge.UI.Tests.Results private TextBox EnterEmailOrUsernameErrorText => Window.FindFirstDescendant(cf => cf.ByControlType(ControlType.Text).And(cf.ByName("Enter email or username"))).AsTextBox(); private TextBox EnterPasswordErrorText => Window.FindFirstDescendant(cf => cf.ByControlType(ControlType.Text).And(cf.ByName("Enter password"))).AsTextBox(); private TextBox ConnectedStateText => Window.FindFirstDescendant(cf => cf.ByControlType(ControlType.Text).And(cf.ByName("Connected"))).AsTextBox(); - + private CheckBox SplitAddressesToggle => AccountView.FindFirstDescendant(cf => cf.ByControlType(ControlType.CheckBox).And(cf.ByName("Split addresses toggle"))).AsCheckBox(); + public HomeResult CheckConnectedState() { Assert.That(ConnectedStateText.IsAvailable, Is.True); @@ -81,7 +82,6 @@ namespace ProtonMailBridge.UI.Tests.Results { Assert.That(AccountDelinquentErrorText.IsAvailable, Is.True); return this; - } public HomeResult CheckIfNotificationTextIsShown() @@ -89,5 +89,11 @@ namespace ProtonMailBridge.UI.Tests.Results Assert.That(AlreadySignedInText.IsAvailable, Is.True); return this; } + + public HomeResult CheckIfSplitAddressesIsDisabledByDefault() + { + Assert.That(SplitAddressesToggle.IsToggled, Is.False); + return this; + } } } \ No newline at end of file diff --git a/tests/e2e/ui_tests/windows_os/Tests/LoginLogoutTests.cs b/tests/e2e/ui_tests/windows_os/Tests/LoginLogoutTests.cs index 2fc51c63..3a4dcafe 100644 --- a/tests/e2e/ui_tests/windows_os/Tests/LoginLogoutTests.cs +++ b/tests/e2e/ui_tests/windows_os/Tests/LoginLogoutTests.cs @@ -108,18 +108,6 @@ namespace ProtonMailBridge.UI.Tests.Tests _mainWindow.SignOutAccount(); } - /* - [Test] - public void AddSecondAccount() - { - _loginWindow.SignIn(TestUserData.GetPaidUser()); - _homeResult.CheckIfLoggedIn(); - _mainWindow.AddNewAccount(); - _loginWindow.SignInMailbox(TestUserData.GetMailboxUser()); - _homeResult.CheckIfLoggedIn(); - } - */ - [Test] public void AddDisabledAccount() { @@ -136,13 +124,22 @@ namespace ProtonMailBridge.UI.Tests.Tests _loginWindow.ClickCancelToSignIn(); } - //[Test] - //public void SuccessfullLogout() - //{ - // _loginWindow.SignIn(TestUserData.GetPaidUser()); - // _mainWindow.SignOutAccount(); - // _homeResult.CheckIfAccountIsSignedOut(); - //} + [Test] + public void VerifySplitAddressesIsDisabledByDefault() + { + _loginWindow.SignIn(TestUserData.GetPaidUser()); + _homeResult.CheckIfSplitAddressesIsDisabledByDefault(); + Thread.Sleep(1000); + } + + [Test] + public void EnableAndDisableSplitAddressMode() + { + _loginWindow.SignIn(TestUserData.GetPaidUser()); + _mainWindow.EnableSplitAddress(); + Thread.Sleep(5000); + _mainWindow.DisableSplitAddress(); + } [SetUp] public void TestInitialize() diff --git a/tests/e2e/ui_tests/windows_os/Windows/HomeWindow.cs b/tests/e2e/ui_tests/windows_os/Windows/HomeWindow.cs index 461ce60a..259ff0d8 100644 --- a/tests/e2e/ui_tests/windows_os/Windows/HomeWindow.cs +++ b/tests/e2e/ui_tests/windows_os/Windows/HomeWindow.cs @@ -18,6 +18,8 @@ namespace ProtonMailBridge.UI.Tests.Windows private Button ConfirmRemoveAccountButton => RemoveAccountConfirmModal.FindFirstDescendant(cf => cf.ByControlType(ControlType.Button).And(cf.ByName("Remove this account"))).AsButton(); private Button SignOutButton => AccountView.FindFirstDescendant(cf => cf.ByControlType(ControlType.Button).And(cf.ByName("Sign out"))).AsButton(); private Button SignInButton => AccountView.FindFirstDescendant(cf => cf.ByControlType(ControlType.Button).And(cf.ByName("Sign in"))).AsButton(); + private CheckBox SplitAddressesToggle => AccountView.FindFirstDescendant(cf => cf.ByControlType(ControlType.CheckBox).And(cf.ByName("Split addresses toggle"))).AsCheckBox(); + private Button EnableSplitAddressButton => Window.FindFirstDescendant(cf => cf.ByControlType(ControlType.Button).And(cf.ByName("Enable split mode"))).AsButton(); public HomeWindow RemoveAccount() { @@ -33,12 +35,12 @@ namespace ProtonMailBridge.UI.Tests.Windows return this; } - public HomeWindow AddNewAccount () + public HomeWindow AddNewAccount() { AddNewAccountButton.Click(); return this; } - + public HomeWindow SignOutAccount() { SignOutButton.Click(); @@ -49,6 +51,57 @@ namespace ProtonMailBridge.UI.Tests.Windows SignInButton.Click(); return this; } + public HomeWindow EnableSplitAddress() + { + SplitAddressesToggle.Click(); + EnableSplitAddressButton.Click(); + Thread.Sleep(5000); + bool syncRestarted = WaitForCondition(() => + { + return IsStatusLabelSyncing(Window); + }, TimeSpan.FromSeconds(30)); + Assert.That(syncRestarted, Is.True, "Sync did not restart after Split Address mode was enabled."); + Assert.That(SplitAddressesToggle.IsToggled, Is.True); + return this; + } + + public HomeWindow DisableSplitAddress() + { + SplitAddressesToggle.Click(); + Thread.Sleep(5000); + bool syncRestarted = WaitForCondition(() => + { + return IsStatusLabelSyncing(Window); + }, TimeSpan.FromSeconds(30)); + + Assert.That(syncRestarted, Is.True, "Sync did not restart after Split Address mode was disabled."); + Assert.That(SplitAddressesToggle.IsToggled, Is.False); + return this; + } + + private bool IsStatusLabelSyncing(AutomationElement window) + { + var syncStatusElement = window.FindAllDescendants(cf => cf.ByControlType(ControlType.Text)).FirstOrDefault(el => + { + string name = el.Name; + return !string.IsNullOrEmpty(name) && + name.StartsWith("Synchronizing (") && + name.EndsWith("%)"); + }); + return syncStatusElement != null && syncStatusElement.Name.Contains("Synchronizing"); + } + + private bool WaitForCondition(Func condition, TimeSpan timeout, int pollingIntervalMs = 500) + { + var endTime = DateTime.Now + timeout; + while (DateTime.Now < endTime) + { + if (condition()) + return true; + Thread.Sleep(pollingIntervalMs); + } + return false; + } } }