From a8b3e7b574a9381a942d72f7f3732994f28c0307 Mon Sep 17 00:00:00 2001 From: Nick Abalov Date: Thu, 17 Dec 2015 11:52:31 +0600 Subject: [PATCH] Change the way GetElementAttribute handles attribute names This breaks v1.5.0 GetElementAttribute compatibility To access Automation Properties the name of property: - must prefixed by `AutomationProperties.` - must not be suffixed by `Property` - examples: - `AutomationProperties.AutomationId` - `AutomationProperties.Name` To access Dependency Properties the name of the property: - must not be suffixed by `Property` - examples: - `IsReadOnly` --- Winium/TestApp.Test/py-functional/tests/test_commands.py | 2 +- .../tests/test_element_attribute_settings.py | 2 +- .../Element/Helpers/AutomationPropertiesAccessor.cs | 2 ++ .../Element/Helpers/PropertiesAccessor.cs | 1 + .../Element/WiniumElement.cs | 9 +++++++++ 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Winium/TestApp.Test/py-functional/tests/test_commands.py b/Winium/TestApp.Test/py-functional/tests/test_commands.py index cfccdf1..45b838e 100644 --- a/Winium/TestApp.Test/py-functional/tests/test_commands.py +++ b/Winium/TestApp.Test/py-functional/tests/test_commands.py @@ -109,7 +109,7 @@ def test_get_element_text(self): @pytest.mark.parametrize(("attr_name", "expected_value"), [ ('Width', '300'), ('DesiredSize.Width', '300'), - ('AutomationIdProperty', 'MyTextBox'), + ('AutomationProperties.AutomationId', 'MyTextBox'), ('Visibility', '0'), ], ids=['simple property', 'nested property', 'automation property', 'enum']) def test_get_element_attribute(self, attr_name, expected_value): diff --git a/Winium/TestApp.Test/py-functional/tests/test_element_attribute_settings.py b/Winium/TestApp.Test/py-functional/tests/test_element_attribute_settings.py index b9beae6..a259035 100644 --- a/Winium/TestApp.Test/py-functional/tests/test_element_attribute_settings.py +++ b/Winium/TestApp.Test/py-functional/tests/test_element_attribute_settings.py @@ -55,6 +55,6 @@ def test_get_element_attribute_access_modifier(self, driver): element = driver.find_element_by_id('MyTextBox') - for i, attr in enumerate(['AutomationIdProperty', 'IsReadOnlyProperty', 'Width']): + for i, attr in enumerate(['AutomationProperties.AutomationId', 'IsReadOnly', 'Width']): value = element.get_attribute(attr) assert expected[i] == value diff --git a/Winium/Winium.StoreApps.InnerServer/Element/Helpers/AutomationPropertiesAccessor.cs b/Winium/Winium.StoreApps.InnerServer/Element/Helpers/AutomationPropertiesAccessor.cs index f08fe12..29054a5 100644 --- a/Winium/Winium.StoreApps.InnerServer/Element/Helpers/AutomationPropertiesAccessor.cs +++ b/Winium/Winium.StoreApps.InnerServer/Element/Helpers/AutomationPropertiesAccessor.cs @@ -12,8 +12,10 @@ internal static class AutomationPropertiesAccessor public static bool TryGetAutomationProperty(FrameworkElement element, string propertyName, out object value) { + propertyName = string.Format("{0}Property", propertyName); value = null; DependencyProperty property; + if (!AutomationPropertiesHelper.Instance.TryGetAutomationProperty(propertyName, out property)) { return false; diff --git a/Winium/Winium.StoreApps.InnerServer/Element/Helpers/PropertiesAccessor.cs b/Winium/Winium.StoreApps.InnerServer/Element/Helpers/PropertiesAccessor.cs index e95586c..91cb170 100644 --- a/Winium/Winium.StoreApps.InnerServer/Element/Helpers/PropertiesAccessor.cs +++ b/Winium/Winium.StoreApps.InnerServer/Element/Helpers/PropertiesAccessor.cs @@ -35,6 +35,7 @@ public static void SetProperty(FrameworkElement element, string propertyName, JT public static bool TryGetDependencyProperty(FrameworkElement element, string propertyName, out object value) { + propertyName = string.Format("{0}Property", propertyName); value = null; var propertyInfo = element.GetType() diff --git a/Winium/Winium.StoreApps.InnerServer/Element/WiniumElement.cs b/Winium/Winium.StoreApps.InnerServer/Element/WiniumElement.cs index 310dce4..09ea960 100644 --- a/Winium/Winium.StoreApps.InnerServer/Element/WiniumElement.cs +++ b/Winium/Winium.StoreApps.InnerServer/Element/WiniumElement.cs @@ -145,6 +145,15 @@ public void SetProperty(string attributeName, JToken value) public bool TryGetAutomationProperty(string automationPropertyName, out object value) { + const string Prefix = "AutomationProperties."; + value = null; + if (!automationPropertyName.StartsWith(Prefix)) + { + return false; + } + + automationPropertyName = automationPropertyName.Remove(0, Prefix.Length); + return AutomationPropertiesAccessor.TryGetAutomationProperty( this.Element, automationPropertyName,