Accessibility Testing
  • 01 May 2023
  • 3 Minutes to read
  • Dark
    Light

Accessibility Testing

  • Dark
    Light

Article summary

What is Accessibility Testing?

Testing for accessibility makes sure that websites are made to be usable by all users, regardless of any impairments or disabilities they may have. It makes it possible for people with impairments to browse and navigate this website without being limited by issues.

Why do you need Accessibility Testing?

Accessibility testing not only makes your websites usable by people with disabilities, but it also helps your products comply with regulations like the Web Content Accessibility Guidelines (WCAG) and the Americans with Disabilities Act (ADA) in the US.

Accessibility testing on pCloudy mobile and browser cloud using the axe-core library

Website accessibility testing is an essential part of making sure that all people can access your site. It helps ensure that your site meets the requirements set by the WCAG (as supported by the axe-core library). Axe DevTools enables developers to rapidly fix accessibility issues using built-in references and solution patterns without requiring deep knowledge of accessibility standards. When accessibility issues are found on a page, users are provided with an issue description, location, source, level of impact.
This document will discuss about how you can perform accessibility testing on pCloudy using axe-core library.

Pre-requisites

Before you can integrate your tests with pCloudy and generate reports using the axe-core library, ensure that the following pre-requisites are completed
• Download the axe.min.js file to your local machine.
• Get the maven dependency for axe-selenium.

Accessibility testing on pCloudy browser cloud using Selenium and axe-core library

  1. Create a Maven project and add the axe.min.js under src/test/resources.
    image.png

  2. Add the axe-selenium maven dependency to pom.xml.

image.png

  1. Now add the scripts as show below and execute the script.
package AxeTest;
import java.io.IOException;
import java.net.URL;
import org.json.JSONArray;
import org.json.JSONObject;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.deque.axe.AXE;



public class PcloudyAxe{
	WebDriver driver;
	DesiredCapabilities capabilities ;
	private static final URL scriptUrl = PcloudyAxe.class.getResource("/axe.min.js") ;
	
	@BeforeMethod
	public void prepareTest() throws IOException, InterruptedException {

		capabilities =  DesiredCapabilities.chrome();
		capabilities.setCapability("os", "Windows");
		capabilities.setCapability("osVersion", "10");
		capabilities.setCapability("browserVersion","110");
		capabilities.setCapability("clientName", "rakesh.kumar@sstsinc.com");
		capabilities.setCapability("apiKey", "YourAPIkey");
		capabilities.setCapability("email", "rakesh.kumar@sstsinc.com");
    	driver = new RemoteWebDriver(new URL("https://prod-browsercloud-in.pcloudy.com/seleniumcloud/wd/hub"), capabilities);
		driver.get("http://www.pcloudy.com");
	}	
	@Test
	public void PcloudyAxeTest1() {
		
		JSONObject responseJson = new AXE.Builder(driver, scriptUrl).analyze();
		JSONArray violations = responseJson.getJSONArray("violations");	
		if(violations.length()==0) {
			System.out.println("no errors");
		}
		else {
			AXE.writeResults("Pcloudy", responseJson);//output file under test-output
			Assert.assertTrue(false, AXE.report(violations));
			
		}
	}
	@AfterMethod
	public void afterMethod() throws InterruptedException{

		driver.quit();
       }}
  1. Now the violations will be listed down on the console for the mentioned website in the script.

Accessibility testing on pCloudy Mobile browsers using Selenium and axe-core library

  1. Create a Maven project and add the axe.min.js under src/test/resources.
    image.png

  2. Add the axe-selenium maven dependency to pom.xml.
    image.png

  3. Now add the scripts as show below and execute the script.

package mobile;

import java.io.IOException;
import java.net.URL;
import org.json.JSONArray;
import org.json.JSONObject;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.deque.axe.AXE;
import io.appium.java_client.android.AndroidDriver;

public class PcloudyAxeMobile {
	WebDriver driver;
	DesiredCapabilities capabilities ;
	private static final URL scriptUrl = PcloudyAxeMobile.class.getResource("/axe.min.js") ;
	
	@BeforeMethod
	public void prepareTest() throws IOException, InterruptedException {

		DesiredCapabilities capabilities = new DesiredCapabilities();
		capabilities.setCapability("pCloudy_Username", "rakesh.kumar@sstsinc.com");
		capabilities.setCapability("pCloudy_ApiKey", "jhc23mj4rmx22hggwpr9xmsg");
		capabilities.setCapability("pCloudy_DurationInMinutes", 10);
		capabilities.setCapability("newCommandTimeout", 600);
		capabilities.setCapability("launchTimeout", 90000);
		capabilities.setCapability("pCloudy_DeviceVersion", "9.0.0");
		capabilities.setCapability("pCloudy_DeviceFullName", "GOOGLE_PixelXL_Android_9.0.0_10318");
		capabilities.setCapability("automationName", "uiautomator2");
		capabilities.setCapability("pCloudy_EnableVideo", "true");
		capabilities.setCapability("pCloudy_EnablePerformanceData", "true");
		capabilities.setCapability("pCloudy_EnableDeviceLogs", "true");
		capabilities.setBrowserName("Chrome");
		driver = new AndroidDriver (new URL("https://ind-west.pcloudy.com/appiumcloud/wd/hub"), capabilities);
		driver.get("http://www.pcloudy.com");
	}	
	@Test
	public void PcloudyAxeTest1() {
		
		JSONObject responseJson = new AXE.Builder(driver, scriptUrl).analyze();
		JSONArray violations = responseJson.getJSONArray("violations");	
		if(violations.length()==0) {
			System.out.println("no errors");
		}
		else {
			AXE.writeResults("Pcloudy", responseJson);//output file 
			Assert.assertTrue(false, AXE.report(violations));
			
			
		}
	}
	@AfterMethod
	public void afterMethod() throws InterruptedException{

		driver.quit();
}}

Note: You can create the capabilities using capability configurator on pCloudy portal.

  1. Now the violations will be listed down on the console for the mentioned website in the script and a “.json” (Example: Pcloudy.json from above script) file will be created under “test-output” with the reports for the session.

image.png

All the objects that’s been returned in report has some properties that’s available in the axe-core API Documentation.


Was this article helpful?