Learn how to enable high contrast mode on browsers to perform accessibility testing of your websites in BrowserStack Automate.
Accessibility testing ensures that your website is accessible to all kinds of users. Using the BrowserStack high contrast mode capability, you can now conduct Accessibility testing of your websites on BrowserStack Automate. Using our custom capability you will be able to test whether your website renders properly in the high contrast mode of the browser.
platforms:-os: Windows
osVersion:10browserName: Firefox
browserVersion: latest
highContrast:truebuildName: BStack Build Number 1
projectName: BStack Sample Test
BrowserStack SDK is a plug-n-play solution that takes care of all the integration steps for you. Using the BrowserStack SDK is the recommended integration method for your project. To know more, visit the SDK core concepts page.
// Sample test in Java to run Automate session.importorg.openqa.selenium.By;importorg.openqa.selenium.Platform;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.WebElement;importorg.openqa.selenium.remote.DesiredCapabilities;importorg.openqa.selenium.remote.RemoteWebDriver;importjava.net.URL;publicclassJavaSample{publicstaticfinalString AUTOMATE_USERNAME ="YOUR_USERNAME";publicstaticfinalString AUTOMATE_ACCESS_KEY ="YOUR_ACCESS_KEY";publicstaticfinalString URL ="https://"+ AUTOMATE_USERNAME +":"+ AUTOMATE_ACCESS_KEY +"@hub-cloud.browserstack.com/wd/hub";publicstaticvoidmain(String[] args)throwsException{DesiredCapabilities caps =newDesiredCapabilities();
caps.setCapability("os_version","10");
caps.setCapability("resolution","1920x1080");
caps.setCapability("browser","Firefox");
caps.setCapability("browser_version","80.0");
caps.setCapability("os","Windows");
caps.setCapability("name","BStack-[Java] Sample Test");// test name
caps.setCapability("build","BStack Build Number 1");// CI/CD job or build name
caps.setCapability("browserstack.highContrast","true");WebDriver driver =newRemoteWebDriver(newURL(URL), caps);
driver.get("https://www.google.com");WebElement element = driver.findElement(By.name("q"));
element.sendKeys("BrowserStack");
element.submit();System.out.println(driver.getTitle());
driver.quit();}}
var webdriver =require('selenium-webdriver');// Input capabilitiesvar capabilities ={'os_version':'10','resolution':'1920x1080','browserName':'Firefox','browser_version':'80.0','os':'Windows','name':'BStack-[NodeJS] Sample Test',// test name'build':'BStack Build Number 1',// CI/CD job or build name'browserstack.user':'YOUR_USERNAME','browserstack.key':'YOUR_ACCESS_KEY','browserstack.highContrast':'True'}var driver =newwebdriver.Builder().usingServer('https://hub-cloud.browserstack.com/wd/hub').withCapabilities(capabilities).build();
driver.get('https://www.google.com').then(function(){
driver.findElement(webdriver.By.name('q')).sendKeys('BrowserStack').then(function(){
driver.getTitle().then(function(title){
console.log(title);
driver.quit();});});});
// Sample test in Java to run Automate session.usingSystem;usingOpenQA.Selenium;usingOpenQA.Selenium.Remote;namespaceSeleniumTest{classProgram{staticvoidMain(string[] args){IWebDriver driver;OpenQA.Selenium.Firefox.FirefoxOptions capability =newOpenQA.Selenium.Firefox.FirefoxOptions();
capability.AddAdditionalCapability("os_version","10",true);
capability.AddAdditionalCapability("resolution","1920x1080",true);
capability.AddAdditionalCapability("browser","Firefox",true);
capability.AddAdditionalCapability("browser_version","80.0",true);
capability.AddAdditionalCapability("os","Windows",true);
capability.AddAdditionalCapability("name","BStack-[C_sharp] Sample Test",true);// test name
capability.AddAdditionalCapability("build","BStack Build Number 1",true);// CI/CD job or build name
capability.AddAdditionalCapability("browserstack.user","YOUR_USERNAME",true);
capability.AddAdditionalCapability("browserstack.key","YOUR_ACCESS_KEY",true);
capability.AddAdditionalCapability("browserstack.highContrast","true",true);
driver =newRemoteWebDriver(newUri("https://hub-cloud.browserstack.com/wd/hub/"), capability
);
driver.Navigate().GoToUrl("https://www.google.com");
Console.WriteLine(driver.Title);IWebElement query = driver.FindElement(By.Name("q"));
query.SendKeys("Browserstack");
query.Submit();
Console.WriteLine(driver.Title);
driver.Quit();}}}
<?phprequire_once('vendor/autoload.php');useFacebook\WebDriver\Remote\RemoteWebDriver;useFacebook\WebDriver\WebDriverBy;$caps=array("os_version"=>"10","resolution"=>"1920x1080","browser"=>"Firefox","browser_version"=>"80.0","os"=>"Windows","name"=>"BStack-[Php] Sample Test",// test name"build"=>"BStack Build Number 1",// CI/CD job or build name"browserstack.highContrast"=>"true");$web_driver=RemoteWebDriver::create("https://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub",$caps);$web_driver->get("https://www.google.com");$element=$web_driver->findElement(WebDriverBy::name("q"));if($element){$element->sendKeys("Browserstack");$element->submit();}print$web_driver->getTitle();$web_driver->quit();?>
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
desired_cap ={"os":"Windows","os_version":"10","browser":"Firefox","browser_version":"80.0","name":"BStack-[Python] HCM Test",# test name"build":"BStack Build Number 1","browserstack.highContrast":"true"}
driver = webdriver.Remote(
command_executor='https://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub',
desired_capabilities=desired_cap)
driver.get("https://www.google.com")ifnot"Google"in driver.title:raise Exception("Unable to load google page!")
elem = driver.find_element_by_name("q")
elem.send_keys("BrowserStack")
elem.submit()print(driver.title)
driver.quit()
require'rubygems'require'selenium-webdriver'# Input capabilities
caps =Selenium::WebDriver::Remote::Capabilities.new
caps['device']='iPhone 8 Plus'
caps['realMobile']='true'
caps['os_version']='12'
caps['name']='BStack-[Ruby] Sample Test'# test name
caps['build']='BStack Build Number 1'# CI/CD job or build name
caps["browserstack.highContrast"]:"true"
driver =Selenium::WebDriver.for(:remote,:url=>"https://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub",:desired_capabilities=> caps)
driver.navigate.to "https://www.google.com"
element = driver.find_element(:name,'q')
element.send_keys "BrowserStack"
element.submit
puts driver.title
driver.quit
Following is the screenshot from the test as run through the script above. It shows the website getting rendered on a high contrast enabled browser on the BrowserStack Automate platform:
Did this page help you?
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked