/** * Copyright 2017 Google Inc. All rights reserved. * Modifications copyright (c) Microsoft Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { test as it, expect } from './pageTest'; async function giveItAChanceToResolve(page) { for (let i = 0; i < 5; i++) await page.evaluate(() => new Promise(f => requestAnimationFrame(() => requestAnimationFrame(f)))); } it('element state checks should work as expected for label with zero-sized input', async ({ page, server }) => { await page.setContent(` `); // Visible checks the label. expect(await page.isVisible('text=Click me')).toBe(true); expect(await page.isHidden('text=Click me')).toBe(false); // Enabled checks the input. expect(await page.isEnabled('text=Click me')).toBe(false); expect(await page.isDisabled('text=Click me')).toBe(true); }); it('should wait for enclosing disabled button', async ({ page }) => { await page.setContent(''); const span = await page.$('text=Target'); let done = false; const promise = span.waitForElementState('disabled').then(() => done = true); await giveItAChanceToResolve(page); expect(done).toBe(false); await span.evaluate(span => (span.parentElement as HTMLButtonElement).disabled = true); await promise; }); it('should wait for enclosing button with a disabled fieldset', async ({ page }) => { await page.setContent('