Skip to content

Commit

Permalink
add support for input file type; add support for attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
gravity-api committed Feb 12, 2020
1 parent e411a18 commit eab344e
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Mock;

namespace Gravity.Drivers.Mock.Tests
{
[TestClass]
public class ElementTests
{
[TestMethod]
public void FileElement()
{
// generate element
var onElement = MockWebElement.GetElement(new MockWebDriver(), MockBy.InputFile());

// assertion
Assert.IsTrue(onElement.TagName == "INPUT");
Assert.IsTrue(onElement.GetAttribute("type") == "file");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.0.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.0.0" />
<PackageReference Include="coverlet.collector" Version="1.0.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Gravity.Drivers.Mock\Gravity.Drivers.Mock.csproj" />
</ItemGroup>

</Project>
8 changes: 7 additions & 1 deletion src/csharp/Gravity.Drivers.Mock/Gravity.Drivers.Mock.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29709.97
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gravity.Drivers.Mock", "Gravity.Drivers.Mock\Gravity.Drivers.Mock.csproj", "{A8460E8D-120B-4010-A024-32D953ABCF5A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Gravity.Drivers.Mock", "Gravity.Drivers.Mock\Gravity.Drivers.Mock.csproj", "{A8460E8D-120B-4010-A024-32D953ABCF5A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gravity.Drivers.Mock.Tests", "Gravity.Drivers.Mock.Tests\Gravity.Drivers.Mock.Tests.csproj", "{9F611A8F-1EE5-44EF-9014-F0994D414DAC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -15,6 +17,10 @@ Global
{A8460E8D-120B-4010-A024-32D953ABCF5A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A8460E8D-120B-4010-A024-32D953ABCF5A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A8460E8D-120B-4010-A024-32D953ABCF5A}.Release|Any CPU.Build.0 = Release|Any CPU
{9F611A8F-1EE5-44EF-9014-F0994D414DAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9F611A8F-1EE5-44EF-9014-F0994D414DAC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9F611A8F-1EE5-44EF-9014-F0994D414DAC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9F611A8F-1EE5-44EF-9014-F0994D414DAC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,11 @@ public static class MockBy
/// </summary>
/// <returns>A <see cref="By"/> object the driver can use to find the elements.</returns>
public static By Focused() => By.Id(MockLocators.Focused);

/// <summary>
/// Gets a mechanism to find [input type="file"] element.
/// </summary>
/// <returns>A <see cref="By"/> object the driver can use to find the elements.</returns>
public static By InputFile() => By.Id(MockLocators.File);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ public static class MockLocators
public const string SelectElementNoOptions = "select-element-no-options";
public const string Option = "option";
public const string Index = "index";
public const string File = "file";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public MockWebElement(MockWebDriver parent, string tagName, string text, bool en
Displayed = displayed;
Location = new Point(1, 1);
Size = new Size(10, 10);
Attributes = new Dictionary<string, string>();
}
#endregion

Expand Down Expand Up @@ -162,6 +163,11 @@ public MockWebElement(MockWebDriver parent, string tagName, string text, bool en
/// Gets or sets a value indicating whether or not this element is state is invalid.
/// </summary>
public bool IsInvalidState { get; set; }

/// <summary>
/// Gets or sets the collection of this <see cref="MockWebElement"/> attributes.
/// </summary>
public IDictionary<string, string> Attributes { get; set; }
#endregion

#region *** selenium ***
Expand Down Expand Up @@ -235,6 +241,10 @@ public ReadOnlyCollection<IWebElement> FindElementsByLinkText(string linkText)
/// <returns>The attribute's current value. Returns a null if the value is not set.</returns>
public string GetAttribute(string attributeName)
{
if (Attributes.ContainsKey(attributeName))
{
return Attributes[attributeName];
}
if (attributeName.Equals(MockLocators.Null, StringComparison.OrdinalIgnoreCase))
{
return null;
Expand Down Expand Up @@ -343,6 +353,25 @@ public static ReadOnlyCollection<IWebElement> GetElements(MockWebDriver parent,
return new ReadOnlyCollection<IWebElement>(elements.Where(i => i != null).ToList());
}

/// <summary>
/// Gets a positive 'INPUT' of type 'file'.
/// </summary>
/// <param name="parent">Driver in use.</param>
/// <returns>An interface through which the user controls elements on the page.</returns>
[Description(MockLocators.File)]
public static IWebElement GetFile(MockWebDriver parent)
{
// setup
var onElement = new MockWebElement(
parent, tagName: "INPUT", text: string.Empty, enabled: true, selected: false, displayed: true);

// apply attribute data
onElement.Attributes["type"] = "file";

// result
return onElement;
}

/// <summary>
/// Gets a positive 'DIV' element (displayed, enabled and selected).
/// </summary>
Expand Down

0 comments on commit eab344e

Please sign in to comment.