Remove ICustomPropertyProviders (#1229)

* Remove unused ICustomPropertyProviders
* Modify UI tests to not use Customproperties
This commit is contained in:
Rudy Huyn 2020-08-12 08:22:49 -07:00 committed by GitHub
parent 6299ec2303
commit 1c8b642376
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 112 additions and 75 deletions

View File

@ -9,7 +9,7 @@ namespace CalculatorApp
{
namespace ViewModel
{
[Windows::UI::Xaml::Data::Bindable] public ref class HistoryItemViewModel sealed : Windows::UI::Xaml::Data::ICustomPropertyProvider
[Windows::UI::Xaml::Data::Bindable] public ref class HistoryItemViewModel sealed
{
internal :
@ -42,23 +42,6 @@ namespace CalculatorApp
property Platform::String
^ AccResult { Platform::String ^ get() { return m_accResult; } }
virtual Windows::UI::Xaml::Data::ICustomProperty
^ GetCustomProperty(Platform::String ^ name) { return nullptr; }
virtual Windows::UI::Xaml::Data::ICustomProperty
^ GetIndexedProperty(Platform::String ^ name, Windows::UI::Xaml::Interop::TypeName type) { return nullptr; }
virtual property Windows::UI::Xaml::Interop::TypeName Type
{
Windows::UI::Xaml::Interop::TypeName get()
{
return this->GetType();
}
}
virtual Platform::String
^ GetStringRepresentation() { return m_accExpression + " " + m_accResult; }
private : static Platform::String
^ GetAccessibleExpressionFromTokens(
_In_ std::shared_ptr<std::vector<std::pair<std::wstring, int>>> const& spTokens,

View File

@ -14,8 +14,7 @@ namespace CalculatorApp
/// <summary>
/// Model representation of a single item in the Memory list
/// </summary>
[Windows::UI::Xaml::Data::Bindable] public ref class MemoryItemViewModel sealed : public Windows::UI::Xaml::Data::INotifyPropertyChanged,
Windows::UI::Xaml::Data::ICustomPropertyProvider
[Windows::UI::Xaml::Data::Bindable] public ref class MemoryItemViewModel sealed : public Windows::UI::Xaml::Data::INotifyPropertyChanged
{
public:
MemoryItemViewModel(StandardCalculatorViewModel ^ calcVM)
@ -27,24 +26,7 @@ namespace CalculatorApp
OBSERVABLE_PROPERTY_RW(int, Position);
OBSERVABLE_PROPERTY_RW(Platform::String ^, Value);
virtual Windows::UI::Xaml::Data::ICustomProperty
^ GetCustomProperty(Platform::String ^ name) { return nullptr; }
virtual Windows::UI::Xaml::Data::ICustomProperty
^ GetIndexedProperty(Platform::String ^ name, Windows::UI::Xaml::Interop::TypeName type) { return nullptr; }
virtual property Windows::UI::Xaml::Interop::TypeName Type
{
Windows::UI::Xaml::Interop::TypeName get()
{
return this->GetType();
}
}
virtual Platform::String
^ GetStringRepresentation() { return Value; }
void Clear();
void Clear();
void MemoryAdd();
void MemorySubtract();

View File

@ -63,6 +63,7 @@
Margin="0,0,0,4"
HorizontalAlignment="Right"
Style="{ThemeResource BodyTextBlockMediumStyle}"
AutomationProperties.AutomationId="HistoryItemExpression"
AutomationProperties.Name="{x:Bind AccExpression}"
IsTextSelectionEnabled="True"
Text="{x:Bind Expression}"
@ -72,6 +73,7 @@
HorizontalAlignment="Right"
Style="{ThemeResource TitleTextBlockStyle}"
FontWeight="SemiBold"
AutomationProperties.AutomationId="HistoryItemValue"
AutomationProperties.Name="{x:Bind AccResult}"
IsTextSelectionEnabled="True"
Text="{x:Bind Result}"

View File

@ -54,6 +54,7 @@
HorizontalAlignment="Right"
Style="{ThemeResource TitleTextBlockStyle}"
FontWeight="SemiBold"
AutomationProperties.AutomationId="MemoryItemValue"
FlowDirection="LeftToRight"
IsTextSelectionEnabled="True"
Text="{x:Bind Model.Value, Mode=OneWay}"

View File

@ -0,0 +1,29 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using OpenQA.Selenium.Appium;
using System;
using System.Collections.Generic;
using System.Text;
namespace CalculatorUITestFramework
{
public class HistoryItem
{
public AppiumWebElement Item { get; }
public HistoryItem(AppiumWebElement item)
{
Item = item;
}
public string GetValue()
{
return Item.FindElementByAccessibilityId("HistoryItemValue")?.Text;
}
public string GetExpression()
{
return Item.FindElementByAccessibilityId("HistoryItemExpression")?.Text;
}
}
}

View File

@ -5,8 +5,10 @@
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Interactions;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Linq;
namespace CalculatorUITestFramework
{
@ -34,10 +36,10 @@ public void OpenHistoryPanel()
/// Gets all of the history items listed in the History Pane.
/// </summary>
/// <returns>A readonly collection of history items.</returns>
public ReadOnlyCollection<AppiumWebElement> GetAllHistoryListViewItems()
public List<HistoryItem> GetAllHistoryListViewItems()
{
OpenHistoryPanel();
return this.HistoryListView.FindElementsByClassName("ListViewItem");
return (from item in this.HistoryListView.FindElementsByClassName("ListViewItem") select new HistoryItem(item)).ToList();
}
/// <summary>
@ -92,10 +94,10 @@ public void OpenHistoryFlyout()
/// Gets all of the History items listed in the History Flyout.
/// </summary>
/// <returns> A read only collection of History items.</returns>
public ReadOnlyCollection<AppiumWebElement> GetAllHistoryFlyoutListViewItems()
public List<HistoryItem> GetAllHistoryFlyoutListViewItems()
{
OpenHistoryFlyout();
return this.HistoryListView.FindElementsByClassName("ListViewItem");
return (from item in this.HistoryListView.FindElementsByClassName("ListViewItem") select new HistoryItem(item)).ToList();
}
/// <summary>

View File

@ -0,0 +1,25 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using OpenQA.Selenium.Appium;
using System;
using System.Collections.Generic;
using System.Text;
namespace CalculatorUITestFramework
{
public class MemoryItem
{
public AppiumWebElement Item { get; }
public MemoryItem(AppiumWebElement item)
{
Item = item;
}
public string GetValue()
{
return Item.FindElementByAccessibilityId("MemoryItemValue")?.Text;
}
}
}

View File

@ -6,8 +6,10 @@
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Interactions;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Linq;
namespace CalculatorUITestFramework
{
@ -43,10 +45,10 @@ public void OpenMemoryPanel()
/// Gets all of the memory items listed in the Memory Pane.
/// </summary>
/// <returns>A read-only collection of memory items.</returns>
public ReadOnlyCollection<AppiumWebElement> GetAllMemoryListViewItems()
public List<MemoryItem> GetAllMemoryListViewItems()
{
OpenMemoryPanel();
return this.MemoryListView.FindElementsByClassName("ListViewItem");
return (from item in this.MemoryListView.FindElementsByClassName("ListViewItem") select new MemoryItem(item)).ToList();
}
/// <summary>
@ -119,10 +121,10 @@ public void OpenMemoryFlyout()
/// Gets all of the memory items listed in the Memory Flyout.
/// </summary>
/// <returns> A read only collection of memory items.</returns>
public ReadOnlyCollection<AppiumWebElement> GetAllMemoryFlyoutListViewItems()
public List<MemoryItem> GetAllMemoryFlyoutListViewItems()
{
OpenMemoryFlyout();
return this.MemoryListView.FindElementsByClassName("ListViewItem");
return (from item in this.MemoryListView.FindElementsByClassName("ListViewItem") select new MemoryItem(item)).ToList();
}
/// <summary>

View File

@ -88,20 +88,22 @@ public void StandardHistory_Panel()
page.StandardOperators.EqualButton.Click();
var historyItems = page.HistoryPanel.GetAllHistoryListViewItems();
Assert.IsTrue(historyItems[0].Text.Equals("2 Minus ( 3= Minus (1", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(historyItems[1].Text.Equals("-3 + -2.6= Minus (5.6", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(historyItems[0].GetValue().Equals("-1", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(historyItems[0].GetExpression().Equals("2 - 3 =", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(historyItems[1].GetValue().Equals("-5.6", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(historyItems[1].GetExpression().Equals("-3 + -2.6 =", StringComparison.InvariantCultureIgnoreCase));
Assert.AreEqual("-1", page.CalculatorResults.GetCalculatorResultText());
Actions clickHistoryItemsw1 = new Actions(WinAppDriver.Instance.CalculatorSession);
clickHistoryItemsw1.Click(historyItems[1]);
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);
clickHistoryItemsw0.Click(historyItems[0]);
clickHistoryItemsw0.Click(historyItems[0].Item);
clickHistoryItemsw0.Perform();
Assert.AreEqual("-1", page.CalculatorResults.GetCalculatorResultText());
@ -131,14 +133,18 @@ public void StandardHistory_Flyout()
page.StandardOperators.EqualButton.Click();
var historyPanelItems = page.HistoryPanel.GetAllHistoryListViewItems();
Assert.IsTrue(historyPanelItems[0].Text.Equals("2 Minus ( 3= Minus (1", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(historyPanelItems[1].Text.Equals("-3 + -2.6= Minus (5.6", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(historyPanelItems[0].GetValue().Equals("-1", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(historyPanelItems[0].GetExpression().Equals("2 - 3 =", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(historyPanelItems[1].GetValue().Equals("-5.6", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(historyPanelItems[1].GetExpression().Equals("-3 + -2.6 =", StringComparison.InvariantCultureIgnoreCase));
Assert.AreEqual("-1", page.CalculatorResults.GetCalculatorResultText());
var historyItems = page.HistoryPanel.GetAllHistoryFlyoutListViewItems();
Assert.IsTrue(historyItems[0].Text.Equals("2 Minus ( 3= Minus (1", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(historyItems[1].Text.Equals("-3 + -2.6= Minus (5.6", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(historyItems[0].GetValue().Equals("-1", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(historyItems[0].GetExpression().Equals("2 - 3 =", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(historyItems[1].GetValue().Equals("-5.6", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(historyItems[1].GetExpression().Equals("-3 + -2.6 =", StringComparison.InvariantCultureIgnoreCase));
Assert.AreEqual("-1", page.CalculatorResults.GetCalculatorResultText());

View File

@ -77,20 +77,20 @@ public void StandardMemory_Panel()
Actions moveToListView = new Actions(WinAppDriver.Instance.CalculatorSession);
var memoryItems = page.MemoryPanel.GetAllMemoryListViewItems();
moveToListView.MoveToElement(memoryItems[0]);
moveToListView.ContextClick(memoryItems[0]);
moveToListView.MoveToElement(memoryItems[0].Item);
moveToListView.ContextClick(memoryItems[0].Item);
moveToListView.Perform();
CalculatorApp.Window.SendKeys(Keys.ArrowDown + Keys.ArrowDown + Keys.Enter);
Assert.IsTrue(memoryItems[0].Text.Equals("0", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(memoryItems[0].GetValue().Equals("0", StringComparison.InvariantCultureIgnoreCase));
moveToListView.Perform();
CalculatorApp.Window.SendKeys(Keys.ArrowUp + Keys.ArrowUp + Keys.Enter);
Assert.IsTrue(memoryItems[0].Text.Equals("3", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(memoryItems[0].GetValue().Equals("3", StringComparison.InvariantCultureIgnoreCase));
moveToListView.Perform();
CalculatorApp.Window.SendKeys(Keys.ArrowDown + Keys.ArrowUp + Keys.Enter);
var memoryItems2 = page.MemoryPanel.GetAllMemoryListViewItems();
Assert.IsTrue(memoryItems2[0].Text.Equals("3", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(memoryItems2[0].GetValue().Equals("3", StringComparison.InvariantCultureIgnoreCase));
page.MemoryPanel.PanelClearMemoryButton.Click();
Assert.IsNotNull(WinAppDriver.Instance.CalculatorSession.FindElementByAccessibilityId("MemoryPaneEmpty"));
@ -108,22 +108,22 @@ public void StandardMemory_Flyout()
page.MemoryPanel.OpenMemoryFlyout();
var memoryItems = page.MemoryPanel.GetAllMemoryFlyoutListViewItems();
Actions moveToListView = new Actions(WinAppDriver.Instance.CalculatorSession);
moveToListView.MoveToElement(memoryItems[0]);
moveToListView.ContextClick(memoryItems[0]);
moveToListView.MoveToElement(memoryItems[0].Item);
moveToListView.ContextClick(memoryItems[0].Item);
moveToListView.Perform();
CalculatorApp.Window.SendKeys(Keys.ArrowDown + Keys.ArrowDown + Keys.Enter);
Assert.IsTrue(memoryItems[0].Text.Equals("0", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(memoryItems[0].GetValue().Equals("0", StringComparison.InvariantCultureIgnoreCase));
page.MemoryPanel.OpenMemoryFlyout();
moveToListView.Perform();
CalculatorApp.Window.SendKeys(Keys.ArrowUp + Keys.ArrowUp + Keys.Enter);
Assert.IsTrue(memoryItems[0].Text.Equals("3", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(memoryItems[0].GetValue().Equals("3", StringComparison.InvariantCultureIgnoreCase));
page.MemoryPanel.OpenMemoryFlyout();
moveToListView.Perform();
CalculatorApp.Window.SendKeys(Keys.ArrowDown + Keys.ArrowUp + Keys.Enter);
var memoryItems2 = page.MemoryPanel.GetAllMemoryListViewItems();
Assert.IsTrue(memoryItems2[0].Text.Equals("3", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(memoryItems2[0].GetValue().Equals("3", StringComparison.InvariantCultureIgnoreCase));
page.MemoryPanel.OpenMemoryFlyout();
page.MemoryPanel.PanelClearMemoryButton.Click();

View File

@ -171,10 +171,12 @@ public void MouseInput_HistoryButtons()
page.HistoryPanel.ResizeWindowToDisplayHistoryButton();
page.HistoryPanel.HistoryButton.Click();
var historyFlyoutItems = page.HistoryPanel.GetAllHistoryFlyoutListViewItems();
Assert.IsTrue(historyFlyoutItems[0].Text.Equals("4 × 5 ÷ 6= 3.333333333333333", StringComparison.InvariantCultureIgnoreCase)); //verifies History button
Assert.IsTrue(historyFlyoutItems[0].GetValue().Equals("3.333333333333333", StringComparison.InvariantCultureIgnoreCase)); //verifies History button
Assert.IsTrue(historyFlyoutItems[0].GetExpression().Equals("4 × 5 ÷ 6 =", StringComparison.InvariantCultureIgnoreCase)); //verifies History button
page.HistoryPanel.ResizeWindowToDisplayHistoryLabel();
var historyItems = page.HistoryPanel.GetAllHistoryListViewItems();
Assert.IsTrue(historyItems[0].Text.Equals("4 × 5 ÷ 6= 3.333333333333333", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(historyItems[0].GetValue().Equals("3.333333333333333", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(historyItems[0].GetExpression().Equals("4 × 5 ÷ 6 =", StringComparison.InvariantCultureIgnoreCase));
page.HistoryPanel.ClearHistoryButton.Click();
Assert.IsNotNull(WinAppDriver.Instance.CalculatorSession.FindElementByAccessibilityId("HistoryEmpty")); //verifies the History panel's clear history button
}
@ -187,16 +189,16 @@ public void MouseInput_MemoryButtons()
page.StandardOperators.NumberPad.Num1Button.Click();
page.MemoryPanel.NumberpadMSButton.Click();
var memoryItems = page.MemoryPanel.GetAllMemoryListViewItems();
Assert.IsTrue(memoryItems[0].Text.Equals("1", StringComparison.InvariantCultureIgnoreCase)); //verifies memory button
Assert.IsTrue(memoryItems[0].GetValue().Equals("1", StringComparison.InvariantCultureIgnoreCase)); //verifies memory button
page.MemoryPanel.NumberpadMPlusButton.Click();
Assert.IsTrue(memoryItems[0].Text.Equals("2", StringComparison.InvariantCultureIgnoreCase)); //verifies memory plus button
Assert.IsTrue(memoryItems[0].GetValue().Equals("2", StringComparison.InvariantCultureIgnoreCase)); //verifies memory plus button
page.MemoryPanel.NumberpadMRButton.Click();
Assert.AreEqual("2", page.CalculatorResults.GetCalculatorResultText()); //verifies memory recall button
page.StandardOperators.MinusButton.Click();
page.StandardOperators.NumberPad.Num1Button.Click();
page.StandardOperators.EqualButton.Click();
page.MemoryPanel.NumberpadMMinusButton.Click();
Assert.IsTrue(memoryItems[0].Text.Equals("1", StringComparison.InvariantCultureIgnoreCase));
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
@ -344,9 +346,9 @@ public void KeyboardInput_MemoryHotkeys()
CalculatorApp.Window.SendKeys("1");
CalculatorApp.Window.SendKeys(Keys.Control + "m" + Keys.Control);
var memoryItems = page.MemoryPanel.GetAllMemoryListViewItems();
Assert.IsTrue(memoryItems[0].Text.Equals("1", StringComparison.InvariantCultureIgnoreCase)); //verifies memory hotkey
Assert.IsTrue(memoryItems[0].GetValue().Equals("1", StringComparison.InvariantCultureIgnoreCase)); //verifies memory hotkey
CalculatorApp.Window.SendKeys(Keys.Control + "p" + Keys.Control);
Assert.IsTrue(memoryItems[0].Text.Equals("2", StringComparison.InvariantCultureIgnoreCase)); //verifies memory plus hotkey
Assert.IsTrue(memoryItems[0].GetValue().Equals("2", StringComparison.InvariantCultureIgnoreCase)); //verifies memory plus hotkey
CalculatorApp.Window.SendKeys(Keys.Control + "r" + Keys.Control);
Assert.AreEqual("2", page.CalculatorResults.GetCalculatorResultText()); //verifies memory recall hotkey
CalculatorApp.Window.SendKeys(Keys.Subtract);
@ -354,7 +356,7 @@ public void KeyboardInput_MemoryHotkeys()
CalculatorApp.Window.SendKeys(Keys.Equal);
CalculatorApp.Window.SendKeys(Keys.Subtract);
CalculatorApp.Window.SendKeys(Keys.Control + "q" + Keys.Control);
Assert.IsTrue(memoryItems[0].Text.Equals("1", StringComparison.InvariantCultureIgnoreCase));
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
@ -536,8 +538,10 @@ public void MixedInput_Operators_Equal()
CalculatorApp.Window.SendKeys(Keys.Equal);
Assert.AreEqual("0", page.CalculatorResults.GetCalculatorResultText());
var historyItems = page.HistoryPanel.GetAllHistoryListViewItems();
Assert.IsTrue(historyItems[0].Text.Equals("0= 0", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(historyItems[1].Text.Equals("0= 0", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(historyItems[0].GetValue().Equals("0", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(historyItems[0].GetExpression().Equals("0 =", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(historyItems[1].GetValue().Equals("0", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(historyItems[1].GetExpression().Equals("0 =", StringComparison.InvariantCultureIgnoreCase));
CalculatorApp.Window.SendKeys(Keys.Escape);
}
@ -670,7 +674,8 @@ public void AoT_HistoryFunction()
{
page.StandardAoTCalculatorPage.NavigateToStandardMode();
var historyItems = page.HistoryPanel.GetAllHistoryListViewItems();
Assert.IsTrue(historyItems[0].Text.Equals("3 + 3= 6", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(historyItems[0].GetValue().Equals("6", StringComparison.InvariantCultureIgnoreCase));
Assert.IsTrue(historyItems[0].GetExpression().Equals("3 + 3 =", StringComparison.InvariantCultureIgnoreCase));
}
}