Path: blob/trunk/javascript/selenium-webdriver/test/webComponent_test.js
2884 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617'use strict'1819const assert = require('node:assert')20const { By, error } = require('selenium-webdriver')21const test = require('../lib/test')22const Pages = test.Pages2324test.suite(25function (env) {26describe('ShadowRoot', function () {27let driver2829before(async function () {30driver = await env.builder().build()31})3233after(function () {34return driver.quit()35})3637it('can get Shadow Root', async function () {38await driver.get(Pages.webComponents)39let element = await driver.findElement(By.css('custom-checkbox-element'))40await element.getShadowRoot()41// If an error is not thrown then test passes42})4344it('Throws NoSuchShadowRoot when one is not attached', async function () {45await driver.get(Pages.simpleTestPage)46let element = await driver.findElement(By.css('input'))4748try {49await element.getShadowRoot()50assert.fail('Error should have been thrown')51} catch (e) {52assert.ok(e instanceof error.NoSuchShadowRootError, `The error is ${typeof e}`)53}54})5556it('can find element below a shadow root', async function () {57await driver.get(Pages.webComponents)58let element = await driver.findElement(By.css('custom-checkbox-element'))59let shadowRoot = await element.getShadowRoot()60await shadowRoot.findElement(By.css('input'))61// test passes if no error throw62})6364it('can find elements below a shadow root', async function () {65await driver.get(Pages.webComponents)66let element = await driver.findElement(By.css('custom-checkbox-element'))67let shadowRoot = await element.getShadowRoot()68let actual = await shadowRoot.findElements(By.css('input'))69assert.strictEqual(actual.length, 1)70})7172it('can return a shadowRoot from executeScript', async function () {73await driver.get(Pages.webComponents)74let element = await driver.findElement(By.css('custom-checkbox-element'))75let shadowRoot = await element.getShadowRoot()76let executeShadow = await driver.executeScript('return arguments[0].shadowRoot', element)77assert.strictEqual(executeShadow.getId(), shadowRoot.getId())78})79})80},81{ browsers: ['chrome'] },82)838485