硒可访问性测试
SELENIUM ACCESSIBILITY TESTING
我已经下载了最新的 rcx 文件,并在 chrome 选项中添加了扩展名。
第一步执行的很好。在第二步中,它一直执行到 driver.Navigate().GoToUrl("chrome://extensions-frame/");
下一步会抛出这个错误
"OpenQA.Selenium.NoSuchElementException
HResult=0x80131500
Message=no such element: Unable to locate element: {"method":"xpath","selector":"//a[@class='extension-commands-config']"}
(Session info: chrome=68.0.3440.106)
(Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 10.0.17134 x86_64)
Source=WebDriver
StackTrace:
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value)
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementByXPath(String xpath)
at OpenQA.Selenium.By.<>c__DisplayClass19_0.<xpath>b__0(ISearchContext context)
at OpenQA.Selenium.By.FindElement(ISearchContext context)
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by)
at Exsilio.QA.Test.DKNAccessabilityTest.AccessabilityTest() in C:\Trilok\Projects\Code\Automation Testing\RealTimeDataUpdate\QualityAssurance\Exsilio.QA.Test\DKNAccessabilityTest.cs:line 40"
我正在使用 "extension_1_0_9_0.crx" 作为当前分机。
请满足需求。
我的代码如下:
[TestInitialize]
public void Init()
{
//Open ChromeDriver with appropriate extension enabled
ChromeOptions options = new ChromeOptions();
options.AddExtension("../Extension/extension_1_0_9_0.crx");
driver = Driver.Initalize<ChromeDriver>(options);
}
[TestMethod]
public void AccessabilityTest()
{
// 2 - setup key shortcut for extension
driver.Navigate().GoToUrl("chrome://extensions-frame/");
driver.FindElement(By.XPath("//a[@class='extension-commands-config']"))
.Click();
driver.FindElement(By.XPath("//span[@class='command-shortcut-text']"))
.SendKeys(Keys.Control + "m");
driver.FindElement(By.Id("extension-commands-dismiss"))
.Click();
// 3
driver.Navigate().GoToUrl("http://www.google.pl");
// 4 - open WAVE extension
new Actions(driver).KeyDown(Keys.Control).SendKeys("m").Build().Perform();
// 5
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.ElementExists(By.ClassName("wave5icon")));
// 6
var waveTips = driver.FindElements(By.ClassName("wave5icon"));
if (waveTips.Count == 0) Assert.Fail(
"Could not locate any WAVE validations - " +
"please ensure that WAVE is installed correctly");
foreach (var waveTip in waveTips)
{
if (!waveTip.GetAttribute("alt").StartsWith("ERROR")) continue;
var fileName = String.Format("{0}{1}{2}",
"WAVE", DateTime.Now.ToString("HHmmss"), ".png");
var screenShot = ((ITakesScreenshot)driver).GetScreenshot();
//screenShot.SaveAsFile(
// Path.Combine(System.IO.Path.GetTempPath(), fileName), ImageFormat.Png);
driver.Close();
Assert.Fail(
"WAVE errors were found on the page. Please see screenshot for details");
Assert.IsTrue(false, "One or more of the functionality tests failed : WAVE errors were found on the page. Please see screenshot for details");
}
//Assert.IsTrue(isAllPass, "One or more of the functionality tests failed");
}
为了回答问题中的任何一行都可以,我使用的是带有 WAVE 扩展名的那些,这就是问题所在。
我没有尝试使用 Wave 来实现这一点。它不适用于 wave 只会给你 snapshots 错误。
从快照中,您将无法了解哪些错误或缺陷类型。
我建议不要为可访问性测试选择 WAVE 扩展。而不是使用工具“Globant.Selenium.Axe”。使用 Nuget 包管理器
安装插件
这是 Chrome 扩展的 link。
这是在文本文件中记录错误的代码:
//If file does not exists, Create a new file and log the result.
if (!File.Exists(accessiblityTestFileLocation))
{
File.Create(accessiblityTestFileLocation).Dispose();
LogResult ();
}
//If file exists, Log the result into file.
else if (File.Exists(accessiblityTestFileLocation))
{
LogResult ();
}
日志结果函数:
public void LogResult ()
{
using (StreamWriter sw = new StreamWriter(accessiblityTestFileLocation))
{
foreach (var path in appInfo.Pages)
{
var navigateUrl = new Uri(baseUrl, path.Path);
driver.Navigate().GoToUrl(navigateUrl);
driverService.driver.Manage().Window.Maximize();
AxeResult results = driver.Analyze();
//Format the results, And write them in the text file.
if (results.Passes.Length > 0)
{
//Format the text as per your need, This text will be entered into the Text file.
sw.WriteLine("\n");
sw.WriteLine(path.Title);
sw.WriteLine("===========================");
sw.WriteLine("\n");
foreach (var passCase in results.Passes)
{
sw.WriteLine("Id: " + passCase.Id);
sw.WriteLine("Description: " + passCase.Description);
sw.WriteLine("Impact: " + "Normal");
sw.WriteLine("Help: " + passCase.Help);
sw.WriteLine("HelpURL: " + passCase.HelpUrl);
foreach (var node in passCase.Nodes)
{
sw.WriteLine(node.Html);
sw.WriteLine("\n");
}
}
}
//Format the results based on the result type, And write them in the text file.
if (results.Violations.Length > 0)
{
foreach (var violation in results.Violations)
{
//Write the accessibility test for the selected Attributes provided by the Axecore.
sw.WriteLine("Id: " + violation.Id);
sw.WriteLine("Description: " + violation.Description);
sw.WriteLine("Impact: " + violation.Impact);
sw.WriteLine("Help: " + violation.Help);
sw.WriteLine("HelpURL: " + violation.HelpUrl);
foreach (var node in violation.Nodes)
{
sw.WriteLine(node.Html);
sw.WriteLine("\n");
}
}
}
}
}
}
感谢阅读,祝编码愉快!!
2 件事。他们移动了 link 以启用 Chrome 插件的快捷键。您甚至可以通过手动切换其中任何一个来看到这一点。该选项仍然可用@ chrome://extensions,但它不再位于页面底部,它是用户 id=menuButton。
我还认为,即使您启用了该选项,您在将 CTRL+m 发送到浏览器时也会遇到问题。
我已经下载了最新的 rcx 文件,并在 chrome 选项中添加了扩展名。
第一步执行的很好。在第二步中,它一直执行到 driver.Navigate().GoToUrl("chrome://extensions-frame/");
下一步会抛出这个错误
"OpenQA.Selenium.NoSuchElementException
HResult=0x80131500
Message=no such element: Unable to locate element: {"method":"xpath","selector":"//a[@class='extension-commands-config']"}
(Session info: chrome=68.0.3440.106)
(Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 10.0.17134 x86_64)
Source=WebDriver
StackTrace:
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value)
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementByXPath(String xpath)
at OpenQA.Selenium.By.<>c__DisplayClass19_0.<xpath>b__0(ISearchContext context)
at OpenQA.Selenium.By.FindElement(ISearchContext context)
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by)
at Exsilio.QA.Test.DKNAccessabilityTest.AccessabilityTest() in C:\Trilok\Projects\Code\Automation Testing\RealTimeDataUpdate\QualityAssurance\Exsilio.QA.Test\DKNAccessabilityTest.cs:line 40"
我正在使用 "extension_1_0_9_0.crx" 作为当前分机。
请满足需求。
我的代码如下:
[TestInitialize]
public void Init()
{
//Open ChromeDriver with appropriate extension enabled
ChromeOptions options = new ChromeOptions();
options.AddExtension("../Extension/extension_1_0_9_0.crx");
driver = Driver.Initalize<ChromeDriver>(options);
}
[TestMethod]
public void AccessabilityTest()
{
// 2 - setup key shortcut for extension
driver.Navigate().GoToUrl("chrome://extensions-frame/");
driver.FindElement(By.XPath("//a[@class='extension-commands-config']"))
.Click();
driver.FindElement(By.XPath("//span[@class='command-shortcut-text']"))
.SendKeys(Keys.Control + "m");
driver.FindElement(By.Id("extension-commands-dismiss"))
.Click();
// 3
driver.Navigate().GoToUrl("http://www.google.pl");
// 4 - open WAVE extension
new Actions(driver).KeyDown(Keys.Control).SendKeys("m").Build().Perform();
// 5
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.ElementExists(By.ClassName("wave5icon")));
// 6
var waveTips = driver.FindElements(By.ClassName("wave5icon"));
if (waveTips.Count == 0) Assert.Fail(
"Could not locate any WAVE validations - " +
"please ensure that WAVE is installed correctly");
foreach (var waveTip in waveTips)
{
if (!waveTip.GetAttribute("alt").StartsWith("ERROR")) continue;
var fileName = String.Format("{0}{1}{2}",
"WAVE", DateTime.Now.ToString("HHmmss"), ".png");
var screenShot = ((ITakesScreenshot)driver).GetScreenshot();
//screenShot.SaveAsFile(
// Path.Combine(System.IO.Path.GetTempPath(), fileName), ImageFormat.Png);
driver.Close();
Assert.Fail(
"WAVE errors were found on the page. Please see screenshot for details");
Assert.IsTrue(false, "One or more of the functionality tests failed : WAVE errors were found on the page. Please see screenshot for details");
}
//Assert.IsTrue(isAllPass, "One or more of the functionality tests failed");
}
为了回答问题中的任何一行都可以,我使用的是带有 WAVE 扩展名的那些,这就是问题所在。
我没有尝试使用 Wave 来实现这一点。它不适用于 wave 只会给你 snapshots 错误。
从快照中,您将无法了解哪些错误或缺陷类型。 我建议不要为可访问性测试选择 WAVE 扩展。而不是使用工具“Globant.Selenium.Axe”。使用 Nuget 包管理器
安装插件这是 Chrome 扩展的 link。
这是在文本文件中记录错误的代码:
//If file does not exists, Create a new file and log the result.
if (!File.Exists(accessiblityTestFileLocation))
{
File.Create(accessiblityTestFileLocation).Dispose();
LogResult ();
}
//If file exists, Log the result into file.
else if (File.Exists(accessiblityTestFileLocation))
{
LogResult ();
}
日志结果函数:
public void LogResult ()
{
using (StreamWriter sw = new StreamWriter(accessiblityTestFileLocation))
{
foreach (var path in appInfo.Pages)
{
var navigateUrl = new Uri(baseUrl, path.Path);
driver.Navigate().GoToUrl(navigateUrl);
driverService.driver.Manage().Window.Maximize();
AxeResult results = driver.Analyze();
//Format the results, And write them in the text file.
if (results.Passes.Length > 0)
{
//Format the text as per your need, This text will be entered into the Text file.
sw.WriteLine("\n");
sw.WriteLine(path.Title);
sw.WriteLine("===========================");
sw.WriteLine("\n");
foreach (var passCase in results.Passes)
{
sw.WriteLine("Id: " + passCase.Id);
sw.WriteLine("Description: " + passCase.Description);
sw.WriteLine("Impact: " + "Normal");
sw.WriteLine("Help: " + passCase.Help);
sw.WriteLine("HelpURL: " + passCase.HelpUrl);
foreach (var node in passCase.Nodes)
{
sw.WriteLine(node.Html);
sw.WriteLine("\n");
}
}
}
//Format the results based on the result type, And write them in the text file.
if (results.Violations.Length > 0)
{
foreach (var violation in results.Violations)
{
//Write the accessibility test for the selected Attributes provided by the Axecore.
sw.WriteLine("Id: " + violation.Id);
sw.WriteLine("Description: " + violation.Description);
sw.WriteLine("Impact: " + violation.Impact);
sw.WriteLine("Help: " + violation.Help);
sw.WriteLine("HelpURL: " + violation.HelpUrl);
foreach (var node in violation.Nodes)
{
sw.WriteLine(node.Html);
sw.WriteLine("\n");
}
}
}
}
}
}
感谢阅读,祝编码愉快!!
2 件事。他们移动了 link 以启用 Chrome 插件的快捷键。您甚至可以通过手动切换其中任何一个来看到这一点。该选项仍然可用@ chrome://extensions,但它不再位于页面底部,它是用户 id=menuButton。
我还认为,即使您启用了该选项,您在将 CTRL+m 发送到浏览器时也会遇到问题。