Skip to content

update solution nugets; update axe-core js; update tests; #7

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void ShouldExecuteAxeScript()
targetLocator.Setup(t => t.DefaultContent()).Returns(driver.Object);

jsExecutor
.Setup(js => js.ExecuteAsyncScript(It.IsAny<string>(), It.IsAny<object[]>()))
.Setup(js => js.ExecuteScript(It.IsAny<string>(), It.IsAny<object[]>()))
.Returns(new
{
violations = new object[] { },
Expand All @@ -62,6 +62,7 @@ public void ShouldExecuteAxeScript()
});

var builder = new AxeBuilder(driver.Object);
builder.WaitForResult = false;
var result = builder.Analyze();

result.Should().NotBeNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,33 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\packages\Castle.Core.4.2.1\lib\net45\Castle.Core.dll</HintPath>
<HintPath>..\packages\Castle.Core.4.3.1\lib\net45\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="FluentAssertions, Version=4.19.2.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
<HintPath>..\packages\FluentAssertions.4.19.2\lib\net45\FluentAssertions.dll</HintPath>
<Private>True</Private>
<Reference Include="FluentAssertions, Version=5.4.1.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
<HintPath>..\packages\FluentAssertions.5.4.1\lib\net45\FluentAssertions.dll</HintPath>
</Reference>
<Reference Include="FluentAssertions.Core, Version=4.19.2.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
<HintPath>..\packages\FluentAssertions.4.19.2\lib\net45\FluentAssertions.Core.dll</HintPath>
<Private>True</Private>
<Reference Include="Moq, Version=4.9.0.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.9.0\lib\net45\Moq.dll</HintPath>
</Reference>
<Reference Include="Moq, Version=4.7.142.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.7.142\lib\net45\Moq.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Drawing" />
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.1\lib\netstandard1.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.1\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="WebDriver, Version=2.53.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Selenium.WebDriver.2.53.0\lib\net40\WebDriver.dll</HintPath>
<Private>True</Private>
<Reference Include="WebDriver, Version=3.14.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Selenium.WebDriver.3.14.0\lib\net45\WebDriver.dll</HintPath>
</Reference>
</ItemGroup>
<Choose>
Expand All @@ -78,7 +80,6 @@
</Choose>
<ItemGroup>
<Compile Include="AxeBuilderTest.cs" />
<Compile Include="IntegrationTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand All @@ -88,9 +89,8 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
Expand Down
15 changes: 15 additions & 0 deletions Globant.Selenium.Axe/Globant.Selenium.Axe.Test/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
13 changes: 8 additions & 5 deletions Globant.Selenium.Axe/Globant.Selenium.Axe.Test/packages.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Castle.Core" version="4.2.1" targetFramework="net45" />
<package id="FluentAssertions" version="4.19.2" targetFramework="net45" />
<package id="Moq" version="4.7.142" targetFramework="net45" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" />
<package id="Selenium.WebDriver" version="2.53.0" targetFramework="net45" />
<package id="Castle.Core" version="4.3.1" targetFramework="net45" />
<package id="FluentAssertions" version="5.4.1" targetFramework="net45" />
<package id="Moq" version="4.9.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net45" />
<package id="Selenium.WebDriver" version="3.14.0" targetFramework="net45" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.1" targetFramework="net45" />
<package id="System.Threading.Tasks.Extensions" version="4.5.1" targetFramework="net45" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net45" />
</packages>
67 changes: 46 additions & 21 deletions Globant.Selenium.Axe/Globant.Selenium.Axe/AxeBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Newtonsoft.Json.Linq;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using System;
using System.Net;

namespace Globant.Selenium.Axe
{
Expand All @@ -14,15 +14,15 @@ public class AxeBuilder
private readonly IWebDriver _webDriver;
private readonly IncludeExcludeManager _includeExcludeManager = new IncludeExcludeManager();

private static readonly AxeBuilderOptions DefaultOptions = new AxeBuilderOptions {ScriptProvider = new EmbeddedResourceAxeProvider()};

public string Options { get; set; } = "null";
private static readonly AxeBuilderOptions DefaultOptions = new AxeBuilderOptions { ScriptProvider = new EmbeddedResourceAxeProvider() };

public string Options { get; set; } = "null";
public bool WaitForResult { get; set; } = true;
/// <summary>
/// Initialize an instance of <see cref="AxeBuilder"/>
/// </summary>
/// <param name="webDriver">Selenium driver to use</param>
public AxeBuilder(IWebDriver webDriver): this(webDriver, DefaultOptions)
public AxeBuilder(IWebDriver webDriver) : this(webDriver, DefaultOptions)
{
}

Expand All @@ -33,13 +33,12 @@ public AxeBuilder(IWebDriver webDriver): this(webDriver, DefaultOptions)
/// <param name="options">Builder options</param>
public AxeBuilder(IWebDriver webDriver, AxeBuilderOptions options)
{
if (webDriver == null)
throw new ArgumentNullException(nameof(webDriver));

if (options == null)
{
throw new ArgumentNullException(nameof(options));
}

_webDriver = webDriver;
_webDriver = webDriver ?? throw new ArgumentNullException(nameof(webDriver));
_webDriver.Inject(options.ScriptProvider);
}

Expand All @@ -50,9 +49,17 @@ public AxeBuilder(IWebDriver webDriver, AxeBuilderOptions options)
/// <param name="args"></param>
private AxeResult Execute(string command, params object[] args)
{
object response = ((IJavaScriptExecutor)_webDriver).ExecuteAsyncScript(command, args);
((IJavaScriptExecutor)_webDriver).ExecuteScript(command, args);

if (WaitForResult)
{
var wait = new WebDriverWait(_webDriver, TimeSpan.FromSeconds(60));
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementExists(By.Id("accessibilityResultReady")));
}

object response = ((IJavaScriptExecutor)_webDriver).ExecuteScript("return window.promiseResultAccessibility;", args);
var jObject = JObject.FromObject(response);
return new AxeResult(jObject);
return new AxeResult(jObject);
}

/// <summary>
Expand All @@ -62,7 +69,7 @@ private AxeResult Execute(string command, params object[] args)
/// <returns></returns>
public AxeBuilder Include(params string[] selectors)
{
_includeExcludeManager.Include(selectors);
_includeExcludeManager.IncludeToAnalyzer(selectors);
return this;
}

Expand All @@ -74,7 +81,7 @@ public AxeBuilder Include(params string[] selectors)
/// <returns></returns>
public AxeBuilder Exclude(params string[] selectors)
{
_includeExcludeManager.Exclude(selectors);
_includeExcludeManager.ExcludeToAnalyzer(selectors);
return this;
}

Expand All @@ -85,8 +92,20 @@ public AxeBuilder Exclude(params string[] selectors)
/// <returns>An aXe results document</returns>
public AxeResult Analyze(IWebElement context)
{
string command = string.Format("axe.a11yCheck(arguments[0], {0}, arguments[arguments.length - 1]);", Options);
return Execute(command, context);
var id = context.GetAttribute("id");
if (string.IsNullOrEmpty(id)){
throw new ArgumentException("WebElement must have a valid id");
}

var commandParams = Options == "null" ? $"document.getElementById('{id}')" : $"document.getElementById('{id}'), {Options}";
var fullCommand = @"window.promiseResultAccessibility = null;
axe.run([params]).then(function (result) {
promiseResultAccessibility = result;
$(document).add('div').attr('id','accessibilityResultReady');
});
";
fullCommand = fullCommand.Replace("[params]", commandParams);
return Execute(fullCommand, context);
}

/// <summary>
Expand All @@ -95,23 +114,29 @@ public AxeResult Analyze(IWebElement context)
/// <returns>An aXe results document</returns>
public AxeResult Analyze()
{
string command;
string commandParams;

if (_includeExcludeManager.HasMoreThanOneSelectorsToIncludeOrSomeToExclude())
{
command = $"axe.a11yCheck({_includeExcludeManager.ToJson()}, {Options}, arguments[arguments.length - 1]);";
commandParams = Options == "null" ? $"{ _includeExcludeManager.ToJson()}" : $"{ _includeExcludeManager.ToJson()}, {Options}";
}
else if (_includeExcludeManager.HasOneItemToInclude())
{
string itemToInclude = _includeExcludeManager.GetFirstItemToInclude().Replace("'", "");
command = $"axe.a11yCheck('{itemToInclude}', {Options}, arguments[arguments.length - 1]);";
commandParams = Options == "null" ? $"'{itemToInclude}'" : $"'{itemToInclude}', {Options}";
}
else
{
command = $"axe.a11yCheck(document, {Options}, arguments[arguments.length - 1]);";
commandParams = Options == "null" ? $"document" : $"document, {Options}";
}

return Execute(command);
var fullCommand = @"window.promiseResultAccessibility = null;
axe.run([params]).then(function (result) {
promiseResultAccessibility = result;
$(document).add('div').attr('id','accessibilityResultReady');
});
";
fullCommand = fullCommand.Replace("[params]", commandParams);
return Execute(fullCommand);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="SeleniumExtras.WaitHelpers, Version=3.11.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\DotNetSeleniumExtras.WaitHelpers.3.11.0\lib\net45\SeleniumExtras.WaitHelpers.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -44,9 +46,8 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="WebDriver, Version=2.53.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Selenium.WebDriver.2.53.0\lib\net40\WebDriver.dll</HintPath>
<Private>True</Private>
<Reference Include="WebDriver, Version=3.14.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Selenium.WebDriver.3.14.0\lib\net45\WebDriver.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand All @@ -72,18 +73,19 @@
<Compile Include="WebDriverExtensions.cs" />
<Compile Include="WebDriverInjectorExtensions.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="Resources\axe.min.js" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\axe.js" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
30 changes: 15 additions & 15 deletions Globant.Selenium.Axe/Globant.Selenium.Axe/IncludeExcludeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,31 @@ public class IncludeExcludeManager
NullValueHandling = NullValueHandling.Ignore
};

private List<string[]> _includeList;
private List<string[]> _excludeList;
public List<string[]> Include { get; set; }
public List<string[]> Exclude { get; set; }

/// <summary>
/// Include the given selectors, i.e "#foo", "ul.bar .target", "div"
/// </summary>
/// <param name="selectors">Selectors to include</param>
public void Include(params string[] selectors)
public void IncludeToAnalyzer(params string[] selectors)
{
ValidateParameters(selectors);
if (_includeList == null)
_includeList = new List<string[]>();
_includeList.Add(selectors);
if (Include == null)
Include = new List<string[]>();
Include.Add(selectors);
}

/// <summary>
/// Include the given selectors, i.e "frame", "div.foo"
/// </summary>
/// <param name="selectors">Selectors to exclude</param>
public void Exclude(params string[] selectors)
public void ExcludeToAnalyzer(params string[] selectors)
{
ValidateParameters(selectors);
if (_excludeList == null)
_excludeList = new List<string[]>();
_excludeList.Add(selectors);
if (Exclude == null)
Exclude = new List<string[]>();
Exclude.Add(selectors);
}

/// <summary>
Expand All @@ -52,8 +52,8 @@ public void Exclude(params string[] selectors)
/// <returns>True or False</returns>
public bool HasMoreThanOneSelectorsToIncludeOrSomeToExclude()
{
bool hasMoreThanOneSelectorsToInclude = _includeList != null && _includeList.Count > 1;
bool hasSelectorsToExclude = _excludeList != null && _excludeList.Count > 0;
bool hasMoreThanOneSelectorsToInclude = Include != null && Include.Count > 1;
bool hasSelectorsToExclude = Exclude != null && Exclude.Count > 0;

return hasMoreThanOneSelectorsToInclude || hasSelectorsToExclude;
}
Expand All @@ -62,18 +62,18 @@ public bool HasMoreThanOneSelectorsToIncludeOrSomeToExclude()
/// Indicate we have one entry on the include list
/// </summary>
/// <returns>True or False</returns>
public bool HasOneItemToInclude() => _includeList != null && _includeList.Count == 1;
public bool HasOneItemToInclude() => Include != null && Include.Count == 1;

/// <summary>
/// Get first selector of the first entry on include list
/// </summary>
/// <returns></returns>
public string GetFirstItemToInclude()
{
if (_includeList == null || _includeList.Count == 0)
if (Include == null || Include.Count == 0)
throw new InvalidOperationException("You must add at least one selector to include");

return _includeList.First().First();
return Include.First().First();
}

/// <summary>
Expand Down
Loading