Trilok Pathak
Trilok Pathak

Reputation: 3111

SELENIUM ACCESSIBILITY TESTING

I have downloaded the latest rcx file and added the extension in the chrome options.

The First step is executed fine. In the second step it is executed till driver.Navigate().GoToUrl("chrome://extensions-frame/");

For the next step it throws this error

"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"

I am using the "extension_1_0_9_0.crx" as current extension.

Please do the need full.

My code is as below :

[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");
    }

Upvotes: 1

Views: 1828

Answers (2)

Trilok Pathak
Trilok Pathak

Reputation: 3111

For the answer any of the lines from the question will work, I was using those with WAVE extension and that was the problem.

I have tried no of ways to implement this with Wave. It does not work for The wave will just give you snapshots for the error.

From the snaps, you won't able to get an idea like which are the errors or type of the flaws. I suggest don't go for the WAVE extension for the Accessibility testing. Instead of that go with tool "Globant.Selenium.Axe". Install the plugin with Nuget package manager

Here is the link for the Chrome Extension.

Here is the code to log the errors in the text file:

 //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 Function :

   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");
                        }
                    }
                }
            }
        }
                }

Thanks for reading, Happy coding !!

Upvotes: 1

GIZNAJ
GIZNAJ

Reputation: 501

2 things. They have moved the link to enable the shortcut keys for your Chrome plugins. You can even see this by toggling any of them manually. The option is still available @ chrome://extensions, but it is not at the bottom of the page anyore, it is user id=menuButton.

I also think even if you got the option enabled, you will have have issues sending your CTRL+m to the browser.

Upvotes: 1

Related Questions