public void HomePageWithComplexReport() { string reportPath = Path.Combine(LoggingConfig.GetLogDirectory(), "HomePageWithComplexReport.html"); string rawResults = Path.Combine(LoggingConfig.GetLogDirectory(), "HomePageWithComplexReport.json"); // Get to home page LoginPageModel page = new LoginPageModel(this.TestObject); page.OpenLoginPage(); page.LoginWithValidCredentials(Config.GetGeneralValue("User"), Config.GetGeneralValue("Pass")); // Setup custom rules AxeBuilder builder = new AxeBuilder(WebDriver) .Exclude("#HomePage") .WithOutputFile(rawResults) .DisableRules("landmark-one-main", "page-has-heading-one"); // Reprot WebDriver.CreateAxeHtmlReport(builder.Analyze(), reportPath); // Check if there were any violations if (!File.ReadAllText(reportPath).Contains("Violation: 0")) { TestObject.AddAssociatedFile(reportPath); TestObject.AddAssociatedFile(rawResults); Assert.Fail($"Failed violation check see {reportPath} for more details."); } }
public void ShouldPassRunOptionsWithTagConfig() { var expectedTags = new List <string> { "tag1", "tag2" }; var expectedOptions = SerializeObject(new AxeRunOptions() { RunOnly = new RunOnlyOptions { Type = "tag", Values = expectedTags }, }); SetupVerifiableAxeInjectionCall(); SetupVerifiableScanCall(null, expectedOptions); var builder = new AxeBuilder(webDriverMock.Object) .WithTags("tag1", "tag2"); var result = builder.Analyze(); VerifyAxeResult(result); webDriverMock.VerifyAll(); targetLocatorMock.VerifyAll(); jsExecutorMock.VerifyAll(); }
public void ShouldPassRunOptions() { var runOptions = new AxeRunOptions() { Iframes = true, Rules = new Dictionary <string, RuleOptions>() { { "rule1", new RuleOptions() { Enabled = false } } } }; var expectedRunOptions = SerializeObject(runOptions); SetupVerifiableAxeInjectionCall(); SetupVerifiableScanCall(null, expectedRunOptions); var builder = new AxeBuilder(webDriverMock.Object) .WithOptions(runOptions); var result = builder.Analyze(); VerifyAxeResult(result); webDriverMock.VerifyAll(); targetLocatorMock.VerifyAll(); jsExecutorMock.VerifyAll(); }
public void RunScanOnPage(string browser) { InitDriver(browser); LoadSimpleTestPage(); var timeBeforeScan = DateTime.Now; var builder = new AxeBuilder(_webDriver) .WithOptions(new AxeRunOptions() { XPath = true }) .WithTags("wcag2a", "wcag2aa") .DisableRules("color-contrast") .WithOutputFile(@"./raw-axe-results.json"); var results = builder.Analyze(); results.Violations.FirstOrDefault(v => v.Id == "color-contrast").Should().BeNull(); results.Violations.FirstOrDefault(v => !v.Tags.Contains("wcag2a") && !v.Tags.Contains("wcag2aa")).Should().BeNull(); results.Violations.Should().HaveCount(2); results.Violations.First().Nodes.First().XPath.Should().NotBeNullOrEmpty(); File.GetLastWriteTime(@"./raw-axe-results.json").Should().BeOnOrAfter(timeBeforeScan); }
public void TestAnalyzeTarget() { _webDriver.Navigate().GoToUrl(targetTestUrl); AxeBuilder axeBuilder = new AxeBuilder(_webDriver); var results = axeBuilder.Analyze(); results.Should().NotBeNull(nameof(results)); }
public void ShouldHandleIfOptionsAndContextNotSet() { SetupVerifiableAxeInjectionCall(); SetupVerifiableScanCall(null, "{}"); var builder = new AxeBuilder(webDriverMock.Object); var result = builder.Analyze(); VerifyAxeResult(result); webDriverMock.VerifyAll(); targetLocatorMock.VerifyAll(); jsExecutorMock.VerifyAll(); }
public void ReportRespectRules(string browser) { string path = CreateReportPath(); InitDriver(browser); LoadSimpleTestPage(); _wait.Until(drv => drv.FindElement(By.CssSelector(mainElementSelector))); var builder = new AxeBuilder(_webDriver).DisableRules("color-contrast"); _webDriver.CreateAxeHtmlReport(builder.Analyze(), path); ValidateReport(path, 3, 23, 0, 63); }
public void ReportRespectsIframeImplicitTrue(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))); var builder = new AxeBuilder(WebDriver); WebDriver.CreateAxeHtmlReport(builder.Analyze(), path); ValidateReport(path, 4, 43, 0, 64); }
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 { results = 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(); }
public void ShouldPassContextIfIncludeSet() { var expectedContext = SerializeObject(new AxeRunContext() { Include = new List <string[]>(new string[][] { new string[] { "#div1" } }) }); SetupVerifiableAxeInjectionCall(); SetupVerifiableScanCall(expectedContext, "{}"); var builder = new AxeBuilder(webDriverMock.Object).Include("#div1"); var result = builder.Analyze(); VerifyAxeResult(result); webDriverMock.VerifyAll(); targetLocatorMock.VerifyAll(); jsExecutorMock.VerifyAll(); }
public void ReportRespectsIframeFalse(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))); AxeRunOptions runOptions = new AxeRunOptions { Iframes = false }; var builder = new AxeBuilder(WebDriver).WithOptions(runOptions); WebDriver.CreateAxeHtmlReport(builder.Analyze(), path); ValidateReport(path, 1, 24, 1, 65); }
public void ShouldPassRuleConfig() { var expectedRules = new List <string> { "rule1", "rule2" }; var expectedOptions = SerializeObject(new AxeRunOptions() { RunOnly = new RunOnlyOptions { Type = "rule", Values = expectedRules }, Rules = new Dictionary <string, RuleOptions>() { { "excludeRule1", new RuleOptions() { Enabled = false } }, { "excludeRule2", new RuleOptions() { Enabled = false } } } }); SetupVerifiableAxeInjectionCall(); SetupVerifiableScanCall(null, expectedOptions); var builder = new AxeBuilder(webDriverMock.Object) .DisableRules("excludeRule1", "excludeRule2") .WithRules("rule1", "rule2"); var result = builder.Analyze(); VerifyAxeResult(result); webDriverMock.VerifyAll(); targetLocatorMock.VerifyAll(); jsExecutorMock.VerifyAll(); }
public void ShouldPassRunOptionsIfDeprecatedOptionsSet() { var expectedOptions = "deprecated run options"; SetupVerifiableAxeInjectionCall(); SetupVerifiableScanCall(null, expectedOptions); var builder = new AxeBuilder(webDriverMock.Object); #pragma warning disable CS0618 builder.Options = expectedOptions; #pragma warning restore CS0618 var result = builder.Analyze(); VerifyAxeResult(result); webDriverMock.VerifyAll(); targetLocatorMock.VerifyAll(); jsExecutorMock.VerifyAll(); }