How to use getImplicitAriaRole method in Playwright Internal

Best JavaScript code snippet using playwright-internal

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

ariaRoles.js

Source: ariaRoles.js Github

copy
1/**
2 ** use [htmlDatas.js, ariaDatas.js, implicitAriaRoles.js]
3 */
4var getComputedAriaRole = function () {
5    if (this.hasAttribute('role')) {
6        var role = this.getAttribute('role');
7        if (role.trim().length > 0) {
8            var roles = role.split(' ');
9            var computedRole = null;
10            if (roles.length > 1) {
11                for (var i = 0; i < roles.length; i++) {
12                    role = new ARIA.Role(roles[i]);
13                    if (role.isValid()) {
14                        computedRole = role.role;
15                        break;
16                    }
17                }
18                if (computedRole) {
19                    if (computedRole == 'presentation' || computedRole == 'none') {
20                        if (this.matches(HTML.getFocusableElementsSelector())) {
21                            return this.getImplicitAriaRole();
22                        }
23                    }
24                    return computedRole;
25                }
26                else {
27                    return this.getImplicitAriaRole();
28                }
29            }
30            else {
31                role = new ARIA.Role(role);
32                if (role.isValid()) {
33                    if (role.role == 'presentation' || role.role == 'none') {
34                        if (this.matches(HTML.getFocusableElementsSelector())) {
35                            return this.getImplicitAriaRole();
36                        }
37                    }
38                    return role.role;
39                }
40                else {
41                    return this.getImplicitAriaRole();
42                }
43            }
44        }
45        else {
46            return this.getImplicitAriaRole();
47        }
48    }
49    else {
50        return this.getImplicitAriaRole();
51    }
52};
53
54var hasValidRole = function () {
55    var role = this.getAttribute('role');
56    if (role.trim().length > 0) {
57        role = role.split(' ');
58        if (role.length > 1) {
59            var result = false;
60            for (var i = 0; i < role.length; i++) {
61                var token = new ARIA.Role(role[i]);
62                if (token.isValid()) {
63                    result = true;
64                    break;
65                }
66            }
67            return result;
68        }
69        else {
70            role = new ARIA.Role(role);
71            return role.isValid();
72        }
73    }
74    else {
75        return false;
76    }
77};
Full Screen

content.js

Source: content.js Github

copy
1/**
2 *? ariaSemantic.js
3 */
4if (!HTMLElement.prototype.hasOwnProperty('availableARIASemantics')) Object.defineProperty(HTMLElement.prototype, 'availableARIASemantics', { get: getAvailableARIASemantics });
5
6var isARIARoleAllowedOnMe = function () { return this.availableARIASemantics.indexOf('[role="' + role + '"]') > -1; };
7if (!('isARIARoleAllowedOnMe' in HTMLElement.prototype)) HTMLElement.prototype.isARIARoleAllowedOnMe = isARIARoleAllowedOnMe;
8
9/**
10 * ? accessibleName.js
11 */
12if (!SVGElement.prototype.hasOwnProperty('fullAccessibleName')) Object.defineProperty(SVGElement.prototype, 'fullAccessibleName', { get: getAccessibleName });
13if (!HTMLElement.prototype.hasOwnProperty('fullAccessibleName')) Object.defineProperty(HTMLElement.prototype, 'fullAccessibleName', { get: getAccessibleName });
14
15var accessibleName = function () { return this.fullAccessibleName[0]; };
16if (!('accessibleName' in SVGElement.prototype)) SVGElement.prototype.accessibleName = accessibleName;
17if (!('accessibleName' in HTMLElement.prototype)) HTMLElement.prototype.accessibleName = accessibleName;
18
19var hasAccessibleName = function () { return this.fullAccessibleName[0].length > 0; };
20if (!('hasAccessibleName' in SVGElement.prototype)) SVGElement.prototype.hasAccessibleName = hasAccessibleName;
21if (!('hasAccessibleName' in HTMLElement.prototype)) HTMLElement.prototype.hasAccessibleName = hasAccessibleName;
22
23/**
24 * ? implicitAriaRole.js
25 */
26if (!('getImplicitAriaRole' in HTMLElement.prototype)) HTMLElement.prototype.getImplicitAriaRole = getImplicitAriaRole;
27if (!('getImplicitAriaRole' in SVGElement.prototype)) SVGElement.prototype.getImplicitAriaRole = getImplicitAriaRole;
28
29if (!('getImplicitAriaRoleCategory' in HTMLElement.prototype)) HTMLElement.prototype.getImplicitAriaRoleCategory = getImplicitAriaRoleCategory;
30if (!('getImplicitAriaRoleCategory' in SVGElement.prototype)) SVGElement.prototype.getImplicitAriaRoleCategory = getImplicitAriaRoleCategory;
31
32/**
33 * ? ariaRoles.js
34 */
35if (!('getComputedAriaRole' in HTMLElement.prototype)) HTMLElement.prototype.getComputedAriaRole = getComputedAriaRole;
36if (!('getComputedAriaRole' in SVGElement.prototype)) SVGElement.prototype.getComputedAriaRole = getComputedAriaRole;
37
38if (!('hasValidRole' in HTMLElement.prototype)) HTMLElement.prototype.hasValidRole = hasValidRole;
39if (!('hasValidRole' in SVGElement.prototype)) SVGElement.prototype.hasValidRole = hasValidRole;
40
41/**
42 * ? ariaAttributes.js
43 */
44if (!('hasInvalidAriaAttributes' in HTMLElement.prototype)) HTMLElement.prototype.hasInvalidAriaAttributes = hasInvalidAriaAttributes;
45if (!('hasInvalidAriaAttributes' in SVGElement.prototype)) SVGElement.prototype.hasInvalidAriaAttributes = hasInvalidAriaAttributes;
46
47if (!('hasAriaAttributesWithInvalidValues' in HTMLElement.prototype)) HTMLElement.prototype.hasAriaAttributesWithInvalidValues = hasAriaAttributesWithInvalidValues;
48if (!('hasAriaAttributesWithInvalidValues' in SVGElement.prototype)) SVGElement.prototype.hasAriaAttributesWithInvalidValues = hasAriaAttributesWithInvalidValues;
49
50if (!('hasProhibitedAriaAttributes' in HTMLElement.prototype)) HTMLElement.prototype.hasProhibitedAriaAttributes = hasProhibitedAriaAttributes;
51if (!('hasProhibitedAriaAttributes' in SVGElement.prototype)) SVGElement.prototype.hasProhibitedAriaAttributes = hasProhibitedAriaAttributes;
52
53/**
54 * ? language.js
55 */
56 if (!('hasValidLanguageCode' in SVGElement.prototype)) SVGElement.prototype.hasValidLanguageCode = hasValidLanguageCode;
57 if (!('hasValidLanguageCode' in HTMLElement.prototype)) HTMLElement.prototype.hasValidLanguageCode = hasValidLanguageCode;
58
59/**
60 * ? isNotExposedDueTo.js
61 */
62if (!HTMLElement.prototype.hasOwnProperty('isNotExposedDueTo')) Object.defineProperty(HTMLElement.prototype, 'isNotExposedDueTo', { get: isNotExposedDueTo });
63if (!SVGElement.prototype.hasOwnProperty('isNotExposedDueTo')) Object.defineProperty(SVGElement.prototype, 'isNotExposedDueTo', { get: isNotExposedDueTo });
64
65/**
66 * ? contrast.js
67 */
68var isVisible = function () {
69    return getVisibility(this);
70};
71
72if (!HTMLElement.prototype.hasOwnProperty('isVisible')) Object.defineProperty(HTMLElement.prototype, 'isVisible', { get: isVisible });
73if (!SVGElement.prototype.hasOwnProperty('isVisible')) Object.defineProperty(SVGElement.prototype, 'isVisible', { get: isVisible });
74
75/**
76 * ? canBeReachedUsingKeyboardWith.js
77 */
78if (!SVGElement.prototype.hasOwnProperty('canBeReachedUsingKeyboardWith')) Object.defineProperty(SVGElement.prototype, 'canBeReachedUsingKeyboardWith', { get: canBeReachedUsingKeyboardWith });
79if (!HTMLElement.prototype.hasOwnProperty('canBeReachedUsingKeyboardWith')) Object.defineProperty(HTMLElement.prototype, 'canBeReachedUsingKeyboardWith', { get: canBeReachedUsingKeyboardWith });
80
81/**
82 * ? compareStrings.js
83 */
84if (!('isString1MatchString2' in HTMLElement.prototype)) HTMLElement.prototype.isString1MatchString2 = isString1MatchString2;
85if (!('isString1MatchString2' in SVGElement.prototype)) SVGElement.prototype.isString1MatchString2 = isString1MatchString2;
Full Screen

implicitAriaRole.js

Source: implicitAriaRole.js Github

copy
1/**
2 ** use [htmlDatas.js]
3 */
4var getImplicitAriaRole = function () {
5    if (htmlData.elements.hasOwnProperty(this.tagName.toLowerCase())) {
6        var elementData = htmlData.elements[this.tagName.toLowerCase()];
7        if (elementData.hasOwnProperty('implicitAriaRole')) {
8            var result = null;
9            var implicitAriaRole = elementData.implicitAriaRole;
10            switch (implicitAriaRole.constructor) {
11                case String:
12                    result = implicitAriaRole;
13                    break;
14                case Object:
15                    for (var selector in implicitAriaRole) {
16                        if (this.matches(selector)) {
17                            if (implicitAriaRole[selector].constructor == Object) {
18                                if (implicitAriaRole[selector].type == 'integer' && implicitAriaRole[selector].hasOwnProperty('greaterthan')) {
19                                    var attributeValue = this.getAttribute(implicitAriaRole[selector].attribute);
20                                    if (/^(0|[1-9]\d*)$/.test(attributeValue)) {
21                                        result = parseInt(attributeValue) > implicitAriaRole[selector].greaterthan;
22                                        result = implicitAriaRole[selector].role[result ? 1 : 0];
23                                    }
24                                    else {
25                                        result = implicitAriaRole[selector].role[0];
26                                    }
27                                }
28                            }
29                            else {
30                                result = implicitAriaRole[selector];
31                            }
32                            break;
33                        }
34                    }
35                    break;
36            }
37            return result;
38        }
39        else {
40            return null;
41        }
42    }
43    else {
44        return undefined;
45    }
46};
47
48var getImplicitAriaRoleCategory = function () {
49    if (htmlData.elements.hasOwnProperty(this.tagName.toLowerCase())) {
50        var elementData = htmlData.elements[this.tagName.toLowerCase()];
51        if (elementData.hasOwnProperty('category')) {
52            return elementData.category;
53        }
54        else {
55            return null;
56        }
57    }
58    else {
59        return undefined;
60    }
61};
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Playwright Internal on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)