Path: blob/trunk/javascript/selenium-webdriver/test/elementAccessibleName_test.js
2884 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617'use strict'1819const assert = require('node:assert')20const test = require('../lib/test')21const { By, Browser } = require('selenium-webdriver')22const { ignore } = require('../lib/test')2324test.suite(25function (env) {26let driver2728before(async function () {29driver = await env.builder().build()30})31after(() => driver.quit())3233describe('Testing Aria Label', function () {34it('Should return computed label', async function () {35await driver.get(`data:text/html,<!DOCTYPE html>36<h1>Level 1 Header</h1>`)37let header = driver.findElement(By.css('h1'))38assert.strictEqual(await header.getAccessibleName(), 'Level 1 Header')39})4041it('Should return computed label for img', async function () {42await driver.get(`data:text/html,<!DOCTYPE html>43<img src="tequila.png" alt="Test Image">`)44let imgLabel = driver.findElement(By.css('img'))45assert.strictEqual(await imgLabel.getAccessibleName(), 'Test Image')46})4748ignore(env.browsers(Browser.CHROME)).it('Should return computed label for label', async function () {49await driver.get(`data:text/html,<!DOCTYPE html>50<input type="checkbox" id="label_test">51<label for="label_test">Test Label</label>`)52let computedLabel = driver.findElement(By.css('input'))53assert.strictEqual(await computedLabel.getAccessibleName(), 'Test Label')54})5556it('Should return computed label for aria-label', async function () {57await driver.get(`data:text/html,<!DOCTYPE html>58<button aria-label="Add sample button to cart">Add to cart</button>`)59let computedAriaLabel = driver.findElement(By.css('button'))60assert.strictEqual(await computedAriaLabel.getAccessibleName(), 'Add sample button to cart')61})6263it('Should return computed label for aria-labelby', async function () {64await driver.get(`data:text/html,<!DOCTYPE html>65<input type="search" aria-labelledby="this">66<button id="this">Search</button>`)67let computedAriaLabel = driver.findElement(By.css('input'))68assert.strictEqual(await computedAriaLabel.getAccessibleName(), 'Search')69})70})71},72{ browsers: ['chrome'] },73)747576