From 945596c4cdb9b398f878baa07461573da9732350 Mon Sep 17 00:00:00 2001 From: "t.kurnosova" Date: Thu, 30 Jul 2015 15:46:07 +0600 Subject: [PATCH 1/2] Add DataGrid props ColumnCount and RowCount --- .../DataGridTests.cs | 41 +++++++++++++++---- .../DriverMocked.cs | 29 +++++++++++++ .../Winium.Elements.Desktop.Tests.csproj | 7 ++-- src/Winium.Elements.Desktop/DataGrid.cs | 40 +++++++++++++++++- 4 files changed, 106 insertions(+), 11 deletions(-) create mode 100644 src/Tests/Winium.Elements.Desktop.Tests/DriverMocked.cs diff --git a/src/Tests/Winium.Elements.Desktop.Tests/DataGridTests.cs b/src/Tests/Winium.Elements.Desktop.Tests/DataGridTests.cs index fdf6367..0ce016f 100644 --- a/src/Tests/Winium.Elements.Desktop.Tests/DataGridTests.cs +++ b/src/Tests/Winium.Elements.Desktop.Tests/DataGridTests.cs @@ -22,18 +22,12 @@ public class DataGridTests [Test] public void GetDataGridCell() { - var driverMock = new Mock( - new Mock().Object, - new Mock().Object); + var driverMock = new DriverMocked(); driverMock.Protected() .Setup("Execute", "getDataGridCell", ItExpr.IsAny>()) .Returns(Response.FromJson(@"{value: {ELEMENT: ""dGridCellElementId""}}")); - driverMock.Protected() - .Setup("Execute", "newSession", ItExpr.IsAny>()) - .Returns(Response.FromJson(@"{sessionId : ""AvesomeSession""}")); - var elementMock = new Mock(driverMock.Object, "dGridElementId"); var dataGrid = elementMock.Object.ToDataGrid(); @@ -43,6 +37,39 @@ public void GetDataGridCell() Assert.That(cell, Is.TypeOf(typeof(RemoteWebElement))); } + [Test] + public void GetDataGridColumnCount() + { + var driverMock = new DriverMocked(); + + driverMock.Protected() + .Setup("Execute", "getDataGridColumnCount", ItExpr.IsAny>()) + .Returns(Response.FromJson(@"{value: 2}")); + + var elementMock = new Mock(driverMock.Object, "dGridElementId"); + + var dataGrid = elementMock.Object.ToDataGrid(); + + Assert.That(dataGrid.ColumnCount, Is.EqualTo(2)); + } + + [Test] + public void GetDataGridRowCount() + { + var driverMock = new DriverMocked(); + + driverMock.Protected() + .Setup("Execute", "getDataGridRowCount", ItExpr.IsAny>()) + .Returns(Response.FromJson(@"{value: 2}")); + + var elementMock = new Mock(driverMock.Object, "dGridElementId"); + + var dataGrid = elementMock.Object.ToDataGrid(); + + Assert.That(dataGrid.RowCount, Is.EqualTo(2)); + } + #endregion } + } diff --git a/src/Tests/Winium.Elements.Desktop.Tests/DriverMocked.cs b/src/Tests/Winium.Elements.Desktop.Tests/DriverMocked.cs new file mode 100644 index 0000000..5186afe --- /dev/null +++ b/src/Tests/Winium.Elements.Desktop.Tests/DriverMocked.cs @@ -0,0 +1,29 @@ +namespace Winium.Elements.Desktop.Tests +{ + #region using + + using System.Collections.Generic; + + using Moq; + using Moq.Protected; + + using OpenQA.Selenium; + using OpenQA.Selenium.Remote; + + #endregion + + public class DriverMocked : Mock + { + #region Constructors and Destructors + + public DriverMocked() + : base(new Mock().Object, new Mock().Object) + { + this.Protected() + .Setup("Execute", "newSession", ItExpr.IsAny>()) + .Returns(Response.FromJson(@"{sessionId : ""AvesomeSession""}")); + } + + #endregion + } +} diff --git a/src/Tests/Winium.Elements.Desktop.Tests/Winium.Elements.Desktop.Tests.csproj b/src/Tests/Winium.Elements.Desktop.Tests/Winium.Elements.Desktop.Tests.csproj index d0bd4e4..1226ccd 100644 --- a/src/Tests/Winium.Elements.Desktop.Tests/Winium.Elements.Desktop.Tests.csproj +++ b/src/Tests/Winium.Elements.Desktop.Tests/Winium.Elements.Desktop.Tests.csproj @@ -34,21 +34,22 @@ - ..\packages\Moq.4.2.1507.0118\lib\net40\Moq.dll + ..\..\packages\Moq.4.2.1507.0118\lib\net40\Moq.dll True - ..\packages\NUnit.2.6.4\lib\nunit.framework.dll + ..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll True - ..\packages\Selenium.WebDriver.2.46.0\lib\net40\WebDriver.dll + ..\..\packages\Selenium.WebDriver.2.46.0\lib\net40\WebDriver.dll True + diff --git a/src/Winium.Elements.Desktop/DataGrid.cs b/src/Winium.Elements.Desktop/DataGrid.cs index f0353fe..0b069e8 100644 --- a/src/Winium.Elements.Desktop/DataGrid.cs +++ b/src/Winium.Elements.Desktop/DataGrid.cs @@ -15,6 +15,10 @@ public class DataGrid : DesktopElement private const string GetDataGridCell = "getDataGridCell"; + private const string GetDataGridColumnCount = "getDataGridColumnCount"; + + private const string GetDataGridRowCount = "getDataGridRowCount"; + #endregion #region Constructors and Destructors @@ -23,7 +27,15 @@ static DataGrid() { CommandInfoRepository.Instance.TryAddCommand( GetDataGridCell, - new CommandInfo("POST", "/session/{sessionId}/element/{id}/cell/{row}/{column}")); + new CommandInfo("POST", "/session/{sessionId}/element/{id}/datagrid/cell/{row}/{column}")); + + CommandInfoRepository.Instance.TryAddCommand( + GetDataGridColumnCount, + new CommandInfo("POST", "/session/{sessionId}/element/{id}/datagrid/column/count")); + + CommandInfoRepository.Instance.TryAddCommand( + GetDataGridRowCount, + new CommandInfo("POST", "/session/{sessionId}/element/{id}/datagrid/row/count")); } public DataGrid(IWebElement element) @@ -33,6 +45,32 @@ public DataGrid(IWebElement element) #endregion + #region Public Properties + + public int ColumnCount + { + get + { + var parameters = new Dictionary { { "id", this.WrappedElement.GetId() } }; + var response = this.WrappedElement.Execute(GetDataGridColumnCount, parameters); + + return int.Parse(response.Value.ToString()); + } + } + + public int RowCount + { + get + { + var parameters = new Dictionary { { "id", this.WrappedElement.GetId() } }; + var response = this.WrappedElement.Execute(GetDataGridRowCount, parameters); + + return int.Parse(response.Value.ToString()); + } + } + + #endregion + #region Public Methods and Operators public RemoteWebElement GetCell(int row, int column) From 3bd08ec0b26086aa78c5da85897aeb1b555d66f5 Mon Sep 17 00:00:00 2001 From: "t.kurnosova" Date: Mon, 3 Aug 2015 12:26:21 +0600 Subject: [PATCH 2/2] Some refactoring --- src/Winium.Elements.Desktop/DataGrid.cs | 21 ++-- src/Winium.Elements.Desktop/DesktopElement.cs | 117 ++---------------- 2 files changed, 15 insertions(+), 123 deletions(-) diff --git a/src/Winium.Elements.Desktop/DataGrid.cs b/src/Winium.Elements.Desktop/DataGrid.cs index 0b069e8..a50a7aa 100644 --- a/src/Winium.Elements.Desktop/DataGrid.cs +++ b/src/Winium.Elements.Desktop/DataGrid.cs @@ -51,8 +51,8 @@ public int ColumnCount { get { - var parameters = new Dictionary { { "id", this.WrappedElement.GetId() } }; - var response = this.WrappedElement.Execute(GetDataGridColumnCount, parameters); + var parameters = new Dictionary { { "id", this.Id } }; + var response = this.Execute(GetDataGridColumnCount, parameters); return int.Parse(response.Value.ToString()); } @@ -62,8 +62,8 @@ public int RowCount { get { - var parameters = new Dictionary { { "id", this.WrappedElement.GetId() } }; - var response = this.WrappedElement.Execute(GetDataGridRowCount, parameters); + var parameters = new Dictionary { { "id", this.Id } }; + var response = this.Execute(GetDataGridRowCount, parameters); return int.Parse(response.Value.ToString()); } @@ -75,13 +75,8 @@ public int RowCount public RemoteWebElement GetCell(int row, int column) { - var parameters = new Dictionary - { - { "id", this.WrappedElement.GetId() }, - { "row", row }, - { "column", column } - }; - var response = this.WrappedElement.Execute(GetDataGridCell, parameters); + var parameters = new Dictionary { { "id", this.Id }, { "row", row }, { "column", column } }; + var response = this.Execute(GetDataGridCell, parameters); var elementDictionary = response.Value as Dictionary; if (elementDictionary == null) @@ -89,9 +84,7 @@ public RemoteWebElement GetCell(int row, int column) return null; } - return new RemoteWebElement( - (RemoteWebDriver)this.WrappedElement.WrappedDriver, - (string)elementDictionary["ELEMENT"]); + return new RemoteWebElement((RemoteWebDriver)this.WrappedDriver, (string)elementDictionary["ELEMENT"]); } #endregion diff --git a/src/Winium.Elements.Desktop/DesktopElement.cs b/src/Winium.Elements.Desktop/DesktopElement.cs index 542b4bc..9b63785 100644 --- a/src/Winium.Elements.Desktop/DesktopElement.cs +++ b/src/Winium.Elements.Desktop/DesktopElement.cs @@ -3,135 +3,34 @@ #region using using System; - using System.Collections.ObjectModel; - using System.Drawing; using OpenQA.Selenium; using OpenQA.Selenium.Remote; #endregion - public abstract class DesktopElement : IWebElement + public abstract class DesktopElement : RemoteWebElement { - #region Fields - - protected RemoteWebElement WrappedElement; - - #endregion - #region Constructors and Destructors protected DesktopElement(IWebElement element) + : base(GetRemoteWebDriver(element), element.GetId()) { - this.WrappedElement = element as RemoteWebElement; - if (this.WrappedElement == null) - { - throw new InvalidCastException("Specified cast is not valid. Please use RemoteWebElement as parameter."); - } } #endregion - #region Public Properties - - public bool Displayed - { - get - { - return this.WrappedElement.Displayed; - } - } - - public bool Enabled - { - get - { - return this.WrappedElement.Enabled; - } - } - - public Point Location - { - get - { - return this.WrappedElement.Location; - } - } - - public bool Selected - { - get - { - return this.WrappedElement.Selected; - } - } - - public Size Size - { - get - { - return this.WrappedElement.Size; - } - } - - public string TagName - { - get - { - return this.WrappedElement.TagName; - } - } + #region Methods - public string Text + private static RemoteWebDriver GetRemoteWebDriver(IWebElement element) { - get + var remoteWebElement = element as RemoteWebElement; + if (remoteWebElement == null) { - return this.WrappedElement.Text; + throw new InvalidCastException("Specified cast is not valid. Please use RemoteWebElement as parameter."); } - } - - #endregion - - #region Public Methods and Operators - - public void Clear() - { - this.WrappedElement.Clear(); - } - - public void Click() - { - this.WrappedElement.Click(); - } - public IWebElement FindElement(By @by) - { - return this.WrappedElement.FindElement(@by); - } - - public ReadOnlyCollection FindElements(By @by) - { - return this.WrappedElement.FindElements(@by); - } - - public string GetAttribute(string attributeName) - { - return this.WrappedElement.GetAttribute(attributeName); - } - - public string GetCssValue(string propertyName) - { - return this.WrappedElement.GetCssValue(propertyName); - } - - public void SendKeys(string text) - { - this.WrappedElement.SendKeys(text); - } - - public void Submit() - { - this.WrappedElement.Submit(); + return (RemoteWebDriver)remoteWebElement.WrappedDriver; } #endregion