Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 硒可及性测试_C#_Selenium_Automation_Browser Automation - Fatal编程技术网

C# 硒可及性测试

C# 硒可及性测试,c#,selenium,automation,browser-automation,C#,Selenium,Automation,Browser Automation,我已经下载了最新的rcx文件,并在chrome选项中添加了扩展名 第一步执行得很好。在第二步中,它一直执行到driver.Navigate().gotour(“chrome://extensions-frame/"); 对于下一步,它抛出此错误 "OpenQA.Selenium.NoSuchElementException HResult=0x80131500 Message=no such element: Unable to locate element: {"method":"xpath"

我已经下载了最新的rcx文件,并在chrome选项中添加了扩展名

第一步执行得很好。在第二步中,它一直执行到driver.Navigate().gotour(“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"
“OpenQA.Selenium.NoSuchElementException
HResult=0x80131500
Message=没有这样的元素:无法找到元素:{“方法”:“xpath”,“选择器”:“//a[@class='extension-commands-config']”
(会话信息:chrome=68.0.3440.106)
(驱动程序信息:chromedriver=2.41.578737(49da6702b16031c40d63e5618de03a32ff6c197e),平台=Windows NT 10.0.17134 x8664)
Source=WebDriver
堆栈跟踪:
在OpenQA.Selenium.Remote.RemoteWebDriver.UnpackantRownerError(响应错误响应)中
在OpenQA.Selenium.Remote.RemoteWebDriver.Execute(stringdrivercommandtoexecute,Dictionary`2参数)
在OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(字符串机制,字符串值)
位于OpenQA.Selenium.Remote.RemoteWebDriver.FindElementByXPath(字符串xpath)
在OpenQA.Selenium.By.c_uuudisplayClass19_0.b_uu0(ISearchContext上下文)中
在OpenQA.Selenium.By.FindElement(ISearchContext)上
位于OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By)
在C:\Trilok\Projects\Code\Automation Testing\RealTimeDataUpdate\QualityAssurance\Exsilio.QA.Test\DKNAccessabilityTest.accessibilitytest()中的Exsilio.QA.Test.DKNAccessabilityTest.accessibilitytest()处:第40行“
我正在使用“extension\u1\u0\u9\u0.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");
    }
[测试初始化]
公共void Init()
{
//在启用相应扩展的情况下打开ChromeDriver
ChromeOptions选项=新的ChromeOptions();
options.AddExtension(“../Extension/Extension_1_0_9_0.crx”);
driver=driver.Initalize(选项);
}
[测试方法]
公共无效可访问性测试()
{
//2-设置扩展的快捷键
driver.Navigate().gotour(“chrome://extensions-frame/");
driver.FindElement(By.XPath(“//a[@class='extension-commands-config']))
。单击();
driver.FindElement(By.XPath(“//span[@class='command-shortcut-text']))
.SendKeys(key.Control+“m”);
driver.FindElement(By.Id(“扩展命令”))
。单击();
// 3
driver.Navigate().gotour(“http://www.google.pl");
//4-开放波延伸
新操作(驱动程序).KeyDown(Keys.Control).SendKeys(“m”).Build().Perform();
// 5
var wait=new WebDriverWait(驱动程序,TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.element存在(By.ClassName(“wave5icon”));
// 6
var waveTips=driver.FindElements(By.ClassName(“wave5icon”);
如果(waveTips.Count==0)Assert.Fail(
“找不到任何波形验证—+
“请确保WAVE安装正确”);
foreach(waveTips中的var waveTip)
{
如果(!waveTip.GetAttribute(“alt”).StartsWith(“ERROR”))继续;
var fileName=String.Format(“{0}{1}{2}”,
“WAVE”,DateTime.Now.ToString(“HHmmss”),“.png”);
var screenShot=((ITakesScreenshot)驱动程序).GetScreenshot();
//screenShot.SaveAsFile(
//Combine(System.IO.Path.GetTempPath(),文件名),ImageFormat.Png);
driver.Close();
断言失败(
“在页面上发现了波形错误。有关详细信息,请参阅屏幕截图”);
IsTrue(false,“一个或多个功能测试失败:在页面上发现波形错误。有关详细信息,请参阅屏幕截图”);
}
//isAllPass,“一个或多个功能测试失败”);
}

对于问题的答案,问题中的任何一行都会起作用,我使用的是WAVE extension,这就是问题所在


我没有用Wave尝试任何方法来实现这一点。它不适用于只会为错误提供快照

从快照中,您无法了解哪些错误或缺陷类型。 我建议不要在可访问性测试中使用WAVE扩展。使用工具“Globant.Selenium.Axe”来代替它。使用Nuget package manager安装插件

这是Chrome扩展的最新版本

以下是在文本文件中记录错误的代码:

 //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 ();
            }
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件事。他们已经移动了链接,为你的Chrome插件启用快捷键。您甚至可以通过手动切换它们中的任何一个来看到这一点。该选项仍然可用@chrome://extensions,但它不再位于页面底部,而是用户id=menuButton


我还认为,即使启用了该选项,将CTRL+m发送到浏览器时也会遇到问题。

我没有尝试过任何方法来使用Wave实现这一点。这对我不起作用。Wave只会为错误提供快照。从这些快照中,您无法了解哪些错误或缺陷类型。我建议不要在可访问性测试中使用WAVE扩展。而不是使用工具“Globant.Selenium.Axe”。使用Nuget软件包管理器安装插件并享受!