/** * 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, expect } from './pageTest'; test.describe('toBeChecked', () => { test('default', async ({ page }) => { await page.setContent(''); const locator = page.locator('input'); await expect(locator).toBeChecked(); }); test('with checked:true', async ({ page }) => { await page.setContent(''); const locator = page.locator('input'); await expect(locator).toBeChecked({ checked: true }); }); test('with checked:false', async ({ page }) => { await page.setContent(''); const locator = page.locator('input'); await expect(locator).not.toBeChecked({ checked: false }); }); test('fail', async ({ page }) => { await page.setContent(''); const locator = page.locator('input'); const error = await expect(locator).toBeChecked({ timeout: 1000 }).catch(e => e); expect(error.message).toContain(`expect.toBeChecked with timeout 1000ms`); }); test('with not', async ({ page }) => { await page.setContent(''); const locator = page.locator('input'); await expect(locator).not.toBeChecked(); }); test('with not and checked:false', async ({ page }) => { await page.setContent(''); const locator = page.locator('input'); await expect(locator).toBeChecked({ checked: false }); }); test('fail with not', async ({ page }) => { await page.setContent(''); const locator = page.locator('input'); const error = await expect(locator).not.toBeChecked({ timeout: 1000 }).catch(e => e); expect(error.message).toContain(`expect.not.toBeChecked with timeout 1000ms`); expect(error.message).toContain(`locator resolved to `); }); test('fail with checked:false', async ({ page }) => { await page.setContent(''); const locator = page.locator('input'); const error = await expect(locator).toBeChecked({ checked: false, timeout: 1000 }).catch(e => e); expect(error.message).toContain(`expect.toBeChecked with timeout 1000ms`); }); test('fail missing', async ({ page }) => { await page.setContent('
no inputs here
'); const locator2 = page.locator('input2'); const error = await expect(locator2).not.toBeChecked({ timeout: 1000 }).catch(e => e); expect(error.message).toContain(`expect.not.toBeChecked with timeout 1000ms`); expect(error.message).toContain('waiting for locator(\'input2\')'); }); test('with role', async ({ page }) => { for (const role of ['checkbox', 'menuitemcheckbox', 'option', 'radio', 'switch', 'menuitemradio', 'treeitem']) { await test.step(`role=${role}`, async () => { await page.setContent(`
I am checked
`); const locator = page.locator('div'); await expect(locator).toBeChecked(); }); } }); test('friendly log', async ({ page }) => { await page.setContent(''); const message1 = await expect(page.locator('input')).toBeChecked({ timeout: 1000 }).catch(e => e.message); expect(message1).toContain('unexpected value "unchecked"'); await page.setContent(''); const message2 = await expect(page.locator('input')).toBeChecked({ checked: false, timeout: 1000 }).catch(e => e.message); expect(message2).toContain('unexpected value "checked"'); }); test('with impossible timeout', async ({ page }) => { await page.setContent(''); await expect(page.locator('input')).toBeChecked({ timeout: 1 }); }); test('with impossible timeout .not', async ({ page }) => { await page.setContent(''); await expect(page.locator('input')).not.toBeChecked({ timeout: 1 }); }); }); test.describe('toBeEditable', () => { test('default', async ({ page }) => { await page.setContent(''); const locator = page.locator('input'); await expect(locator).toBeEditable(); }); test('with not', async ({ page }) => { await page.setContent(''); const locator = page.locator('input'); await expect(locator).not.toBeEditable(); }); test('with editable:true', async ({ page }) => { await page.setContent(''); const locator = page.locator('input'); await expect(locator).toBeEditable({ editable: true }); }); test('with editable:false', async ({ page }) => { await page.setContent(''); const locator = page.locator('input'); await expect(locator).toBeEditable({ editable: false }); }); test('with not and editable:false', async ({ page }) => { await page.setContent(''); const locator = page.locator('input'); await expect(locator).not.toBeEditable({ editable: false }); }); test('throws', async ({ page }) => { await page.setContent('