-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make all Built-in AxeScriptProviders public Move AxeResult population logic to it self
- Loading branch information
Showing
9 changed files
with
126 additions
and
24 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
Globant.Selenium.Axe/Globant.Selenium.Axe.Test/AxeBuilderTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using OpenQA.Selenium; | ||
using Moq; | ||
using OpenQA.Selenium.Firefox; | ||
|
||
namespace Globant.Selenium.Axe.Test | ||
{ | ||
[TestClass] | ||
public class AxeBuilderTest | ||
{ | ||
[TestMethod] | ||
[ExpectedException(typeof(ArgumentNullException))] | ||
public void ThrowWhenDriverIsNull() | ||
{ | ||
//arrange / act /assert | ||
var axeBuilder = new AxeBuilder(null); | ||
} | ||
|
||
[TestMethod] | ||
[ExpectedException(typeof(ArgumentNullException))] | ||
public void ThrowWhenOptionsAreNull() | ||
{ | ||
//arrange | ||
var driver = new Mock<IWebDriver>(); | ||
|
||
// act / assert | ||
var axeBuilder = new AxeBuilder(driver.Object, null); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldExecuteAxeScript() | ||
{ | ||
//arrange | ||
var driver = new Mock<IWebDriver>(); | ||
var jsExecutor =driver.As<IJavaScriptExecutor>(); | ||
var targetLocator = new Mock<ITargetLocator>(); | ||
|
||
driver | ||
.Setup(d => d.FindElements(It.IsAny<By>())) | ||
.Returns(new ReadOnlyCollection<IWebElement>(new List<IWebElement>(0))); | ||
|
||
driver.Setup(d => d.SwitchTo()).Returns(targetLocator.Object); | ||
targetLocator.Setup(t => t.DefaultContent()).Returns(driver.Object); | ||
|
||
jsExecutor | ||
.Setup(js => js.ExecuteAsyncScript(It.IsAny<string>(), It.IsAny<object[]>())) | ||
.Returns(new | ||
{ | ||
violations = new object[] { }, | ||
passes = new object[] { }, | ||
inapplicable = new object[] { }, | ||
incomplete = new object[] { }, | ||
timestamp = DateTimeOffset.Now, | ||
url = "www.test.com", | ||
}); | ||
|
||
var builder = new AxeBuilder(driver.Object); | ||
var result = builder.Analyze(); | ||
|
||
result.Should().NotBeNull(); | ||
result.Inapplicable.Should().NotBeNull(); | ||
result.Incomplete.Should().NotBeNull(); | ||
result.Passes.Should().NotBeNull(); | ||
result.Violations.Should().NotBeNull(); | ||
|
||
result.Inapplicable.Length.Should().Be(0); | ||
result.Incomplete.Length.Should().Be(0); | ||
result.Passes.Length.Should().Be(0); | ||
result.Violations.Length.Should().Be(0); | ||
|
||
driver.VerifyAll(); | ||
targetLocator.VerifyAll(); | ||
jsExecutor.VerifyAll(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
Globant.Selenium.Axe/Globant.Selenium.Axe.Test/packages.config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
<?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" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,33 @@ | ||
using Newtonsoft.Json.Linq; | ||
using System; | ||
using Newtonsoft.Json.Linq; | ||
using System.Collections.Generic; | ||
|
||
namespace Globant.Selenium.Axe | ||
{ | ||
public class AxeResult | ||
{ | ||
public IReadOnlyList<AxeResultItem> Violations { get; private set; } | ||
public IReadOnlyList<AxeResultItem> Passes { get; private set; } | ||
public AxeResultItem[] Violations { get; } | ||
public AxeResultItem[] Passes { get; } | ||
public AxeResultItem[] Inapplicable { get; } | ||
public AxeResultItem[] Incomplete { get; } | ||
public DateTimeOffset? Timestamp { get; private set; } | ||
public string Url { get; private set; } | ||
|
||
public AxeResult(JToken violationsToken, JToken passesToken) | ||
public AxeResult(JObject results) | ||
{ | ||
Violations = violationsToken.ToObject<List<AxeResultItem>>(); | ||
Passes = passesToken.ToObject<List<AxeResultItem>>(); | ||
JToken violationsToken = results.SelectToken("violations"); | ||
JToken passesToken = results.SelectToken("passes"); | ||
JToken inapplicableToken = results.SelectToken("inapplicable"); | ||
JToken incompleteToken = results.SelectToken("incomplete"); | ||
JToken timestampToken = results.SelectToken("timestamp"); | ||
JToken urlToken = results.SelectToken("url"); | ||
|
||
Violations = violationsToken?.ToObject<AxeResultItem[]>(); | ||
Passes = passesToken?.ToObject<AxeResultItem[]>(); | ||
Inapplicable = inapplicableToken?.ToObject<AxeResultItem[]>(); | ||
Incomplete = incompleteToken?.ToObject<AxeResultItem[]>(); | ||
Timestamp = timestampToken?.ToObject<DateTimeOffset>(); | ||
Url = urlToken?.ToObject<string>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters