Replace code which starts the WinAppDriver server (#1957)

This commit is contained in:
Matt Cooley 2023-05-26 07:52:05 -07:00 коммит произвёл GitHub
Родитель 264174669d
Коммит 4a1aa8eec6
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
27 изменённых файлов: 202 добавлений и 574 удалений

Просмотреть файл

@ -37,211 +37,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
---
Appium DotNet Driver
Copyright 2014-2015 Appium Contributors
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Просмотреть файл

@ -16,7 +16,7 @@ namespace CalculatorUITestFramework
internal static WindowsElement Header => session.TryFindElementByAccessibilityId("Header");
private static WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
private static WindowsDriver<WindowsElement> session => CalculatorDriver.Instance.CalculatorSession;
private static WindowsElement AppName => session.TryFindElementByAccessibilityId("AppName");
/// <summary>
@ -51,8 +51,8 @@ namespace CalculatorUITestFramework
public static void ResizeWindowToDisplayMemoryHistoryDockPanel()
{
// Put the calculator in the upper left region of the screen
WinAppDriver.Instance.CalculatorSession.Manage().Window.Position = new Point(8, 8);
GrowWindowToShowDock(WinAppDriver.Instance.CalculatorSession.Manage().Window.Size.Width);
CalculatorDriver.Instance.CalculatorSession.Manage().Window.Position = new Point(8, 8);
GrowWindowToShowDock(CalculatorDriver.Instance.CalculatorSession.Manage().Window.Size.Width);
}
/// <summary>
@ -67,8 +67,8 @@ namespace CalculatorUITestFramework
if (!session.PageSource.Contains("DockPanel"))
{
var height = WinAppDriver.Instance.CalculatorSession.Manage().Window.Size.Height;
WinAppDriver.Instance.CalculatorSession.Manage().Window.Size = new Size(width, height);
var height = CalculatorDriver.Instance.CalculatorSession.Manage().Window.Size.Height;
CalculatorDriver.Instance.CalculatorSession.Manage().Window.Size = new Size(width, height);
//give window time to render new size
System.Threading.Thread.Sleep(10);
GrowWindowToShowDock(width + 100);

Просмотреть файл

@ -10,45 +10,35 @@ using System;
namespace CalculatorUITestFramework
{
public sealed class WinAppDriver
public sealed class CalculatorDriver
{
private WindowsDriverLocalService windowsDriverService = null;
public MemoryPanel MemoryPanel = new MemoryPanel();
private const string defaultAppId = "Microsoft.WindowsCalculator.Dev_8wekyb3d8bbwe!App";
private static WinAppDriver instance = null;
public static WinAppDriver Instance
private static CalculatorDriver instance = null;
public static CalculatorDriver Instance
{
get
{
if (instance == null)
{
instance = new WinAppDriver();
instance = new CalculatorDriver();
}
return instance;
}
}
private WinAppDriverLocalServer server;
public WindowsDriver<WindowsElement> CalculatorSession { get; private set; }
private WinAppDriver()
private CalculatorDriver()
{
}
public void SetupCalculatorSession(TestContext context)
{
this.windowsDriverService = new WindowsDriverServiceBuilder().Build();
this.windowsDriverService.OutputDataReceived += (sender, e) =>
{
var outputData = e.Data?.Replace("\0", string.Empty);
if (!string.IsNullOrEmpty(outputData))
{
Console.WriteLine(outputData);
}
};
this.windowsDriverService.Start();
this.server = new WinAppDriverLocalServer();
// Launch Calculator application if it is not yet launched
if (this.CalculatorSession == null)
@ -67,7 +57,7 @@ namespace CalculatorUITestFramework
}
options.AddAdditionalCapability("deviceName", "WindowsPC");
this.CalculatorSession = new WindowsDriver<WindowsElement>(this.windowsDriverService.ServiceUrl, options);
this.CalculatorSession = new WindowsDriver<WindowsElement>(this.server.ServiceUrl, options);
this.CalculatorSession.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
Assert.IsNotNull(this.CalculatorSession);
}
@ -82,12 +72,11 @@ namespace CalculatorUITestFramework
this.CalculatorSession = null;
}
if (this.windowsDriverService != null)
if (this.server != null)
{
this.windowsDriverService.Dispose();
this.windowsDriverService = null;
this.server.Dispose();
this.server = null;
}
}
}
}

Просмотреть файл

@ -10,7 +10,7 @@ namespace CalculatorUITestFramework
{
public class CalculatorResults
{
private WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
private WindowsDriver<WindowsElement> session => CalculatorDriver.Instance.CalculatorSession;
private WindowsElement CalculatorAlwaysOnTopResults => this.session.TryFindElementByAccessibilityId("CalculatorAlwaysOnTopResults");
private WindowsElement CalculatorResult => this.session.TryFindElementByAccessibilityId("CalculatorResults");
private WindowsElement CalculatorExpression => this.session.TryFindElementByAccessibilityId("CalculatorExpression");
@ -57,7 +57,7 @@ namespace CalculatorUITestFramework
/// <returns>The string shown in the UI.</returns>
public void IsResultsExpressionClear()
{
string source = WinAppDriver.Instance.CalculatorSession.PageSource;
string source = CalculatorDriver.Instance.CalculatorSession.PageSource;
if (source.Contains("CalculatorExpression"))
{
throw new Exception("The Calculator Expression is not clear");

Просмотреть файл

@ -17,7 +17,7 @@ namespace CalculatorUITestFramework
public WindowsElement ListViewItem => this.session.FindElementByClassName("ListViewItem");
public WindowsElement ClearHistoryButton => this.session.TryFindElementByAccessibilityId("ClearHistory");
private WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
private WindowsDriver<WindowsElement> session => CalculatorDriver.Instance.CalculatorSession;
private WindowsElement HistoryLabel => this.session.TryFindElementByAccessibilityId("HistoryLabel");
private WindowsElement HistoryListView => this.session.TryFindElementByAccessibilityId("HistoryListView");
private WindowsElement HistoryFlyout => this.session.TryFindElementByAccessibilityId("HistoryFlyout");
@ -62,8 +62,8 @@ namespace CalculatorUITestFramework
public void ResizeWindowToDisplayHistoryLabel()
{
// Put the calculator in the upper left region of the screen
WinAppDriver.Instance.CalculatorSession.Manage().Window.Position = new Point(8, 8);
GrowWindowToShowHistoryLabel(WinAppDriver.Instance.CalculatorSession.Manage().Window.Size.Width);
CalculatorDriver.Instance.CalculatorSession.Manage().Window.Position = new Point(8, 8);
GrowWindowToShowHistoryLabel(CalculatorDriver.Instance.CalculatorSession.Manage().Window.Size.Width);
}
///// <summary>
@ -72,8 +72,8 @@ namespace CalculatorUITestFramework
public void ResizeWindowToDisplayHistoryButton()
{
// Put the calculator in the upper left region of the screen
WinAppDriver.Instance.CalculatorSession.Manage().Window.Position = new Point(8, 8);
ShrinkWindowToShowHistoryButton(WinAppDriver.Instance.CalculatorSession.Manage().Window.Size.Width);
CalculatorDriver.Instance.CalculatorSession.Manage().Window.Position = new Point(8, 8);
ShrinkWindowToShowHistoryButton(CalculatorDriver.Instance.CalculatorSession.Manage().Window.Size.Width);
}
/// <summary>
@ -84,7 +84,7 @@ namespace CalculatorUITestFramework
this.ResizeWindowToDisplayHistoryButton();
CalculatorApp.EnsureCalculatorHasFocus();
CalculatorApp.Window.SendKeys(Keys.Control + "h" + Keys.Control);
Actions moveToHistoryFlyout = new Actions(WinAppDriver.Instance.CalculatorSession);
Actions moveToHistoryFlyout = new Actions(CalculatorDriver.Instance.CalculatorSession);
moveToHistoryFlyout.MoveToElement(HistoryFlyout);
moveToHistoryFlyout.Perform();
}
@ -111,8 +111,8 @@ namespace CalculatorUITestFramework
if (!this.session.PageSource.Contains("HistoryLabel"))
{
var height = WinAppDriver.Instance.CalculatorSession.Manage().Window.Size.Height;
WinAppDriver.Instance.CalculatorSession.Manage().Window.Size = new Size(width, height);
var height = CalculatorDriver.Instance.CalculatorSession.Manage().Window.Size.Height;
CalculatorDriver.Instance.CalculatorSession.Manage().Window.Size = new Size(width, height);
//give window time to render new size
System.Threading.Thread.Sleep(10);
GrowWindowToShowHistoryLabel(width + 100);
@ -131,8 +131,8 @@ namespace CalculatorUITestFramework
if (!this.session.PageSource.Contains("HistoryButton"))
{
var height = WinAppDriver.Instance.CalculatorSession.Manage().Window.Size.Height;
WinAppDriver.Instance.CalculatorSession.Manage().Window.Size = new Size(width, height);
var height = CalculatorDriver.Instance.CalculatorSession.Manage().Window.Size.Height;
CalculatorDriver.Instance.CalculatorSession.Manage().Window.Size = new Size(width, height);
//give window time to render new size
System.Threading.Thread.Sleep(10);
ShrinkWindowToShowHistoryButton(width - 100);

Просмотреть файл

@ -24,7 +24,7 @@ namespace CalculatorUITestFramework
public WindowsElement PanelClearMemoryButton => this.session.TryFindElementByAccessibilityId("ClearMemory");
public WindowsElement ListViewItem => this.session.FindElementByClassName("ListViewItem");
private WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
private WindowsDriver<WindowsElement> session => CalculatorDriver.Instance.CalculatorSession;
private WindowsElement MemoryPane => this.session.TryFindElementByAccessibilityId("MemoryPanel");
private WindowsElement MemoryLabel => this.session.TryFindElementByAccessibilityId("MemoryLabel");
private WindowsElement MemoryListView => this.session.TryFindElementByAccessibilityId("MemoryListView");
@ -87,8 +87,8 @@ namespace CalculatorUITestFramework
public void ResizeWindowToDisplayMemoryLabel()
{
// Put the calculator in the upper left region of the screen
WinAppDriver.Instance.CalculatorSession.Manage().Window.Position = new Point(8, 8);
GrowWindowToShowMemoryLabel(WinAppDriver.Instance.CalculatorSession.Manage().Window.Size.Width);
CalculatorDriver.Instance.CalculatorSession.Manage().Window.Position = new Point(8, 8);
GrowWindowToShowMemoryLabel(CalculatorDriver.Instance.CalculatorSession.Manage().Window.Size.Width);
}
/// <summary>
@ -97,8 +97,8 @@ namespace CalculatorUITestFramework
public void ResizeWindowToDisplayMemoryButton()
{
// Put the calculator in the upper left region of the screen
WinAppDriver.Instance.CalculatorSession.Manage().Window.Position = new Point(8, 8);
ShrinkWindowToShowMemoryButton(WinAppDriver.Instance.CalculatorSession.Manage().Window.Size.Width);
CalculatorDriver.Instance.CalculatorSession.Manage().Window.Position = new Point(8, 8);
ShrinkWindowToShowMemoryButton(CalculatorDriver.Instance.CalculatorSession.Manage().Window.Size.Width);
}
/// <summary>
@ -108,11 +108,11 @@ namespace CalculatorUITestFramework
{
this.ResizeWindowToDisplayMemoryButton();
CalculatorApp.EnsureCalculatorHasFocus();
Actions moveToMemoryButton = new Actions(WinAppDriver.Instance.CalculatorSession);
Actions moveToMemoryButton = new Actions(CalculatorDriver.Instance.CalculatorSession);
moveToMemoryButton.MoveToElement(MemoryFlyoutButton);
moveToMemoryButton.Perform();
CalculatorApp.Window.SendKeys(Keys.Alt + "m" + Keys.Alt);
Actions moveToMemoryFlyout = new Actions(WinAppDriver.Instance.CalculatorSession);
Actions moveToMemoryFlyout = new Actions(CalculatorDriver.Instance.CalculatorSession);
moveToMemoryFlyout.MoveToElement(MemoryFlyout);
moveToMemoryFlyout.Perform();
}
@ -139,8 +139,8 @@ namespace CalculatorUITestFramework
if (!this.session.PageSource.Contains("MemoryLabel"))
{
var height = WinAppDriver.Instance.CalculatorSession.Manage().Window.Size.Height;
WinAppDriver.Instance.CalculatorSession.Manage().Window.Size = new Size(width, height);
var height = CalculatorDriver.Instance.CalculatorSession.Manage().Window.Size.Height;
CalculatorDriver.Instance.CalculatorSession.Manage().Window.Size = new Size(width, height);
//give window time to render new size
System.Threading.Thread.Sleep(10);
GrowWindowToShowMemoryLabel(width + 100);
@ -160,8 +160,8 @@ namespace CalculatorUITestFramework
//Page source contains differnt memory button types, using hotkey info is for this specific memory button
if (!this.session.PageSource.Contains("Alt, M"))
{
var height = WinAppDriver.Instance.CalculatorSession.Manage().Window.Size.Height;
WinAppDriver.Instance.CalculatorSession.Manage().Window.Size = new Size(width, height);
var height = CalculatorDriver.Instance.CalculatorSession.Manage().Window.Size.Height;
CalculatorDriver.Instance.CalculatorSession.Manage().Window.Size = new Size(width, height);
//give window time to render new size
System.Threading.Thread.Sleep(10);
ShrinkWindowToShowMemoryButton(width - 100);

Просмотреть файл

@ -33,7 +33,7 @@ namespace CalculatorUITestFramework
public WindowsElement NavigationMenuButton => this.session.TryFindElementByAccessibilityId("TogglePaneButton");
public WindowsElement NavigationMenuPane => this.session.TryFindElementByClassName("SplitViewPane");
private WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
private WindowsDriver<WindowsElement> session => CalculatorDriver.Instance.CalculatorSession;
/// <summary>
/// Changes the mode using the navigation menu in the UI

Просмотреть файл

@ -23,7 +23,7 @@ namespace CalculatorUITestFramework
public WindowsElement DecimalButton => this.session.TryFindElementByAccessibilityId("decimalSeparatorButton");
public WindowsElement NegateButton => this.session.TryFindElementByAccessibilityId("negateButton");
private WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
private WindowsDriver<WindowsElement> session => CalculatorDriver.Instance.CalculatorSession;
/// <summary>
/// Translates a number into the Calculator button clicks.

Просмотреть файл

@ -10,7 +10,7 @@ namespace CalculatorUITestFramework
/// </summary>
public class ProgrammerCalculatorPage
{
private WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
private WindowsDriver<WindowsElement> session => CalculatorDriver.Instance.CalculatorSession;
public ScientificOperatorsPanel ScientificOperators = new ScientificOperatorsPanel();
public StandardOperatorsPanel StandardOperators = new StandardOperatorsPanel();
public ProgrammerOperatorsPanel ProgrammerOperators = new ProgrammerOperatorsPanel();

Просмотреть файл

@ -11,7 +11,7 @@ namespace CalculatorUITestFramework
/// </summary>
public class ProgrammerOperatorsPanel
{
private WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
private WindowsDriver<WindowsElement> session => CalculatorDriver.Instance.CalculatorSession;
public NumberPad NumberPad = new NumberPad();
public WindowsElement HexButton => this.session.TryFindElementByAccessibilityId("hexButton");

Просмотреть файл

@ -10,7 +10,7 @@ namespace CalculatorUITestFramework
/// </summary>
public class ScientificCalculatorPage
{
private WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
private WindowsDriver<WindowsElement> session => CalculatorDriver.Instance.CalculatorSession;
public ScientificOperatorsPanel ScientificOperators = new ScientificOperatorsPanel();
public StandardOperatorsPanel StandardOperators = new StandardOperatorsPanel();
public MemoryPanel MemoryPanel = new MemoryPanel();

Просмотреть файл

@ -26,7 +26,7 @@ namespace CalculatorUITestFramework
/// </summary>
public class ScientificOperatorsPanel
{
private WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
private WindowsDriver<WindowsElement> session => CalculatorDriver.Instance.CalculatorSession;
public WindowsElement XPower3Button => this.session.TryFindElementByAccessibilityId("xpower3Button");
public WindowsElement XPowerYButton => this.session.TryFindElementByAccessibilityId("powerButton");
public WindowsElement PowerOf10Button => this.session.TryFindElementByAccessibilityId("powerOf10Button");

Просмотреть файл

@ -20,9 +20,9 @@ namespace CalculatorUITestFramework
public NavigationMenu NavigationMenu = new NavigationMenu();
public WindowsElement EnterAlwaysOnTopButton => this.session.TryFindElementByAccessibilityId("NormalAlwaysOnTopButton");
public WindowsElement ExitAlwaysOnTopButton => this.session.TryFindElementByAccessibilityId("ExitAlwaysOnTopButton");
public AppiumWebElement ToolTip => WinAppDriver.Instance.CalculatorSession.FindElementByClassName("ToolTip").FindElementByClassName("TextBlock");
public AppiumWebElement ToolTip => CalculatorDriver.Instance.CalculatorSession.FindElementByClassName("ToolTip").FindElementByClassName("TextBlock");
private WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
private WindowsDriver<WindowsElement> session => CalculatorDriver.Instance.CalculatorSession;
///// <summary>
///// Navigates from AoT(Keep on top) to Standard
@ -59,7 +59,7 @@ namespace CalculatorUITestFramework
{
this.EnterAlwaysOnTopButton.Click();
this.ExitAlwaysOnTopButton.WaitForDisplayed();
source = WinAppDriver.Instance.CalculatorSession.PageSource;
source = CalculatorDriver.Instance.CalculatorSession.PageSource;
if (source.Contains("Header"))
{
throw new NotFoundException("Failed to enter 'Keep on top' mode; In AoT mode, Calculator does not have header");
@ -77,13 +77,13 @@ namespace CalculatorUITestFramework
{
if (source.Contains("Keep on top"))
{
Actions moveToAoTButton = new Actions(WinAppDriver.Instance.CalculatorSession);
Actions moveToAoTButton = new Actions(CalculatorDriver.Instance.CalculatorSession);
moveToAoTButton.MoveToElement(EnterAlwaysOnTopButton);
moveToAoTButton.Perform();
}
else
{
Actions moveToBackToFullViewVButton = new Actions(WinAppDriver.Instance.CalculatorSession);
Actions moveToBackToFullViewVButton = new Actions(CalculatorDriver.Instance.CalculatorSession);
moveToBackToFullViewVButton.MoveToElement(ExitAlwaysOnTopButton);
moveToBackToFullViewVButton.Perform();
}
@ -127,8 +127,8 @@ namespace CalculatorUITestFramework
public void ResizeAoTWindowToDisplayInvertButton()
{
// Put the calculator in the upper left region of the screen
WinAppDriver.Instance.CalculatorSession.Manage().Window.Position = new Point(8, 8);
GrowWindowToShowInvertButton(WinAppDriver.Instance.CalculatorSession.Manage().Window.Size.Height);
CalculatorDriver.Instance.CalculatorSession.Manage().Window.Position = new Point(8, 8);
GrowWindowToShowInvertButton(CalculatorDriver.Instance.CalculatorSession.Manage().Window.Size.Height);
}
/// <summary>
@ -143,8 +143,8 @@ namespace CalculatorUITestFramework
if (!this.session.PageSource.Contains("invertButton"))
{
var width = WinAppDriver.Instance.CalculatorSession.Manage().Window.Size.Width;
WinAppDriver.Instance.CalculatorSession.Manage().Window.Size = new Size(width, height);
var width = CalculatorDriver.Instance.CalculatorSession.Manage().Window.Size.Width;
CalculatorDriver.Instance.CalculatorSession.Manage().Window.Size = new Size(width, height);
//give window time to render new size
System.Threading.Thread.Sleep(10);
GrowWindowToShowInvertButton(height + 100);

Просмотреть файл

@ -17,7 +17,7 @@ namespace CalculatorUITestFramework
public StandardAoTCalculatorPage StandardAoTCalculatorPage = new StandardAoTCalculatorPage();
public CalculatorResults CalculatorResults = new CalculatorResults();
private WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
private WindowsDriver<WindowsElement> session => CalculatorDriver.Instance.CalculatorSession;
/// <summary>
/// Navigates the calculator to Standard mode and ensures that it is in standard mode
@ -57,7 +57,7 @@ namespace CalculatorUITestFramework
///// </summary>
public void EnsureCalculatorIsInStandardMode()
{
string source = WinAppDriver.Instance.CalculatorSession.PageSource;
string source = CalculatorDriver.Instance.CalculatorSession.PageSource;
if (source.Contains("Header"))
{
string header = CalculatorApp.Header.Text;

Просмотреть файл

@ -10,7 +10,7 @@ namespace CalculatorUITestFramework
/// </summary>
public class StandardOperatorsPanel
{
private WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
private WindowsDriver<WindowsElement> session => CalculatorDriver.Instance.CalculatorSession;
public NumberPad NumberPad = new NumberPad();
public WindowsElement PercentButton => this.session.TryFindElementByAccessibilityId("percentButton");

Просмотреть файл

@ -6,7 +6,7 @@ namespace CalculatorUITestFramework
{
public class UnitConverterOperatorsPanel
{
private WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
private WindowsDriver<WindowsElement> session => CalculatorDriver.Instance.CalculatorSession;
public NumberPad NumberPad = new NumberPad();
public WindowsElement ClearButton => this.session.TryFindElementByAccessibilityId("ClearEntryButtonPos0");
public WindowsElement BackSpaceButton => this.session.TryFindElementByAccessibilityId("BackSpaceButtonSmall");

Просмотреть файл

@ -10,7 +10,7 @@ namespace CalculatorUITestFramework
public NavigationMenu NavigationMenu = new NavigationMenu();
public UnitConverterResults UnitConverterResults = new UnitConverterResults();
private WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
private WindowsDriver<WindowsElement> session => CalculatorDriver.Instance.CalculatorSession;
/// <summary>
/// Clear the Calculator display
@ -46,7 +46,7 @@ namespace CalculatorUITestFramework
///// </summary>
public void EnsureCalculatorIsCurrencyMode()
{
string source = WinAppDriver.Instance.CalculatorSession.PageSource;
string source = CalculatorDriver.Instance.CalculatorSession.PageSource;
if (source.Contains("Header"))
{
string header = CalculatorApp.Header.Text;

Просмотреть файл

@ -10,7 +10,7 @@ namespace CalculatorUITestFramework
{
public class UnitConverterResults
{
private WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
private WindowsDriver<WindowsElement> session => CalculatorDriver.Instance.CalculatorSession;
private WindowsElement CalculationResult1 => this.session.TryFindElementByAccessibilityId("Value1");
private WindowsElement CalculationResult2 => this.session.TryFindElementByAccessibilityId("Value2");

Просмотреть файл

@ -0,0 +1,111 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
namespace CalculatorUITestFramework
{
public class WinAppDriverLocalServer : IDisposable
{
private const int WinAppDriverDefaultPort = 4723;
private static readonly IPAddress WinAppDriverDefaultIp = IPAddress.Loopback;
private readonly Process winAppDriverProcess;
private bool processExited = false;
public Uri ServiceUrl => new UriBuilder()
{
Scheme = "http",
Host = WinAppDriverDefaultIp.ToString(),
Port = WinAppDriverDefaultPort,
}.Uri;
public WinAppDriverLocalServer()
{
var driverRelativePath = @"Windows Application Driver\winappdriver.exe";
string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), driverRelativePath);
if (!File.Exists(path))
{
path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), driverRelativePath);
}
if (!File.Exists(path))
{
throw new Exception("Could not find winappdriver.exe in program files. Make sure WinAppDriver is installed: https://aka.ms/winappdriver");
}
this.winAppDriverProcess = new Process();
this.winAppDriverProcess.StartInfo.CreateNoWindow = true;
this.winAppDriverProcess.StartInfo.FileName = path;
this.winAppDriverProcess.StartInfo.UseShellExecute = false;
this.winAppDriverProcess.StartInfo.RedirectStandardOutput = true;
this.winAppDriverProcess.StartInfo.RedirectStandardError = true;
this.winAppDriverProcess.OutputDataReceived += this.OnProcessOutputDataReceived;
this.winAppDriverProcess.ErrorDataReceived += this.OnProcessErrorDataReceived;
if (!this.winAppDriverProcess.Start())
{
throw new Exception("WinAppDriver process failed to start.");
}
this.winAppDriverProcess.BeginOutputReadLine();
this.winAppDriverProcess.BeginErrorReadLine();
var pingUri = new Uri(this.ServiceUrl, "/status");
var status = new HttpClient().GetAsync(pingUri);
var timeout = TimeSpan.FromSeconds(10);
if (!status.Wait(timeout))
{
throw new Exception($"Request to WinAppDriver at {pingUri} timed out after {timeout.TotalSeconds} seconds.");
}
status.Result.EnsureSuccessStatusCode();
}
private void OnProcessOutputDataReceived(object sender, DataReceivedEventArgs e)
{
var data = e.Data?.Replace("\0", string.Empty);
if (!string.IsNullOrEmpty(data))
{
Console.WriteLine(this.PrependWinAppDriverToEachLine(data));
}
}
private void OnProcessErrorDataReceived(object sender, DataReceivedEventArgs e)
{
var data = e.Data?.Replace("\0", string.Empty);
if (!string.IsNullOrEmpty(data))
{
Console.Error.WriteLine(this.PrependWinAppDriverToEachLine(data));
}
}
private string PrependWinAppDriverToEachLine(string data)
{
return string.Join("\r\n", data
.ReplaceLineEndings("\n")
.Split("\n")
.Select(line => "WinAppDriver> " + line));
}
~WinAppDriverLocalServer()
{
if (!this.processExited)
{
this.winAppDriverProcess.Kill();
this.winAppDriverProcess.WaitForExit();
}
}
public void Dispose()
{
this.winAppDriverProcess.Kill();
this.winAppDriverProcess.WaitForExit();
this.processExited = true;
GC.SuppressFinalize(this);
}
}
}

Просмотреть файл

@ -1,169 +0,0 @@
//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//See the NOTICE file distributed with this work for additional
//information regarding copyright ownership.
//You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.
//Portions Copyright(c) Microsoft Corporation
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
namespace CalculatorUITestFramework
{
public class WindowsDriverLocalService : IDisposable
{
private readonly FileInfo FileName;
private readonly string Arguments;
private readonly IPAddress IP;
private readonly int Port;
private TimeSpan InitializationTimeout;
private Process Service;
public event DataReceivedEventHandler OutputDataReceived;
internal WindowsDriverLocalService(
FileInfo fileName,
string arguments,
IPAddress ip,
int port,
TimeSpan initializationTimeout)
{
this.FileName = fileName;
this.Arguments = arguments;
this.IP = ip;
this.Port = port;
this.InitializationTimeout = initializationTimeout;
}
[MethodImpl(MethodImplOptions.Synchronized)]
public void Start()
{
if (this.IsRunning)
{
return;
}
this.Service = new Process();
this.Service.StartInfo.FileName = FileName.FullName;
this.Service.StartInfo.Arguments = Arguments;
this.Service.StartInfo.UseShellExecute = false;
this.Service.StartInfo.CreateNoWindow = true;
this.Service.StartInfo.RedirectStandardOutput = true;
this.Service.OutputDataReceived += (sender, e) => OutputDataReceived?.Invoke(this, e);
bool isLaunched = false;
string msgTxt =
$"The local WinAppDriver server has not been started: {this.FileName.FullName} Arguments: {this.Arguments}. " +
"\n";
try
{
Service.Start();
Service.BeginOutputReadLine();
}
catch (Exception e)
{
DestroyProcess();
throw new Exception(msgTxt, e);
}
isLaunched = Ping();
if (!isLaunched)
{
DestroyProcess();
throw new Exception(
msgTxt +
$"Time {InitializationTimeout.TotalMilliseconds} ms for the service starting has been expired!");
}
}
public bool IsRunning
{
get
{
if (this.Service == null)
{
return false;
}
try
{
var pid = this.Service.Id;
}
catch (Exception)
{
return false;
}
return Ping();
}
}
public void Dispose()
{
DestroyProcess();
GC.SuppressFinalize(this);
}
public Uri ServiceUrl => new Uri($"http://{this.IP}:{Convert.ToString(this.Port)}");
private void DestroyProcess()
{
if (this.Service == null)
{
return;
}
try
{
this.Service.Kill();
}
catch (Exception)
{
}
finally
{
this.Service.Close();
}
}
private bool Ping()
{
Uri status;
Uri service = this.ServiceUrl;
using (HttpClient httpClient = new HttpClient())
{
httpClient.Timeout = this.InitializationTimeout;
if (service.IsLoopback)
{
status = new Uri("http://localhost:" + Convert.ToString(this.Port) + "/status");
}
else
{
status = new Uri(service + "/status");
}
var httpResponse = Task.Run(() => httpClient.GetAsync(status)).ConfigureAwait(false).GetAwaiter().GetResult();
return httpResponse.IsSuccessStatusCode;
}
}
}
}

Просмотреть файл

@ -1,95 +0,0 @@
//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//See the NOTICE file distributed with this work for additional
//information regarding copyright ownership.
//You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.
//Portions Copyright(c) Microsoft Corporation
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
namespace CalculatorUITestFramework
{
public class WindowsDriverServiceBuilder
{
private string IpAddress = "127.0.0.1";
private int Port = 4723;
private TimeSpan StartUpTimeout = new TimeSpan(0, 2, 0);
private FileInfo FileInfo;
public WindowsDriverLocalService Build()
{
if (this.FileInfo == null)
{
this.FileInfo = new FileInfo(@"c:\Program Files (x86)\Windows Application Driver\winappdriver.exe");
}
return new WindowsDriverLocalService(this.FileInfo, string.Empty, IPAddress.Parse(this.IpAddress), this.Port, this.StartUpTimeout);
}
public WindowsDriverServiceBuilder WithFileInfo(FileInfo fileInfo)
{
this.FileInfo = fileInfo ?? throw new ArgumentNullException("FileInfo should not be NULL");
return this;
}
public WindowsDriverServiceBuilder WithStartUpTimeOut(TimeSpan startUpTimeout)
{
this.StartUpTimeout = startUpTimeout;
return this;
}
public WindowsDriverServiceBuilder WithIPAddress(string ipAddress)
{
this.IpAddress = ipAddress;
return this;
}
public WindowsDriverServiceBuilder UsingPort(int port)
{
if (port < 0)
{
throw new ArgumentException("The port parameter should not be negative");
}
if (port == 0)
{
return UsingAnyFreePort();
}
this.Port = port;
return this;
}
public WindowsDriverServiceBuilder UsingAnyFreePort()
{
Socket sock = null;
try
{
sock = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
sock.Bind(new IPEndPoint(IPAddress.Any, 0));
this.Port = ((IPEndPoint)sock.LocalEndPoint).Port;
return this;
}
finally
{
if (sock != null)
{
sock.Dispose();
}
}
}
}
}

Просмотреть файл

@ -21,7 +21,7 @@ namespace CalculatorUITests
public static void ClassInitialize(TestContext context)
{
// Create session to launch a Calculator window
WinAppDriver.Instance.SetupCalculatorSession(context);
CalculatorDriver.Instance.SetupCalculatorSession(context);
}
/// <summary>
@ -31,7 +31,7 @@ namespace CalculatorUITests
public static void ClassCleanup()
{
// Tear down Calculator session.
WinAppDriver.Instance.TearDownCalculatorSession();
CalculatorDriver.Instance.TearDownCalculatorSession();
}
/// <summary>

Просмотреть файл

@ -25,7 +25,7 @@ namespace CalculatorUITests
public static void ClassInitialize(TestContext context)
{
// Create session to launch a Calculator window
WinAppDriver.Instance.SetupCalculatorSession(context);
CalculatorDriver.Instance.SetupCalculatorSession(context);
// Ensure that calculator is in standard mode
page.NavigateToStandardCalculator();
@ -41,7 +41,7 @@ namespace CalculatorUITests
public static void ClassCleanup()
{
// Tear down Calculator session.
WinAppDriver.Instance.TearDownCalculatorSession();
CalculatorDriver.Instance.TearDownCalculatorSession();
}
/// <summary>
@ -98,21 +98,21 @@ namespace CalculatorUITests
Assert.AreEqual("-1", page.CalculatorResults.GetCalculatorResultText());
Actions clickHistoryItemsw1 = new Actions(WinAppDriver.Instance.CalculatorSession);
Actions clickHistoryItemsw1 = new Actions(CalculatorDriver.Instance.CalculatorSession);
clickHistoryItemsw1.Click(historyItems[1].Item);
clickHistoryItemsw1.Perform();
Assert.AreEqual("-5.6", page.CalculatorResults.GetCalculatorResultText());
Assert.AreEqual("-3 + -2.6=", page.CalculatorResults.GetCalculatorExpressionText());
Actions clickHistoryItemsw0 = new Actions(WinAppDriver.Instance.CalculatorSession);
Actions clickHistoryItemsw0 = new Actions(CalculatorDriver.Instance.CalculatorSession);
clickHistoryItemsw0.Click(historyItems[0].Item);
clickHistoryItemsw0.Perform();
Assert.AreEqual("-1", page.CalculatorResults.GetCalculatorResultText());
page.HistoryPanel.ClearHistory();
Assert.IsNotNull(WinAppDriver.Instance.CalculatorSession.FindElementByAccessibilityId("HistoryEmpty"));
Assert.IsNotNull(CalculatorDriver.Instance.CalculatorSession.FindElementByAccessibilityId("HistoryEmpty"));
}
[TestMethod]
@ -164,10 +164,10 @@ namespace CalculatorUITests
page.HistoryPanel.ClearHistoryButton.Click();
page.HistoryPanel.OpenHistoryFlyout();
Assert.IsNotNull(WinAppDriver.Instance.CalculatorSession.FindElementByAccessibilityId("HistoryEmpty"));
Assert.IsNotNull(CalculatorDriver.Instance.CalculatorSession.FindElementByAccessibilityId("HistoryEmpty"));
page.HistoryPanel.OpenHistoryPanel();
Assert.IsNotNull(WinAppDriver.Instance.CalculatorSession.FindElementByAccessibilityId("HistoryEmpty"));
Assert.IsNotNull(CalculatorDriver.Instance.CalculatorSession.FindElementByAccessibilityId("HistoryEmpty"));
}
#endregion

Просмотреть файл

@ -25,7 +25,7 @@ namespace CalculatorUITests
public static void ClassInitialize(TestContext context)
{
// Create session to launch a Calculator window
WinAppDriver.Instance.SetupCalculatorSession(context);
CalculatorDriver.Instance.SetupCalculatorSession(context);
// Ensure that calculator is in standard mode
page.NavigateToStandardCalculator();
@ -41,7 +41,7 @@ namespace CalculatorUITests
public static void ClassCleanup()
{
// Tear down Calculator session.
WinAppDriver.Instance.TearDownCalculatorSession();
CalculatorDriver.Instance.TearDownCalculatorSession();
}
/// <summary>
@ -78,7 +78,7 @@ namespace CalculatorUITests
page.MemoryPanel.NumberpadMSButton.Click();
page.MemoryPanel.OpenMemoryPanel();
Actions moveToListView = new Actions(WinAppDriver.Instance.CalculatorSession);
Actions moveToListView = new Actions(CalculatorDriver.Instance.CalculatorSession);
var memoryItems = page.MemoryPanel.GetAllMemoryListViewItems();
moveToListView.MoveToElement(memoryItems[0].Item);
moveToListView.ContextClick(memoryItems[0].Item);
@ -96,7 +96,7 @@ namespace CalculatorUITests
Assert.IsTrue(memoryItems2[0].GetValue().Equals("3", StringComparison.InvariantCultureIgnoreCase));
page.MemoryPanel.PanelClearMemoryButton.Click();
Assert.IsNotNull(WinAppDriver.Instance.CalculatorSession.FindElementByAccessibilityId("MemoryPaneEmpty"));
Assert.IsNotNull(CalculatorDriver.Instance.CalculatorSession.FindElementByAccessibilityId("MemoryPaneEmpty"));
}
[TestMethod]
@ -110,7 +110,7 @@ namespace CalculatorUITests
page.MemoryPanel.OpenMemoryFlyout();
var memoryItems = page.MemoryPanel.GetAllMemoryFlyoutListViewItems();
Actions moveToListView = new Actions(WinAppDriver.Instance.CalculatorSession);
Actions moveToListView = new Actions(CalculatorDriver.Instance.CalculatorSession);
moveToListView.MoveToElement(memoryItems[0].Item);
moveToListView.ContextClick(memoryItems[0].Item);
moveToListView.Perform();
@ -130,10 +130,10 @@ namespace CalculatorUITests
page.MemoryPanel.OpenMemoryFlyout();
page.MemoryPanel.PanelClearMemoryButton.Click();
Assert.IsNotNull(WinAppDriver.Instance.CalculatorSession.FindElementByAccessibilityId("MemoryPaneEmpty"));
Assert.IsNotNull(CalculatorDriver.Instance.CalculatorSession.FindElementByAccessibilityId("MemoryPaneEmpty"));
page.MemoryPanel.ResizeWindowToDisplayMemoryLabel();
Assert.IsNotNull(WinAppDriver.Instance.CalculatorSession.FindElementByAccessibilityId("MemoryPaneEmpty"));
Assert.IsNotNull(CalculatorDriver.Instance.CalculatorSession.FindElementByAccessibilityId("MemoryPaneEmpty"));
}
#endregion

Просмотреть файл

@ -24,7 +24,7 @@ namespace CalculatorUITests
public static void ClassInitialize(TestContext context)
{
// Create session to launch a Calculator window
WinAppDriver.Instance.SetupCalculatorSession(context);
CalculatorDriver.Instance.SetupCalculatorSession(context);
// Ensure that calculator is in programmer mode
page.NavigateToProgrammerCalculator();
@ -40,7 +40,7 @@ namespace CalculatorUITests
public static void ClassCleanup()
{
// Tear down Calculator session.
WinAppDriver.Instance.TearDownCalculatorSession();
CalculatorDriver.Instance.TearDownCalculatorSession();
}
/// <summary>

Просмотреть файл

@ -20,7 +20,7 @@ namespace CalculatorUITests
public static void ClassInitialize(TestContext context)
{
// Create session to launch a Calculator window
WinAppDriver.Instance.SetupCalculatorSession(context);
CalculatorDriver.Instance.SetupCalculatorSession(context);
// Ensure that calculator is in scientific mode
page.NavigateToScientificCalculator();
@ -36,7 +36,7 @@ namespace CalculatorUITests
public static void ClassCleanup()
{
// Tear down Calculator session.
WinAppDriver.Instance.TearDownCalculatorSession();
CalculatorDriver.Instance.TearDownCalculatorSession();
}
/// <summary>

Просмотреть файл

@ -25,7 +25,7 @@ namespace CalculatorUITests
public static void ClassInitialize(TestContext context)
{
// Create session to launch a Calculator window
WinAppDriver.Instance.SetupCalculatorSession(context);
CalculatorDriver.Instance.SetupCalculatorSession(context);
// Ensure that calculator is in standard mode
page.NavigateToStandardCalculator();
@ -41,7 +41,7 @@ namespace CalculatorUITests
public static void ClassCleanup()
{
// Tear down Calculator session.
WinAppDriver.Instance.TearDownCalculatorSession();
CalculatorDriver.Instance.TearDownCalculatorSession();
}
/// <summary>
@ -186,7 +186,7 @@ namespace CalculatorUITests
Assert.IsTrue(historyItems[1].GetValue().Equals("20", StringComparison.InvariantCultureIgnoreCase)); //verifies History button
Assert.IsTrue(historyItems[1].GetExpression().Equals("4 × 5=", StringComparison.InvariantCultureIgnoreCase)); //verifies History button
page.HistoryPanel.ClearHistoryButton.Click();
Assert.IsNotNull(WinAppDriver.Instance.CalculatorSession.FindElementByAccessibilityId("HistoryEmpty")); //verifies the History panel's clear history button
Assert.IsNotNull(CalculatorDriver.Instance.CalculatorSession.FindElementByAccessibilityId("HistoryEmpty")); //verifies the History panel's clear history button
}
[TestMethod]
@ -209,7 +209,7 @@ namespace CalculatorUITests
Assert.IsTrue(memoryItems[0].GetValue().Equals("1", StringComparison.InvariantCultureIgnoreCase));
Assert.AreEqual("1", page.CalculatorResults.GetCalculatorResultText()); //verifies MemMinus button
page.MemoryPanel.NumberpadMCButton.Click();
Assert.IsNotNull(WinAppDriver.Instance.CalculatorSession.FindElementByAccessibilityId("MemoryPaneEmpty")); //verifies the Memory panel's memory clear button
Assert.IsNotNull(CalculatorDriver.Instance.CalculatorSession.FindElementByAccessibilityId("MemoryPaneEmpty")); //verifies the Memory panel's memory clear button
}
#endregion
@ -367,7 +367,7 @@ namespace CalculatorUITests
Assert.IsTrue(memoryItems[0].GetValue().Equals("1", StringComparison.InvariantCultureIgnoreCase));
Assert.AreEqual("1", page.CalculatorResults.GetCalculatorResultText()); //verifies MemMinus hotkey
CalculatorApp.Window.SendKeys(Keys.Control + "l" + Keys.Control);
Assert.IsNotNull(WinAppDriver.Instance.CalculatorSession.FindElementByAccessibilityId("MemoryPaneEmpty")); //verifies the Memory panel's memory clear button hotkey
Assert.IsNotNull(CalculatorDriver.Instance.CalculatorSession.FindElementByAccessibilityId("MemoryPaneEmpty")); //verifies the Memory panel's memory clear button hotkey
}
[TestMethod]
@ -398,7 +398,7 @@ namespace CalculatorUITests
Assert.IsTrue(historyExpression0.Equals("20÷2=", StringComparison.InvariantCultureIgnoreCase)); //verifies History button hotkeys
Assert.IsTrue(historyExpression1.Equals("4×5=", StringComparison.InvariantCultureIgnoreCase)); //verifies History button hotkeys
CalculatorApp.Window.SendKeys(Keys.Shift + Keys.Control + "d" + Keys.Control + Keys.Shift);
Assert.IsNotNull(WinAppDriver.Instance.CalculatorSession.FindElementByAccessibilityId("HistoryEmpty")); //verifies the History panel's clear history button hotkeys
Assert.IsNotNull(CalculatorDriver.Instance.CalculatorSession.FindElementByAccessibilityId("HistoryEmpty")); //verifies the History panel's clear history button hotkeys
}
#endregion
@ -690,7 +690,7 @@ namespace CalculatorUITests
CalculatorApp.Window.SendKeys(Keys.Shift); //Hotkeys such as "Delete" will break without this line
page.StandardAoTCalculatorPage.NavigateToStandardMode();
page.MemoryPanel.OpenMemoryPanel();
Assert.IsNotNull(WinAppDriver.Instance.CalculatorSession.FindElementByAccessibilityId("MemoryPaneEmpty"));
Assert.IsNotNull(CalculatorDriver.Instance.CalculatorSession.FindElementByAccessibilityId("MemoryPaneEmpty"));
}
[TestMethod]
@ -703,7 +703,7 @@ namespace CalculatorUITests
page.StandardAoTCalculatorPage.NavigateToStandardAoTMode();
page.StandardOperators.EqualButton.Click();
CalculatorApp.Window.SendKeys(Keys.Control + "H" + Keys.Control);
string source = WinAppDriver.Instance.CalculatorSession.PageSource;
string source = CalculatorDriver.Instance.CalculatorSession.PageSource;
if (source.Contains("HistoryFlyout"))
{
throw new NotFoundException("This test fails; history flyout is present");