Skip to content

Commit

Permalink
Merge pull request #123 from 2gis/change-get-attribute
Browse files Browse the repository at this point in the history
Change the way GetElementAttribute handles attribute names
  • Loading branch information
skyline-gleb committed Dec 28, 2015
2 parents 213a4be + a8b3e7b commit 824e669
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Winium/TestApp.Test/py-functional/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions Winium/Winium.StoreApps.InnerServer/Element/WiniumElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 824e669

Please sign in to comment.