Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/selenium-webdriver/test/elementAriaRole_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 } = require('selenium-webdriver')
23
24
test.suite(
25
function (env) {
26
let driver
27
28
before(async function () {
29
driver = await env.builder().build()
30
})
31
after(() => driver.quit())
32
33
describe('Testing Aria role', function () {
34
it('Should return explicitly defined role', async function () {
35
await driver.get(`data:text/html,<!DOCTYPE html>
36
<div role='heading' aria-level='1'>Level 1 Header</div>`)
37
let header = driver.findElement(By.css('div'))
38
assert.strictEqual(await header.getAriaRole(), 'heading')
39
})
40
41
it('Should return implicit role defined by tagName', async function () {
42
await driver.get(`data:text/html,<!DOCTYPE html>
43
<h1> Level 1 Header</h1>`)
44
let header = driver.findElement(By.css('h1'))
45
assert.strictEqual(await header.getAriaRole(), 'heading')
46
})
47
48
it('Should return explicit role even if it contradicts TagName', async function () {
49
await driver.get(`data:text/html,<!DOCTYPE html>
50
<h1 role='alert'>Level 1 Header</h1>`)
51
let header = driver.findElement(By.css('h1'))
52
assert.strictEqual(await header.getAriaRole(), 'alert')
53
})
54
})
55
},
56
{ browsers: ['chrome'] },
57
)
58
59