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 DataGrid props ColumnCount and RowCount #1

Merged
merged 2 commits into from
Aug 3, 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
41 changes: 34 additions & 7 deletions src/Tests/Winium.Elements.Desktop.Tests/DataGridTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,12 @@ public class DataGridTests
[Test]
public void GetDataGridCell()
{
var driverMock = new Mock<RemoteWebDriver>(
new Mock<ICommandExecutor>().Object,
new Mock<ICapabilities>().Object);
var driverMock = new DriverMocked();

driverMock.Protected()
.Setup<Response>("Execute", "getDataGridCell", ItExpr.IsAny<Dictionary<string, object>>())
.Returns(Response.FromJson(@"{value: {ELEMENT: ""dGridCellElementId""}}"));

driverMock.Protected()
.Setup<Response>("Execute", "newSession", ItExpr.IsAny<Dictionary<string, object>>())
.Returns(Response.FromJson(@"{sessionId : ""AvesomeSession""}"));

var elementMock = new Mock<RemoteWebElement>(driverMock.Object, "dGridElementId");

var dataGrid = elementMock.Object.ToDataGrid();
Expand All @@ -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<Response>("Execute", "getDataGridColumnCount", ItExpr.IsAny<Dictionary<string, object>>())
.Returns(Response.FromJson(@"{value: 2}"));

var elementMock = new Mock<RemoteWebElement>(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<Response>("Execute", "getDataGridRowCount", ItExpr.IsAny<Dictionary<string, object>>())
.Returns(Response.FromJson(@"{value: 2}"));

var elementMock = new Mock<RemoteWebElement>(driverMock.Object, "dGridElementId");

var dataGrid = elementMock.Object.ToDataGrid();

Assert.That(dataGrid.RowCount, Is.EqualTo(2));
}

#endregion
}

}
29 changes: 29 additions & 0 deletions src/Tests/Winium.Elements.Desktop.Tests/DriverMocked.cs
Original file line number Diff line number Diff line change
@@ -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<RemoteWebDriver>
{
#region Constructors and Destructors

public DriverMocked()
: base(new Mock<ICommandExecutor>().Object, new Mock<ICapabilities>().Object)
{
this.Protected()
.Setup<Response>("Execute", "newSession", ItExpr.IsAny<Dictionary<string, object>>())
.Returns(Response.FromJson(@"{sessionId : ""AvesomeSession""}"));
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,22 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Moq, Version=4.2.1507.118, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.2.1507.0118\lib\net40\Moq.dll</HintPath>
<HintPath>..\..\packages\Moq.4.2.1507.0118\lib\net40\Moq.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
<HintPath>..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="WebDriver, Version=2.46.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Selenium.WebDriver.2.46.0\lib\net40\WebDriver.dll</HintPath>
<HintPath>..\..\packages\Selenium.WebDriver.2.46.0\lib\net40\WebDriver.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="DriverMocked.cs" />
<Compile Include="DataGridTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
53 changes: 42 additions & 11 deletions src/Winium.Elements.Desktop/DataGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -33,27 +45,46 @@ public DataGrid(IWebElement element)

#endregion

#region Public Properties

public int ColumnCount
{
get
{
var parameters = new Dictionary<string, object> { { "id", this.Id } };
var response = this.Execute(GetDataGridColumnCount, parameters);

return int.Parse(response.Value.ToString());
}
}

public int RowCount
{
get
{
var parameters = new Dictionary<string, object> { { "id", this.Id } };
var response = this.Execute(GetDataGridRowCount, parameters);

return int.Parse(response.Value.ToString());
}
}

#endregion

#region Public Methods and Operators

public RemoteWebElement GetCell(int row, int column)
{
var parameters = new Dictionary<string, object>
{
{ "id", this.WrappedElement.GetId() },
{ "row", row },
{ "column", column }
};
var response = this.WrappedElement.Execute(GetDataGridCell, parameters);
var parameters = new Dictionary<string, object> { { "id", this.Id }, { "row", row }, { "column", column } };
var response = this.Execute(GetDataGridCell, parameters);

var elementDictionary = response.Value as Dictionary<string, object>;
if (elementDictionary == null)
{
return null;
}

return new RemoteWebElement(
(RemoteWebDriver)this.WrappedElement.WrappedDriver,
(string)elementDictionary["ELEMENT"]);
return new RemoteWebElement((RemoteWebDriver)this.WrappedDriver, (string)elementDictionary["ELEMENT"]);
}

#endregion
Expand Down
117 changes: 8 additions & 109 deletions src/Winium.Elements.Desktop/DesktopElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IWebElement> 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
Expand Down