Skip to content

Commit 27fe2d9

Browse files
authored
[JS] Adding support for computedrole (#8990)
1 parent 7c69619 commit 27fe2d9

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

javascript/node/selenium-webdriver/lib/command.js

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ const Name = {
140140
EXECUTE_ASYNC_SCRIPT: 'executeAsyncScript',
141141

142142
GET_ELEMENT_TEXT: 'getElementText',
143+
GET_COMPUTED_ROLE: 'getAriaRole',
143144
GET_ELEMENT_TAG_NAME: 'getElementTagName',
144145
IS_ELEMENT_SELECTED: 'isElementSelected',
145146
IS_ELEMENT_ENABLED: 'isElementEnabled',

javascript/node/selenium-webdriver/lib/http.js

+2
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ const COMMAND_MAP = new Map([
234234
],
235235
[cmd.Name.SUBMIT_ELEMENT, post('/session/:sessionId/element/:id/submit')],
236236
[cmd.Name.GET_ELEMENT_TEXT, get('/session/:sessionId/element/:id/text')],
237+
[cmd.Name.GET_COMPUTED_ROLE, get('/session/:sessionId/element/:id/computedrole')],
237238
[cmd.Name.GET_ELEMENT_TAG_NAME, get('/session/:sessionId/element/:id/name')],
238239
[
239240
cmd.Name.IS_ELEMENT_SELECTED,
@@ -402,6 +403,7 @@ const W3C_COMMAND_MAP = new Map([
402403
post('/session/:sessionId/element/:id/value'),
403404
],
404405
[cmd.Name.GET_ELEMENT_TEXT, get('/session/:sessionId/element/:id/text')],
406+
[cmd.Name.GET_COMPUTED_ROLE, get('/session/:sessionId/element/:id/computedrole')],
405407
[cmd.Name.IS_ELEMENT_ENABLED, get('/session/:sessionId/element/:id/enabled')],
406408
[
407409
cmd.Name.GET_ELEMENT_ATTRIBUTE,

javascript/node/selenium-webdriver/lib/webdriver.js

+10
Original file line numberDiff line numberDiff line change
@@ -2324,6 +2324,16 @@ class WebElement {
23242324
return this.execute_(new command.Command(command.Name.GET_ELEMENT_TEXT))
23252325
}
23262326

2327+
/**
2328+
* Get the computed WAI-ARIA role of element.
2329+
*
2330+
* @return {!Promise<string>} A promise that will be
2331+
* resolved with the element's computed role.
2332+
*/
2333+
getAriaRole() {
2334+
return this.execute_(new command.Command(command.Name.GET_COMPUTED_ROLE))
2335+
}
2336+
23272337
/**
23282338
* Returns an object describing an element's location, in pixels relative to
23292339
* the document element, and the element's size in pixels.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Licensed to the Software Freedom Conservancy (SFC) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The SFC licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
'use strict'
21+
22+
const assert = require('assert')
23+
const test = require('../lib/test')
24+
const { By } = require('../index')
25+
26+
test.suite(
27+
function (env) {
28+
let driver
29+
30+
before(async function () {
31+
driver = await env.builder().build()
32+
})
33+
after(() => driver.quit())
34+
35+
describe('Testing Aria role', function () {
36+
it('Should return explicitly defined role', async function () {
37+
await driver.get(`data:text/html,<!DOCTYPE html>
38+
<div role='heading' aria-level='1'>Level 1 Header</div>`)
39+
let header = driver.findElement(By.css('div'))
40+
assert.equal(await header.getAriaRole(), 'heading')
41+
})
42+
43+
it('Should return implicit role defined by tagName', async function () {
44+
await driver.get(`data:text/html,<!DOCTYPE html>
45+
<h1> Level 1 Header</h1>`)
46+
let header = driver.findElement(By.css('h1'))
47+
assert.equal(await header.getAriaRole(), 'heading')
48+
})
49+
50+
it('Should return explicit role even if it contradicts TagName', async function () {
51+
await driver.get(`data:text/html,<!DOCTYPE html>
52+
<h1 role='alert'>Level 1 Header</h1>`)
53+
let header = driver.findElement(By.css('h1'))
54+
assert.equal(await header.getAriaRole(), 'alert')
55+
})
56+
})
57+
},
58+
{ browsers: ['chrome'] }
59+
)

0 commit comments

Comments
 (0)