Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/selenium-webdriver/test/elementAccessibleName_test.js
2884 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License. You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied. See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
'use strict'
19
20
const assert = require('node:assert')
21
const test = require('../lib/test')
22
const { By, Browser } = require('selenium-webdriver')
23
const { ignore } = require('../lib/test')
24
25
test.suite(
26
function (env) {
27
let driver
28
29
before(async function () {
30
driver = await env.builder().build()
31
})
32
after(() => driver.quit())
33
34
describe('Testing Aria Label', function () {
35
it('Should return computed label', async function () {
36
await driver.get(`data:text/html,<!DOCTYPE html>
37
<h1>Level 1 Header</h1>`)
38
let header = driver.findElement(By.css('h1'))
39
assert.strictEqual(await header.getAccessibleName(), 'Level 1 Header')
40
})
41
42
it('Should return computed label for img', async function () {
43
await driver.get(`data:text/html,<!DOCTYPE html>
44
<img src="tequila.png" alt="Test Image">`)
45
let imgLabel = driver.findElement(By.css('img'))
46
assert.strictEqual(await imgLabel.getAccessibleName(), 'Test Image')
47
})
48
49
ignore(env.browsers(Browser.CHROME)).it('Should return computed label for label', async function () {
50
await driver.get(`data:text/html,<!DOCTYPE html>
51
<input type="checkbox" id="label_test">
52
<label for="label_test">Test Label</label>`)
53
let computedLabel = driver.findElement(By.css('input'))
54
assert.strictEqual(await computedLabel.getAccessibleName(), 'Test Label')
55
})
56
57
it('Should return computed label for aria-label', async function () {
58
await driver.get(`data:text/html,<!DOCTYPE html>
59
<button aria-label="Add sample button to cart">Add to cart</button>`)
60
let computedAriaLabel = driver.findElement(By.css('button'))
61
assert.strictEqual(await computedAriaLabel.getAccessibleName(), 'Add sample button to cart')
62
})
63
64
it('Should return computed label for aria-labelby', async function () {
65
await driver.get(`data:text/html,<!DOCTYPE html>
66
<input type="search" aria-labelledby="this">
67
<button id="this">Search</button>`)
68
let computedAriaLabel = driver.findElement(By.css('input'))
69
assert.strictEqual(await computedAriaLabel.getAccessibleName(), 'Search')
70
})
71
})
72
},
73
{ browsers: ['chrome'] },
74
)
75
76