Best JavaScript code snippet using playwright-internal
ListNavigationSupport.js
Source:ListNavigationSupport.js
1/*2 * 3 * WinUi54 *5 * pks.winui5.ListNavigationSupport6 * 7 * @author Jan Philipp Knöller <info@pksoftware.de>8 * 9 * Homepage: http://pksoftware.de10 *11 * Copyright (c) 2013-2014 Jan Philipp Knöller <info@pksoftware.de>12 * 13 * Licensed under the Apache License, Version 2.0 (the "License");14 * you may not use this file except in compliance with the License.15 * You may obtain a copy of the License at16 *17 * http://www.apache.org/licenses/LICENSE-2.018 *19 * Unless required by applicable law or agreed to in writing, software20 * distributed under the License is distributed on an "AS IS" BASIS,21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.22 * See the License for the specific language governing permissions and23 * limitations under the License.24 * Released under Apache2 license: http://www.apache.org/licenses/LICENSE-2.0.txt25 * 26 */27sap.ui.define(["./library", "sap/ui/events/KeyCodes"], function(winui5Lib, KeyCodes){28 29 "use strict";30 31 /**32 * @class33 * Class that provides methods to add drag support to items and containers.34 * @alias pks.winui5.ListNavigationSupport.Trait35 * @author Jan Philipp Knoeller36 * @version 1.0.8-SNAPSHOT37 * @public38 */39 var Trait = {};40 41 /**42 * Finds the next node in the order.43 * 44 * @param {pks.winui5.Item} oNode - The node to search from.45 * @param {int} iDir - The direction and step length.46 * @param {boolean} bSkipChildren - Whether to skip the children.47 * 48 * @return {pks.winui5.Item} The next node.49 * 50 * @protected51 * @override52 */53 Trait.findNextItem = function(oNode, iDir, bSkipChildren){54 if(!oNode){55 jQUery.sap.log.warning("Cannot find next item from null!");56 return null;57 }58 59 var aChildNodes = this.getItems();60 61 if(!aChildNodes.length){62 //Should never happen63 throw new Error("Unable to find next item: no items.");64 }65 66 var oNodeParent = oNode.getParent(),67 aParentChildren = oNodeParent.getItems(),68 iNodeIndex = oNodeParent.indexOfItem(oNode),69 iParentChildrenCount = aParentChildren.length;70 71 if(iNodeIndex < 0 || iParentChildrenCount === 0 || iDir === 0){72 //Should never happen73 throw new Error("Could not determine node index.");74 }75 76 iNodeIndex += iDir;77 78 var oNextNode = null;79 80 if(iNodeIndex >= 0 && iNodeIndex < iParentChildrenCount){81 oNextNode = aParentChildren[iNodeIndex];82 83 //Skip item if unavailable84 if(oNextNode && !oNextNode.isAvailable()){85 oNextNode = this.findNextItem(oNextNode, iDir, bSkipChildren);86 }87 }88 89 return oNextNode;90 };91 92 /**93 * Determines the position (index) of the item.94 * 95 * @param {pks.winui5.Item} oItem - The item to test.96 * 97 * @return {int} - The position.98 * 99 * @override100 */101 Trait.determineItemPosition = function(oItem){102 var oParent = oItem.getParent();103 104 if(this !== oParent){105 throw new Error("Item must be inside this container.");106 }107 108 return this.indexOfItem(oItem);109 };110 111 112 113 /**114 * Returns the aria role. Overrides abstract method <em>ItemContainer.prototype.getAriaRole</em>115 * 116 * @return {string} - The aria role.117 * @override118 */119 Trait.getAriaRole = function(){120 return this.getLayout() === "Grid" ? "grid" : "listbox";121 };122 123 /**124 * @class125 * Class that provides methods to add drag support to items and containers.126 * @alias pks.winui5.ListNavigationSupport127 * @author Jan Philipp Knoeller128 * @version 1.0.8-SNAPSHOT129 * @public130 */131 var ListNavigationSupport = {};132 133 ListNavigationSupport.addMetadata = function(oMetadata, bIsElement){134 135 136 };137 138 ListNavigationSupport.addMethods = function(oProto, bIsElement){139 oProto.findNextItem = Trait.findNextItem;140 141 oProto.determineItemPosition = Trait.determineItemPosition;142 143 oProto.getAriaRole = Trait.getAriaRole;144 };145 146 ListNavigationSupport.onInit = function(oInstance){147 148 oInstance.attachNavigate(function(oEvent){149 150 var sKeyCode = oEvent.getParameter("keyCode");151 if(sKeyCode === KeyCodes.ARROW_LEFT152 || sKeyCode === KeyCodes.ARROW_RIGHT){153 154 if(this.getLayout() !== "VerticalList"){155 //Grid or HorizontalList156 var oNode = this.getActiveItem(),157 iStep = 1;158 159 if(!oNode || !oNode.getDomRef()){160 return;161 }162 163 var sKeyCode = oEvent.getParameter("keyCode");164 165 if(sKeyCode === KeyCodes.ARROW_LEFT){166 this.navigate(oNode, -1);167 }168 else if(sKeyCode === KeyCodes.ARROW_RIGHT){169 this.navigate(oNode, 1);170 }171 }172 173 }174 else if(sKeyCode === KeyCodes.ARROW_UP175 || sKeyCode === KeyCodes.ARROW_DOWN){176 177 var oNode = this.getActiveItem();178 179 if(!oNode || !oNode.getDomRef()){180 return;181 }182 183 var iStep = 1; //Width including border184 185 //this.$()[0].clientWidth, //Container width without border186 187 if(this.getLayout() === "Grid"){188 //Grid only189 var iWidth = jQuery(this.getSubDomRef("children")).width(), //Width without padding190 iNodeWidth = oNode.getDomRef().offsetWidth;191 192 iStep = Math.floor(iWidth / iNodeWidth);193 }194 195 if(this.getLayout() !== "HorizontalList"){196 //Grid and vertical list197 if(sKeyCode === KeyCodes.ARROW_UP){198 this.navigate(oNode, -iStep);199 }200 else if(sKeyCode === KeyCodes.ARROW_DOWN){201 this.navigate(oNode, iStep);202 }203 }204 }205 206 });207 208 209 };210 211 return ListNavigationSupport;...
GroupHeaderListItemRenderer-dbg.js
Source:GroupHeaderListItemRenderer-dbg.js
1/*!2 * UI development toolkit for HTML5 (OpenUI5)3 * (c) Copyright 2009-2018 SAP SE or an SAP affiliate company.4 * Licensed under the Apache License, Version 2.0 - see LICENSE.txt.5 */6sap.ui.define(["sap/ui/core/library", "sap/ui/core/Renderer", "./ListItemBaseRenderer"],7 function(coreLibrary, Renderer, ListItemBaseRenderer) {8 "use strict";9 // shortcut for sap.ui.core.TextDirection10 var TextDirection = coreLibrary.TextDirection;11 /**12 * GroupHeaderListItem renderer.13 * @namespace14 */15 var GroupHeaderListItemRenderer = Renderer.extend(ListItemBaseRenderer);16 GroupHeaderListItemRenderer.renderType = function(rm, oLI) {17 var oTable = oLI.getTable();18 // for table render navigation column always19 oTable && rm.write('<td class="sapMListTblNavCol">');20 ListItemBaseRenderer.renderType.apply(this, arguments);21 oTable && rm.write('</td>');22 };23 // GroupHeaderListItem does not respect counter property of the LIB24 GroupHeaderListItemRenderer.renderCounter = function(rm, oLI) {25 };26 /**27 * Renders the attributes for the given list item, using the provided28 * {@link sap.ui.core.RenderManager}.29 *30 * @param {sap.ui.core.RenderManager}31 * rm the RenderManager that can be used for writing to the32 * Render-Output-Buffer33 * @param {sap.ui.core.Control}34 * oLI an object representation of the list item that should be35 * rendered36 */37 GroupHeaderListItemRenderer.renderLIAttributes = function(rm, oLI) {38 rm.addClass("sapMGHLI");39 if (oLI.getUpperCase()) {40 rm.addClass("sapMGHLIUpperCase");41 }42 };43 /**44 * Renders the List item content45 *46 * @param {sap.ui.core.RenderManager}47 * rm the RenderManager that can be used for writing to the48 * Render-Output-Buffer49 * @param {sap.ui.core.Control}50 * oLI an object representation of the list item that should be51 * rendered52 */53 GroupHeaderListItemRenderer.renderLIContentWrapper = function(rm, oLI) {54 var oTable = oLI.getTable();55 if (oTable) {56 rm.write('<td class="sapMGHLICell"');57 rm.writeAttribute("colspan", oTable.getColSpan());58 rm.write(">");59 }60 ListItemBaseRenderer.renderLIContentWrapper.apply(this, arguments);61 if (oTable) {62 rm.write("</td>");63 }64 };65 GroupHeaderListItemRenderer.renderLIContent = function(rm, oLI) {66 var sTextDir = oLI.getTitleTextDirection();67 rm.write("<span class='sapMGHLITitle'");68 if (sTextDir != TextDirection.Inherit) {69 rm.writeAttribute("dir", sTextDir.toLowerCase());70 }71 rm.write(">");72 rm.writeEscaped(oLI.getTitle());73 rm.write("</span>");74 var iCount = oLI.getCount() || oLI.getCounter();75 if (iCount) {76 rm.write("<span class='sapMGHLICounter'>");77 rm.writeEscaped(" (" + iCount + ")");78 rm.write("</span>");79 }80 };81 GroupHeaderListItemRenderer.addLegacyOutlineClass = function(rm, oLI) {82 if (!oLI.getTable()) {83 ListItemBaseRenderer.addLegacyOutlineClass.apply(this, arguments);84 }85 };86 GroupHeaderListItemRenderer.getAriaRole = function(oLI) {87 if (oLI.getTable()) {88 return "row";89 }90 return ListItemBaseRenderer.getAriaRole.apply(this, arguments);91 };92 return GroupHeaderListItemRenderer;...
elementAriaRole_test.js
Source:elementAriaRole_test.js
...29 it('Should return explicitly defined role', async function () {30 await driver.get(`data:text/html,<!DOCTYPE html>31 <div role='heading' aria-level='1'>Level 1 Header</div>`)32 let header = driver.findElement(By.css('div'))33 assert.strictEqual(await header.getAriaRole(), 'heading')34 })35 it('Should return implicit role defined by tagName', 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.getAriaRole(), 'heading')40 })41 it('Should return explicit role even if it contradicts TagName', async function () {42 await driver.get(`data:text/html,<!DOCTYPE html>43 <h1 role='alert'>Level 1 Header</h1>`)44 let header = driver.findElement(By.css('h1'))45 assert.strictEqual(await header.getAriaRole(), 'alert')46 })47 })48 },49 { browsers: ['chrome'] }...
getAriaRole.js
Source:getAriaRole.js
...4 *5 * @example6 * module.exports = {7 * demoTest(browser) {8 * browser.getAriaRole('*[name="search"]', function(result) {9 * this.assert.equal(typeof result, 'object');10 * this.assert.equal(result.value, 'combobox');11 * });12 *13 * // with explicit locate strategy14 * browser.getAriaRole('css selector', '*[name="search"]', function(result) {15 * console.log('getAriaRole result', result.value);16 * });17 *18 * // with selector object - see https://nightwatchjs.org/guide#element-properties19 * browser.getAriaRole({20 * selector: '*[name="search"]',21 * index: 122 * }, function(result) {23 * console.log('getAriaRole result', result.value);24 * });25 *26 * browser.getAriaRole({27 * selector: '*[name="search"]',28 * timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present29 * }, function(result) {30 * console.log('getAriaRole result', result.value);31 * });32 * },33 *34 * demoTestAsync: async function(browser) {35 * const result = await browser.getAriaRole('*[name="search"]');36 * console.log('getAriaRole result', result);37 * }38 * }39 *40 * @method getAriaRole41 * @syntax .getAriaRole(selector, callback)42 * @syntax .getAriaRole(using, selector, callback)43 * @param {string} [using] The locator strategy to use. See [W3C Webdriver - locator strategies](https://www.w3.org/TR/webdriver/#locator-strategies)44 * @param {string} selector The CSS/Xpath selector used to locate the element.45 * @param {function} callback Callback function which is called with the result value.46 * @returns {string} The computed WAI-ARIA role of element.47 * @link /#dfn-get-computed-role48 * @api protocol.elementstate49 */50class GetAriaRole extends BaseElementCommand {51 get extraArgsCount() {52 return 0;53 }54 get elementProtocolAction() {55 return 'getElementAriaRole';56 }...
FieldMultiInputRenderer-dbg.js
Source:FieldMultiInputRenderer-dbg.js
1/*!2 * OpenUI53 * (c) Copyright 2009-2020 SAP SE or an SAP affiliate company.4 * Licensed under the Apache License, Version 2.0 - see LICENSE.txt.5 */6sap.ui.define(['sap/ui/core/Renderer', 'sap/m/MultiInputRenderer'],7 function(Renderer, MultiInputRenderer) {8 "use strict";9 /**10 * FieldMultiInput renderer.11 * @namespace12 */13 var FieldMultiInputRenderer = Renderer.extend(MultiInputRenderer);14 FieldMultiInputRenderer.apiVersion = 2;15 FieldMultiInputRenderer.addOuterClasses = function(oRm, oMultiInput) {16 MultiInputRenderer.addOuterClasses.apply(this, arguments);17 oRm.class("sapUiMdcFieldMultiInput");18 };19 FieldMultiInputRenderer.getAriaRole = function (oMultiInput) {20 var oAriaAttributes = oMultiInput.getAriaAttributes();21 if (oAriaAttributes.role) {22 return oAriaAttributes.role;23 } else {24 return MultiInputRenderer.getAriaRole.apply(this, arguments);25 }26 };27 FieldMultiInputRenderer.getAccessibilityState = function (oMultiInput) {28 var oAriaAttributes = oMultiInput.getAriaAttributes();29 var mAccessibilityState = MultiInputRenderer.getAccessibilityState.apply(this, arguments);30 // add aria attributes31 if (oAriaAttributes.aria) {32 for (var sAttribute in oAriaAttributes.aria) {33 mAccessibilityState[sAttribute] = oAriaAttributes.aria[sAttribute];34 }35 }36 return mAccessibilityState;37 };38 FieldMultiInputRenderer.writeInnerAttributes = function(oRm, oMultiInput) {39 MultiInputRenderer.writeInnerAttributes.apply(this, arguments);40 var oAriaAttributes = oMultiInput.getAriaAttributes();41 // add all not aria specific attributes42 for (var sAttribute in oAriaAttributes) {43 if (sAttribute !== "aria" && sAttribute !== "role") {44 oRm.attr(sAttribute, oAriaAttributes[sAttribute]);45 }46 }47 };48 return FieldMultiInputRenderer;...
FieldInputRenderer-dbg.js
Source:FieldInputRenderer-dbg.js
1/*!2 * OpenUI53 * (c) Copyright 2009-2020 SAP SE or an SAP affiliate company.4 * Licensed under the Apache License, Version 2.0 - see LICENSE.txt.5 */6sap.ui.define(['sap/ui/core/Renderer', 'sap/m/InputRenderer'],7 function(Renderer, InputRenderer) {8 "use strict";9 /**10 * FieldInput renderer.11 * @namespace12 */13 var FieldInputRenderer = Renderer.extend(InputRenderer);14 FieldInputRenderer.apiVersion = 2;15 FieldInputRenderer.addOuterClasses = function(oRm, oInput) {16 InputRenderer.addOuterClasses.apply(this, arguments);17 oRm.class("sapUiMdcFieldInput");18 };19 FieldInputRenderer.getAriaRole = function (oInput) {20 var oAriaAttributes = oInput.getAriaAttributes();21 if (oAriaAttributes.role) {22 return oAriaAttributes.role;23 } else {24 return InputRenderer.getAriaRole.apply(this, arguments);25 }26 };27 FieldInputRenderer.getAccessibilityState = function (oInput) {28 var oAriaAttributes = oInput.getAriaAttributes();29 var mAccessibilityState = InputRenderer.getAccessibilityState.apply(this, arguments);30 // add aria attributes31 if (oAriaAttributes.aria) {32 for (var sAttribute in oAriaAttributes.aria) {33 mAccessibilityState[sAttribute] = oAriaAttributes.aria[sAttribute];34 }35 }36 return mAccessibilityState;37 };38 FieldInputRenderer.writeInnerAttributes = function(oRm, oInput) {39 InputRenderer.writeInnerAttributes.apply(this, arguments);40 var oAriaAttributes = oInput.getAriaAttributes();41 // add all not aria specific attributes42 for (var sAttribute in oAriaAttributes) {43 if (sAttribute !== "aria" && sAttribute !== "role") {44 oRm.attr(sAttribute, oAriaAttributes[sAttribute]);45 }46 }47 };48 return FieldInputRenderer;...
testGetAriaRole.js
Source:testGetAriaRole.js
...7 });8 after(function (done) {9 CommandGlobals.afterEach.call(this, done);10 });11 it('client.getAriaRole()', function (done) {12 MockServer.addMock({13 url: '/wd/hub/session/1352110219202/element/0/computedrole',14 method: 'GET',15 response: JSON.stringify({16 sessionId: '1352110219202',17 status: 0,18 value: 'combobox'19 })20 });21 this.client.api22 .getAriaRole('#weblogin', function callback(result) {23 assert.strictEqual(result.value, 'combobox');24 })25 .getAriaRole('css selector', '#weblogin', function callback(result) {26 assert.strictEqual(result.value, 'combobox');27 })28 .getAriaRole(29 'css selector',30 {31 selector: '#weblogin',32 timeout: 10033 },34 function callback(result) {35 assert.strictEqual(result.value, 'combobox');36 }37 )38 .getAriaRole(39 {40 selector: '#weblogin',41 timeout: 10042 },43 function callback(result) {44 assert.strictEqual(result.value, 'combobox');45 }46 );47 this.client.start(done);48 });...
ToDoListContainerRenderer.js
Source:ToDoListContainerRenderer.js
...31todomvc.view.ToDoListContainerRenderer.prototype.initializeDom =32 function(container) {33 var elem = /**@type {!Element}*/ (container.getElement());34 // Set the ARIA role.35 var ariaRole = this.getAriaRole();36 if (ariaRole) {37 goog.a11y.aria.setRole(elem, ariaRole);38 }...
Using AI Code Generation
1const { getAriaRole } = require('playwright/lib/server/dom.js');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const role = await getAriaRole(await page.$('a'));8 console.log(role);9 await browser.close();10})();11const { chromium } = require('playwright');12(async () => {13 const browser = await chromium.launch();14 const context = await browser.newContext();15 const page = await context.newPage();16 const role = await page.$eval('a', el => el.ariaRole);17 console.log(role);18 await browser.close();19})();
Using AI Code Generation
1const { getAriaRole } = require('playwright/lib/internal/accessibility');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const element = await page.$('div[role="toolbar"]');8 const role = await getAriaRole(page, element);9 console.log(role);10 await browser.close();11})();
Using AI Code Generation
1const { getAriaRole } = require('@playwright/test/lib/server/dom');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const ariaRole = await getAriaRole(page, 'text="API"');8 console.log(ariaRole);9 await browser.close();10})();11const { getAriaLabel } = require('@playwright/test/lib/server/dom');12const { chromium } = require('playwright');13(async () => {14 const browser = await chromium.launch();15 const context = await browser.newContext();16 const page = await context.newPage();17 const ariaLabel = await getAriaLabel(page, 'text="API"');18 console.log(ariaLabel);19 await browser.close();20})();
Using AI Code Generation
1const { getAriaRole } = require('playwright-core/lib/server/dom.js');2const { chromium } = require('playwright-core');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const element = await page.$('text=Get started');8 const ariaRole = await getAriaRole(element);9 console.log(ariaRole);10 await browser.close();11})();12const { getAttribute } = require('playwright-core/lib/server/dom.js');13const { chromium } = require('playwright-core');14(async () => {15 const browser = await chromium.launch();16 const context = await browser.newContext();17 const page = await context.newPage();18 const element = await page.$('text=Get started');19 const attributeValue = await getAttribute(element, 'href');20 console.log(attributeValue);21 await browser.close();22})();23const { getAttributes } = require('playwright-core/lib/server/dom.js');24const { chromium } = require('playwright-core');25(async () => {26 const browser = await chromium.launch();27 const context = await browser.newContext();28 const page = await context.newPage();29 const element = await page.$('text=Get started');30 const attributes = await getAttributes(element);31 console.log(attributes);32 await browser.close();33})();34const { getBoxModel } = require('playwright-core/lib/server/dom.js');35const { chromium } = require('playwright-core');36(async () => {37 const browser = await chromium.launch();38 const context = await browser.newContext();39 const page = await context.newPage();40 const element = await page.$('text=
Using AI Code Generation
1const { getAriaRole } = require('playwright/lib/server/dom.js');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 await page.waitForSelector('text=Get started');7 const element = await page.$('text=Get started');8 const ariaRole = await getAriaRole(element);9 console.log(ariaRole);10 await browser.close();11})();12const { getAttribute } = require('playwright/lib/server/dom.js');13const { chromium } = require('playwright');14(async () => {15 const browser = await chromium.launch();16 const page = await browser.newPage();17 await page.waitForSelector('text=Get started');18 const element = await page.$('text=Get started');19 const attribute = await getAttribute(element, 'href');20 console.log(attribute);21 await browser.close();22})();23const { getAttributes } = require('playwright/lib/server/dom.js');24const { chromium } = require('playwright');25(async () => {26 const browser = await chromium.launch();27 const page = await browser.newPage();28 await page.waitForSelector('text=Get started');29 const element = await page.$('text=Get started');30 const attributes = await getAttributes(element);31 console.log(attributes);32 await browser.close();33})();34const { getBoxModel } = require('playwright/lib/server/dom.js');35const { chromium } = require('playwright');36(async () => {37 const browser = await chromium.launch();38 const page = await browser.newPage();39 await page.waitForSelector('text=Get started');40 const element = await page.$('text=Get started');
Using AI Code Generation
1const { getAriaRole } = require("playwright-core/lib/server/dom.js");2const { chromium } = require("playwright-core");3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const elementHandle = await page.$("#ex1");8 const ariaRole = await getAriaRole(elementHandle);9 console.log(ariaRole);10 await browser.close();11})();
Using AI Code Generation
1const { Playwright } = require('@playwright/test');2const playwright = new Playwright();3const browser = await playwright.chromium.launch();4const context = await browser.newContext();5const page = await context.newPage();6const elementHandle = await page.$('button');7const ariaRole = await elementHandle.evaluate(element => element.getAriaRole());8console.log(ariaRole);9await browser.close();
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!