Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add settings for GetElementAttribute command #120

Merged
merged 1 commit into from
Dec 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Winium/TestApp.Test/py-functional/tests/test_commands.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# coding: utf-8
from time import sleep

import pytest
from selenium.common.exceptions import NoSuchElementException, NoAlertPresentException, WebDriverException
from selenium.webdriver import ActionChains
Expand All @@ -9,14 +10,14 @@

from tests import WuaTestCase


By.XNAME = 'xname'


class TestGetCommands(WuaTestCase):
"""
Test GET commands that do not change anything in app, meaning they can all be run in one session.
"""

def test_get_current_window_handle(self):
"""
GET /session/:sessionId/window_handle Retrieve the current window handle.
Expand Down Expand Up @@ -108,8 +109,9 @@ def test_get_element_text(self):
@pytest.mark.parametrize(("attr_name", "expected_value"), [
('Width', '300'),
('DesiredSize.Width', '300'),
('AutomationIdProperty', 'MyTextBox')
], ids=['simple property', 'nested property', 'automation property'])
('AutomationIdProperty', 'MyTextBox'),
('Visibility', '0'),
], ids=['simple property', 'nested property', 'automation property', 'enum'])
def test_get_element_attribute(self, attr_name, expected_value):
"""
GET /session/:sessionId/element/:id/attribute/:name Get the value of an element's attribute.
Expand Down Expand Up @@ -252,7 +254,7 @@ def test_automation_toggle(self):

assert start_state != end_state

@pytest.mark.parametrize(("attribute", "value"), [('Width', 10, ), ('Background.Opacity', 0, )],
@pytest.mark.parametrize(("attribute", "value"), [('Width', 10,), ('Background.Opacity', 0,)],
ids=["should set basic properties", "should set nested properties"])
def test_attribute_set(self, attribute, value):
element = self.driver.find_element_by_id('SetButton')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# coding: utf-8
from copy import copy

import pytest
from selenium.webdriver import Remote

import config


@pytest.yield_fixture()
def driver(request):
capabilities = request.param
winium = Remote(command_executor="http://localhost:9999", desired_capabilities=capabilities)
yield winium
winium.quit()


def _enum_as_string_settings_capability(value):
caps = copy(config.DESIRED_CAPABILITIES)
caps['commandSettings'] = {'elementAttributeSettings': {'enumAsString': value}}
return caps


def _access_modifier_settings_capability(value):
caps = copy(config.DESIRED_CAPABILITIES)
caps['commandSettings'] = {'elementAttributeSettings': {'accessModifier': value}}
return caps


class TestElementAttributeCommandSettings(object):
@pytest.mark.parametrize('driver', [_enum_as_string_settings_capability(False)], indirect=True)
def test_get_element_attribute_enum_as_value(self, driver):
element = driver.find_element_by_id('MyTextBox')
element.get_attribute('DesiredSize')
value = element.get_attribute('Visibility')
assert '0' == value

@pytest.mark.parametrize('driver', [_enum_as_string_settings_capability(True)], indirect=True)
def test_get_element_attribute_enum_as_string(self, driver):
element = driver.find_element_by_id('MyTextBox')
value = element.get_attribute('Visibility')
assert 'Visible' == value

@pytest.mark.parametrize('driver', [
_access_modifier_settings_capability('AutomationProperties'),
_access_modifier_settings_capability('DependencyProperties'),
_access_modifier_settings_capability('ClrProperties'),
], indirect=True)
def test_get_element_attribute_access_modifier(self, driver):
expected = {
'AutomationProperties': ['MyTextBox', None, None],
'DependencyProperties': ['MyTextBox', 'false', None],
'ClrProperties': ['MyTextBox', 'false', '300'],
}[driver.desired_capabilities['commandSettings']['elementAttributeSettings']['accessModifier']]

element = driver.find_element_by_id('MyTextBox')

for i, attr in enumerate(['AutomationIdProperty', 'IsReadOnlyProperty', 'Width']):
value = element.get_attribute(attr)
assert expected[i] == value
22 changes: 3 additions & 19 deletions Winium/Winium.StoreApps.Common/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,11 @@

public class Command
{
#region Fields

private IDictionary<string, JToken> commandParameters = new JObject();

#endregion

#region Constructors and Destructors

public Command(string name, IDictionary<string, JToken> parameters)
: this(name)
{
this.Name = name;
if (parameters != null)
{
this.Parameters = parameters;
Expand All @@ -35,6 +29,7 @@ public Command(string name, string jsonParameters)

public Command(string name)
{
this.Parameters = new JObject();
this.Name = name;
}

Expand All @@ -56,18 +51,7 @@ public Command()
/// Gets the parameters of the command
/// </summary>
[JsonProperty("parameters")]
public IDictionary<string, JToken> Parameters
{
get
{
return this.commandParameters;
}

set
{
this.commandParameters = value;
}
}
public IDictionary<string, JToken> Parameters { get; set; }

/// <summary>
/// Gets the SessionID of the command
Expand Down
33 changes: 33 additions & 0 deletions Winium/Winium.StoreApps.Common/CommandSettings/CommandSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace Winium.StoreApps.Common.CommandSettings
{
#region

using Newtonsoft.Json;

#endregion

public class CommandSettings
{
#region Constants

public const string ElementAttributeSettingsParameter = "ElementAttributeSettings";

#endregion

#region Constructors and Destructors

public CommandSettings()
{
this.ElementAttributeSettings = new ElementAttributeCommandSettings();
}

#endregion

#region Public Properties

[JsonProperty("elementAttributeSettings")]
public ElementAttributeCommandSettings ElementAttributeSettings { get; set; }

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace Winium.StoreApps.Common.CommandSettings
{
#region

using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

#endregion

public enum ElementAttributeAccessModifier
{
None = 0,

AutomationProperties = 1,

DependencyProperties = 3,

ClrProperties = 7,
}

public class ElementAttributeCommandSettings
{
#region Constructors and Destructors

public ElementAttributeCommandSettings()
{
this.AccessModifier = ElementAttributeAccessModifier.ClrProperties;
this.EnumAsString = false;
}

#endregion

#region Public Properties

[JsonProperty("accessModifier")]
[JsonConverter(typeof(StringEnumConverter))]
public ElementAttributeAccessModifier AccessModifier { get; set; }

[JsonProperty("enumAsString")]
public bool EnumAsString { get; set; }

#endregion
}
}
2 changes: 2 additions & 0 deletions Winium/Winium.StoreApps.Common/Winium.StoreApps.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@
<Compile Include="Command.cs" />
<Compile Include="CommandInfo.cs" />
<Compile Include="CommandResponse.cs" />
<Compile Include="CommandSettings\ElementAttributeCommandSettings.cs" />
<Compile Include="ConnectionInformation.cs" />
<Compile Include="DriverCommand.cs" />
<Compile Include="Exceptions\AutomationException.cs" />
<Compile Include="Exceptions\InnerDriverRequestException.cs" />
<Compile Include="HttpResponseHelper.cs" />
<Compile Include="CommandSettings\CommandSettings.cs" />
<Compile Include="JsonErrorCodes.cs" />
<Compile Include="JsonWireClasses.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
5 changes: 5 additions & 0 deletions Winium/Winium.StoreApps.Driver/Automator/Capabilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Newtonsoft.Json.Serialization;

using Winium.Mobile.Connectivity;
using Winium.StoreApps.Common.CommandSettings;
using Winium.StoreApps.Common.Exceptions;

#endregion
Expand Down Expand Up @@ -35,6 +36,7 @@ internal Capabilities()
this.Dependencies = new List<string>();
this.PingTimeout = DefaultPingTimeout;
this.NoFallback = true;
this.CommandSettings = new CommandSettings();
}

#endregion
Expand Down Expand Up @@ -110,6 +112,9 @@ public static string PlatformName
[JsonProperty("takesScreenshot")]
public bool TakesScreenshot { get; set; }

[JsonProperty("commandSettings")]
public CommandSettings CommandSettings { get; set; }

#endregion

#region Public Methods and Operators
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace Winium.StoreApps.Driver.CommandExecutors
{
#region

using Newtonsoft.Json.Linq;

using Winium.StoreApps.Common.CommandSettings;

#endregion

internal class GetElementAttributeExecutor : CommandExecutorBase
{
#region Methods

protected override string DoImpl()
{
var settings = JToken.FromObject(this.Automator.ActualCapabilities.CommandSettings.ElementAttributeSettings);
this.ExecutedCommand.Parameters.Add(CommandSettings.ElementAttributeSettingsParameter, settings);
var response = this.Automator.CommandForwarder.ForwardCommand(this.ExecutedCommand);

return response;
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<ItemGroup>
<Compile Include="Automator\Automator.cs" />
<Compile Include="Automator\Capabilities.cs" />
<Compile Include="CommandExecutors\GetElementAttributeExecutor.cs" />
<Compile Include="CommandExecutors\CloseAppExecutor.cs" />
<Compile Include="CommandExecutors\LaunchAppExecutor.cs" />
<Compile Include="CommandExecutors\SetOrientationExecutor.cs" />
Expand Down
Loading