Skip to content

Commit ad67517

Browse files
Merge pull request #209 from TroyWalshProf/nuget/Selenium-4
Update to support Selenium 4
2 parents 2d128de + 7f611b6 commit ad67517

13 files changed

+122
-47
lines changed

Selenium.Axe/Selenium.Axe.Test/AxeResultTargetConverterTest.cs

Lines changed: 87 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,29 @@
1-
using System;
2-
using System.IO;
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using Newtonsoft.Json;
3+
4+
/* Unmerged change from project 'Selenium.Axe.Test (netcoreapp3.1)'
5+
Before:
36
using System.Linq;
47
using Microsoft.VisualStudio.TestTools.UnitTesting;
58
using Newtonsoft.Json;
9+
After:
10+
using System;
11+
using Microsoft.IO;
12+
using System.Linq;
13+
*/
14+
15+
/* Unmerged change from project 'Selenium.Axe.Test (net45)'
16+
Before:
17+
using System.Linq;
18+
using Microsoft.VisualStudio.TestTools.UnitTesting;
19+
using Newtonsoft.Json;
20+
After:
21+
using System;
22+
using Microsoft.IO;
23+
using System.Linq;
24+
*/
25+
using System.IO;
26+
using System.Linq;
627

728
namespace Selenium.Axe.Test
829
{
@@ -15,8 +36,30 @@ public void CanConvertPassedAxeResultTarget()
1536
var instance = new AxeResultTargetConverter();
1637
var result = instance.CanConvert(typeof(AxeResultTarget));
1738
Assert.IsTrue(result);
39+
40+
/* Unmerged change from project 'Selenium.Axe.Test (netcoreapp3.1)'
41+
Before:
42+
}
43+
44+
[TestMethod]
45+
After:
46+
}
47+
48+
[TestMethod]
49+
*/
50+
51+
/* Unmerged change from project 'Selenium.Axe.Test (net45)'
52+
Before:
53+
}
54+
55+
[TestMethod]
56+
After:
57+
}
58+
59+
[TestMethod]
60+
*/
1861
}
19-
62+
2063
[TestMethod]
2164
public void ShouldReadSingleSelector()
2265
{
@@ -26,22 +69,56 @@ public void ShouldReadSingleSelector()
2669
};
2770
var json = $@"{{""target"":[""{testObject.Selector}""]}}";
2871

72+
73+
/* Unmerged change from project 'Selenium.Axe.Test (netcoreapp3.1)'
74+
Before:
75+
var axeResultTarget = DeserializeJsonAndReturnFirstTarget(json);
76+
77+
Assert.AreEqual(axeResultTarget?.Selector, testObject.Selector);
78+
}
79+
80+
[TestMethod]
81+
After:
82+
var axeResultTarget = DeserializeJsonAndReturnFirstTarget(json);
83+
84+
Assert.AreEqual(axeResultTarget?.Selector, testObject.Selector);
85+
}
86+
87+
[TestMethod]
88+
*/
89+
90+
/* Unmerged change from project 'Selenium.Axe.Test (net45)'
91+
Before:
92+
var axeResultTarget = DeserializeJsonAndReturnFirstTarget(json);
93+
94+
Assert.AreEqual(axeResultTarget?.Selector, testObject.Selector);
95+
}
96+
97+
[TestMethod]
98+
After:
99+
var axeResultTarget = DeserializeJsonAndReturnFirstTarget(json);
100+
101+
Assert.AreEqual(axeResultTarget?.Selector, testObject.Selector);
102+
}
103+
104+
[TestMethod]
105+
*/
29106
var axeResultTarget = DeserializeJsonAndReturnFirstTarget(json);
30-
107+
31108
Assert.AreEqual(axeResultTarget?.Selector, testObject.Selector);
32109
}
33-
110+
34111
[TestMethod]
35112
public void ShouldReadArrayOfSelectors()
36113
{
37114
var testObject = new AxeResultTarget
38115
{
39-
Selectors = { "a", "b"}
116+
Selectors = { "a", "b" }
40117
};
41118
var json = $@"{{""target"":[[""{testObject.Selectors.First()}"", ""{testObject.Selectors.Last()}""]]}}";
42119

43120
var axeResultTarget = DeserializeJsonAndReturnFirstTarget(json);
44-
121+
45122
Assert.AreEqual(axeResultTarget?.Selectors.First(), testObject.Selectors.First());
46123
Assert.AreEqual(axeResultTarget?.Selectors.Last(), testObject.Selectors.Last());
47124
}
@@ -58,11 +135,11 @@ public void Write()
58135
{
59136
var jsonWriter = new JsonTextWriter(writer);
60137
var instance = new AxeResultTargetConverter();
61-
62-
instance.WriteJson(jsonWriter, value, new JsonSerializer{ Converters = { instance }});
138+
139+
instance.WriteJson(jsonWriter, value, new JsonSerializer { Converters = { instance } });
63140

64141
var result = writer.ToString();
65-
142+
66143
Assert.IsTrue(expectedResult.Equals(result));
67144
}
68145
}

Selenium.Axe/Selenium.Axe.Test/AxeRunContextTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using Microsoft.VisualStudio.TestTools.UnitTesting;
2-
using System.Collections.Generic;
3-
using FluentAssertions;
1+
using FluentAssertions;
2+
using Microsoft.VisualStudio.TestTools.UnitTesting;
43
using Newtonsoft.Json;
4+
using System.Collections.Generic;
55

66
namespace Selenium.Axe.Test
77
{

Selenium.Axe/Selenium.Axe.Test/AxeRunOptionsTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using Microsoft.VisualStudio.TestTools.UnitTesting;
1+
using FluentAssertions;
2+
using Microsoft.VisualStudio.TestTools.UnitTesting;
23
using Newtonsoft.Json;
34
using System.Collections.Generic;
4-
using FluentAssertions;
55

66
namespace Selenium.Axe.Test
77
{

Selenium.Axe/Selenium.Axe.Test/IntegrationTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public WebDriverWait Wait
6464

6565
[TestCleanup]
6666
public virtual void TearDown()
67-
{
67+
{
6868
WebDriver?.Quit();
6969
WebDriver?.Dispose();
7070
}
@@ -261,7 +261,7 @@ public void ReportRespectsIframeTrue(string browser)
261261
{
262262
string path = CreateReportPath();
263263
string filename = new Uri(Path.GetFullPath(IntegrationTestTargetComplexTargetsFile)).AbsoluteUri;
264-
264+
265265
InitDriver(browser);
266266
WebDriver.Navigate().GoToUrl(filename);
267267
Wait.Until(drv => drv.FindElement(By.CssSelector(mainElementSelector)));
@@ -333,7 +333,7 @@ private string CreateReportPath()
333333
string path = Uri.UnescapeDataString(uri.Path);
334334
return Path.Combine(Path.GetDirectoryName(path), Guid.NewGuid() + ".html");
335335
}
336-
336+
337337
private void ValidateReport(string path, int violationCount, int passCount, int incompleteCount = 0, int inapplicableCount = 0)
338338
{
339339
string text = File.ReadAllText(path);
@@ -394,7 +394,7 @@ private void ValidateResultCount(string text, int count, ResultType resultType)
394394
private void ValidateResultNotWritten(string path, ReportTypes ReportType)
395395
{
396396
string text = File.ReadAllText(path);
397-
397+
398398
foreach (string resultType in ReportType.ToString().Split(','))
399399
{
400400
Assert.IsFalse(text.Contains($"{resultType}: "), $"Expected to not find '{resultType}: '");

Selenium.Axe/Selenium.Axe.Test/Selenium.Axe.Test.csproj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,13 @@
3232
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />
3333
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
3434
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
35-
<PackageReference Include="Selenium.Support" Version="3.141.0" />
35+
<PackageReference Include="Selenium.Support" Version="4.0.0" />
3636
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="94.0.4606.6100" />
3737
<PackageReference Include="Selenium.WebDriver.GeckoDriver" Version="0.30.0" />
38-
<PackageReference Include="Selenium.WebDriver" Version="3.141.0" />
3938
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="5.0.0" />
4039
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
4140
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
4241
</ItemGroup>
43-
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
44-
<Reference Include="netstandard" />
45-
</ItemGroup>
4642
<ItemGroup>
4743
<ProjectReference Include="..\Selenium.Axe\Selenium.Axe.csproj" />
4844
</ItemGroup>

Selenium.Axe/Selenium.Axe/AxeBuilder.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class AxeBuilder
2020
private readonly AxeRunContext runContext = new AxeRunContext();
2121
private AxeRunOptions runOptions = new AxeRunOptions();
2222
private string outputFilePath = null;
23-
23+
2424
private static readonly JsonSerializerSettings JsonSerializerSettings = new JsonSerializerSettings
2525
{
2626
Formatting = Formatting.None,
@@ -217,19 +217,21 @@ private AxeResult AnalyzeRawContext(object rawContextArg)
217217
{
218218
_webDriver.Inject(_AxeBuilderOptions.ScriptProvider, runOptions);
219219

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

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

228228
JObject jObject = JObject.FromObject(result);
229229

230-
if (outputFilePath != null && jObject.Type == JTokenType.Object) {
230+
if (outputFilePath != null && jObject.Type == JTokenType.Object)
231+
{
231232
Encoding utf8NoBOM = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false);
232-
using (var outputFileWriter = new StreamWriter(outputFilePath, append: false, encoding: utf8NoBOM)) {
233+
using (var outputFileWriter = new StreamWriter(outputFilePath, append: false, encoding: utf8NoBOM))
234+
{
233235
jObject.WriteTo(new JsonTextWriter(outputFileWriter));
234236
}
235237
}
@@ -257,9 +259,9 @@ private static void ValidateNotNullParameter<T>(T parameterValue, string paramet
257259

258260
private void ThrowIfDeprecatedOptionsSet()
259261
{
260-
#pragma warning disable CS0618 // Intentionally checking publicly deprecated property for backcompat
262+
#pragma warning disable CS0618 // Intentionally checking publicly deprecated property for backcompat
261263
if (Options != "{}")
262-
#pragma warning restore CS0618
264+
#pragma warning restore CS0618
263265
{
264266
throw new InvalidOperationException("Deprecated Options api shouldn't be used with the new apis - WithOptions/WithRules/WithTags or DisableRules");
265267
}

Selenium.Axe/Selenium.Axe/AxeResultNode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using System.Collections.Generic;
2-
using Newtonsoft.Json;
1+
using Newtonsoft.Json;
2+
using System.Collections.Generic;
33

44
namespace Selenium.Axe
55
{

Selenium.Axe/Selenium.Axe/AxeResultRelatedNode.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
using System.Collections.Generic;
2-
using Newtonsoft.Json;
1+
using Newtonsoft.Json;
2+
using System.Collections.Generic;
33

44
namespace Selenium.Axe
55
{
66
public class AxeResultRelatedNode
77
{
88
public string Html { get; set; }
9-
9+
1010
[JsonProperty("target", ItemConverterType = typeof(AxeResultTargetConverter), NullValueHandling = NullValueHandling.Ignore)]
1111
public List<AxeResultTarget> Target { get; set; }
1212
}

Selenium.Axe/Selenium.Axe/AxeResultTargetConverter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
using Newtonsoft.Json;
12
using System;
23
using System.Collections.Generic;
3-
using Newtonsoft.Json;
44

55
namespace Selenium.Axe
66
{
@@ -23,10 +23,10 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
2323
Selectors = serializer.Deserialize<List<string>>(reader)
2424
};
2525
}
26-
26+
2727
throw new ArgumentException("Cannot unmarshal type Target");
2828
}
29-
29+
3030
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
3131
{
3232
var val = (AxeResultTarget)value;
@@ -41,7 +41,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
4141
serializer.Serialize(writer, val.Selectors);
4242
return;
4343
}
44-
44+
4545
throw new ArgumentException("Cannot marshal type Target");
4646
}
4747
}

Selenium.Axe/Selenium.Axe/AxeTestEnvironment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
public class AxeTestEnvironment
44
{
55
public string UserAgent { get; set; }
6-
public int WindowWidth { get; set; }
6+
public int WindowWidth { get; set; }
77
public int WindowHeight { get; set; }
88
public string OrientationType { get; set; }
99
}

0 commit comments

Comments
 (0)