Skip to content
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
97 changes: 87 additions & 10 deletions Selenium.Axe/Selenium.Axe.Test/AxeResultTargetConverterTest.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
using System;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;

/* Unmerged change from project 'Selenium.Axe.Test (netcoreapp3.1)'
Before:
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
After:
using System;
using Microsoft.IO;
using System.Linq;
*/

/* Unmerged change from project 'Selenium.Axe.Test (net45)'
Before:
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
After:
using System;
using Microsoft.IO;
using System.Linq;
*/
using System.IO;
using System.Linq;

namespace Selenium.Axe.Test
{
Expand All @@ -15,8 +36,30 @@ public void CanConvertPassedAxeResultTarget()
var instance = new AxeResultTargetConverter();
var result = instance.CanConvert(typeof(AxeResultTarget));
Assert.IsTrue(result);

/* Unmerged change from project 'Selenium.Axe.Test (netcoreapp3.1)'
Before:
}

[TestMethod]
After:
}

[TestMethod]
*/

/* Unmerged change from project 'Selenium.Axe.Test (net45)'
Before:
}

[TestMethod]
After:
}

[TestMethod]
*/
}

[TestMethod]
public void ShouldReadSingleSelector()
{
Expand All @@ -26,22 +69,56 @@ public void ShouldReadSingleSelector()
};
var json = $@"{{""target"":[""{testObject.Selector}""]}}";


/* Unmerged change from project 'Selenium.Axe.Test (netcoreapp3.1)'
Before:
var axeResultTarget = DeserializeJsonAndReturnFirstTarget(json);

Assert.AreEqual(axeResultTarget?.Selector, testObject.Selector);
}

[TestMethod]
After:
var axeResultTarget = DeserializeJsonAndReturnFirstTarget(json);

Assert.AreEqual(axeResultTarget?.Selector, testObject.Selector);
}

[TestMethod]
*/

/* Unmerged change from project 'Selenium.Axe.Test (net45)'
Before:
var axeResultTarget = DeserializeJsonAndReturnFirstTarget(json);

Assert.AreEqual(axeResultTarget?.Selector, testObject.Selector);
}

[TestMethod]
After:
var axeResultTarget = DeserializeJsonAndReturnFirstTarget(json);

Assert.AreEqual(axeResultTarget?.Selector, testObject.Selector);
}

[TestMethod]
*/
var axeResultTarget = DeserializeJsonAndReturnFirstTarget(json);

Assert.AreEqual(axeResultTarget?.Selector, testObject.Selector);
}

[TestMethod]
public void ShouldReadArrayOfSelectors()
{
var testObject = new AxeResultTarget
{
Selectors = { "a", "b"}
Selectors = { "a", "b" }
};
var json = $@"{{""target"":[[""{testObject.Selectors.First()}"", ""{testObject.Selectors.Last()}""]]}}";

var axeResultTarget = DeserializeJsonAndReturnFirstTarget(json);

Assert.AreEqual(axeResultTarget?.Selectors.First(), testObject.Selectors.First());
Assert.AreEqual(axeResultTarget?.Selectors.Last(), testObject.Selectors.Last());
}
Expand All @@ -58,11 +135,11 @@ public void Write()
{
var jsonWriter = new JsonTextWriter(writer);
var instance = new AxeResultTargetConverter();
instance.WriteJson(jsonWriter, value, new JsonSerializer{ Converters = { instance }});

instance.WriteJson(jsonWriter, value, new JsonSerializer { Converters = { instance } });

var result = writer.ToString();

Assert.IsTrue(expectedResult.Equals(result));
}
}
Expand Down
6 changes: 3 additions & 3 deletions Selenium.Axe/Selenium.Axe.Test/AxeRunContextTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using FluentAssertions;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using System.Collections.Generic;

namespace Selenium.Axe.Test
{
Expand Down
4 changes: 2 additions & 2 deletions Selenium.Axe/Selenium.Axe.Test/AxeRunOptionsTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using System.Collections.Generic;
using FluentAssertions;

namespace Selenium.Axe.Test
{
Expand Down
8 changes: 4 additions & 4 deletions Selenium.Axe/Selenium.Axe.Test/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public WebDriverWait Wait

[TestCleanup]
public virtual void TearDown()
{
{
WebDriver?.Quit();
WebDriver?.Dispose();
}
Expand Down Expand Up @@ -261,7 +261,7 @@ public void ReportRespectsIframeTrue(string browser)
{
string path = CreateReportPath();
string filename = new Uri(Path.GetFullPath(IntegrationTestTargetComplexTargetsFile)).AbsoluteUri;

InitDriver(browser);
WebDriver.Navigate().GoToUrl(filename);
Wait.Until(drv => drv.FindElement(By.CssSelector(mainElementSelector)));
Expand Down Expand Up @@ -333,7 +333,7 @@ private string CreateReportPath()
string path = Uri.UnescapeDataString(uri.Path);
return Path.Combine(Path.GetDirectoryName(path), Guid.NewGuid() + ".html");
}

private void ValidateReport(string path, int violationCount, int passCount, int incompleteCount = 0, int inapplicableCount = 0)
{
string text = File.ReadAllText(path);
Expand Down Expand Up @@ -394,7 +394,7 @@ private void ValidateResultCount(string text, int count, ResultType resultType)
private void ValidateResultNotWritten(string path, ReportTypes ReportType)
{
string text = File.ReadAllText(path);

foreach (string resultType in ReportType.ToString().Split(','))
{
Assert.IsFalse(text.Contains($"{resultType}: "), $"Expected to not find '{resultType}: '");
Expand Down
6 changes: 1 addition & 5 deletions Selenium.Axe/Selenium.Axe.Test/Selenium.Axe.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,13 @@
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Selenium.Support" Version="3.141.0" />
<PackageReference Include="Selenium.Support" Version="4.0.0" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="94.0.4606.6100" />
<PackageReference Include="Selenium.WebDriver.GeckoDriver" Version="0.30.0" />
<PackageReference Include="Selenium.WebDriver" Version="3.141.0" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="5.0.0" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
<Reference Include="netstandard" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Selenium.Axe\Selenium.Axe.csproj" />
</ItemGroup>
Expand Down
16 changes: 9 additions & 7 deletions Selenium.Axe/Selenium.Axe/AxeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class AxeBuilder
private readonly AxeRunContext runContext = new AxeRunContext();
private AxeRunOptions runOptions = new AxeRunOptions();
private string outputFilePath = null;

private static readonly JsonSerializerSettings JsonSerializerSettings = new JsonSerializerSettings
{
Formatting = Formatting.None,
Expand Down Expand Up @@ -217,19 +217,21 @@ private AxeResult AnalyzeRawContext(object rawContextArg)
{
_webDriver.Inject(_AxeBuilderOptions.ScriptProvider, runOptions);

#pragma warning disable CS0618 // Intentionally falling back to publicly deprecated property for backcompat
#pragma warning disable CS0618 // Intentionally falling back to publicly deprecated property for backcompat
string rawOptionsArg = Options == "{}" ? JsonConvert.SerializeObject(runOptions, JsonSerializerSettings) : Options;
#pragma warning restore CS0618
#pragma warning restore CS0618

string scanJsContent = EmbeddedResourceProvider.ReadEmbeddedFile("scan.js");
object[] rawArgs = new[] { rawContextArg, rawOptionsArg };
var result = ((IJavaScriptExecutor)_webDriver).ExecuteAsyncScript(scanJsContent, rawArgs);

JObject jObject = JObject.FromObject(result);

if (outputFilePath != null && jObject.Type == JTokenType.Object) {
if (outputFilePath != null && jObject.Type == JTokenType.Object)
{
Encoding utf8NoBOM = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false);
using (var outputFileWriter = new StreamWriter(outputFilePath, append: false, encoding: utf8NoBOM)) {
using (var outputFileWriter = new StreamWriter(outputFilePath, append: false, encoding: utf8NoBOM))
{
jObject.WriteTo(new JsonTextWriter(outputFileWriter));
}
}
Expand Down Expand Up @@ -257,9 +259,9 @@ private static void ValidateNotNullParameter<T>(T parameterValue, string paramet

private void ThrowIfDeprecatedOptionsSet()
{
#pragma warning disable CS0618 // Intentionally checking publicly deprecated property for backcompat
#pragma warning disable CS0618 // Intentionally checking publicly deprecated property for backcompat
if (Options != "{}")
#pragma warning restore CS0618
#pragma warning restore CS0618
{
throw new InvalidOperationException("Deprecated Options api shouldn't be used with the new apis - WithOptions/WithRules/WithTags or DisableRules");
}
Expand Down
4 changes: 2 additions & 2 deletions Selenium.Axe/Selenium.Axe/AxeResultNode.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json;
using System.Collections.Generic;

namespace Selenium.Axe
{
Expand Down
6 changes: 3 additions & 3 deletions Selenium.Axe/Selenium.Axe/AxeResultRelatedNode.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json;
using System.Collections.Generic;

namespace Selenium.Axe
{
public class AxeResultRelatedNode
{
public string Html { get; set; }

[JsonProperty("target", ItemConverterType = typeof(AxeResultTargetConverter), NullValueHandling = NullValueHandling.Ignore)]
public List<AxeResultTarget> Target { get; set; }
}
Expand Down
8 changes: 4 additions & 4 deletions Selenium.Axe/Selenium.Axe/AxeResultTargetConverter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Selenium.Axe
{
Expand All @@ -23,10 +23,10 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
Selectors = serializer.Deserialize<List<string>>(reader)
};
}

throw new ArgumentException("Cannot unmarshal type Target");
}

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var val = (AxeResultTarget)value;
Expand All @@ -41,7 +41,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
serializer.Serialize(writer, val.Selectors);
return;
}

throw new ArgumentException("Cannot marshal type Target");
}
}
Expand Down
2 changes: 1 addition & 1 deletion Selenium.Axe/Selenium.Axe/AxeTestEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public class AxeTestEnvironment
{
public string UserAgent { get; set; }
public int WindowWidth { get; set; }
public int WindowWidth { get; set; }
public int WindowHeight { get; set; }
public string OrientationType { get; set; }
}
Expand Down
6 changes: 4 additions & 2 deletions Selenium.Axe/Selenium.Axe/EmbeddedResourceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ namespace Selenium.Axe
{
internal static class EmbeddedResourceProvider
{
public static string ReadEmbeddedFile(string fileName) {
public static string ReadEmbeddedFile(string fileName)
{
var assembly = typeof(EmbeddedResourceProvider).Assembly;
var resourceStream = assembly.GetManifestResourceStream($"Selenium.Axe.Resources.{fileName}");
using (var reader = new StreamReader(resourceStream, Encoding.UTF8)) {
using (var reader = new StreamReader(resourceStream, Encoding.UTF8))
{
return reader.ReadToEnd();
}
}
Expand Down
4 changes: 1 addition & 3 deletions Selenium.Axe/Selenium.Axe/HtmlReport.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using HtmlAgilityPack;
using OpenQA.Selenium;
using OpenQA.Selenium.Internal;
using System;
using System.IO;
using System.Text;
using System.Web;

Expand Down Expand Up @@ -174,7 +172,7 @@ public static void CreateAxeHtmlReport(this ISearchContext context, AxeResult re
modalImage.SetAttributeValue("id", "modalimage");
modal.AppendChild(modalImage);


doc.DocumentNode.SelectSingleNode("//script").InnerHtml = EmbeddedResourceProvider.ReadEmbeddedFile("htmlReporterElements.js");

doc.Save(destination, Encoding.UTF8);
Expand Down
2 changes: 1 addition & 1 deletion Selenium.Axe/Selenium.Axe/Selenium.Axe.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Selenium.WebDriver" Version="3.141.0" />
<PackageReference Include="Selenium.WebDriver" Version="4.0.0" />
</ItemGroup>

<!-- Running this using BeforeTagets="Restore" doesn't work if we run "dotnet restore" from solution folder.
Expand Down