');
- await page.click('text=Click target');
- expect(await page.evaluate('__CLICKED')).toBe(true);
-});
-
-it('should climb up to a anchor', async ({ page }) => {
- // For Firefox its not allowed to return anything: https://bugzilla.mozilla.org/show_bug.cgi?id=1392046
- // Note the intermediate div - it is necessary, otherwise
is not recognized as a clickable link.
- await page.setContent(`
`);
- await page.click('#inner');
- expect(await page.evaluate('__CLICKED')).toBe(true);
-});
-
-it('should climb up to a [role=link]', async ({ page }) => {
- await page.setContent(`
`);
- await page.click('#inner');
- expect(await page.evaluate('__CLICKED')).toBe(true);
-});
-
it('should wait for BUTTON to be clickable when it has pointer-events:none', async ({ page }) => {
await page.setContent('
');
let done = false;
diff --git a/tests/page/page-fill.spec.ts b/tests/page/page-fill.spec.ts
index f0c060f2d1..aec4a0b858 100644
--- a/tests/page/page-fill.spec.ts
+++ b/tests/page/page-fill.spec.ts
@@ -34,36 +34,6 @@ it('should fill input', async ({ page, server }) => {
expect(await page.evaluate(() => window['result'])).toBe('some value');
});
-it('should fill input with label', async ({ page }) => {
- await page.setContent(`
`);
- await page.fill('text=Fill me', 'some value');
- expect(await page.$eval('input', input => input.value)).toBe('some value');
-});
-
-it('should fill input with label 2', async ({ page }) => {
- await page.setContent(`
`);
- await page.fill('text=Fill me', 'some value');
- expect(await page.$eval('input', input => input.value)).toBe('some value');
-});
-
-it('should fill input with span inside the label', async ({ page }) => {
- await page.setContent(`
`);
- await page.fill('text=Fill me', 'some value');
- expect(await page.$eval('input', input => input.value)).toBe('some value');
-});
-
-it('should fill input inside the label', async ({ page }) => {
- await page.setContent(`
`);
- await page.fill('input', 'some value');
- expect(await page.$eval('input', input => input.value)).toBe('some value');
-});
-
-it('should fill textarea with label', async ({ page }) => {
- await page.setContent(`
`);
- await page.fill('text=Fill me', 'some value');
- expect(await page.$eval('textarea', textarea => textarea.value)).toBe('some value');
-});
-
it('should throw on unsupported inputs', async ({ page, server }) => {
await page.goto(server.PREFIX + '/input/textarea.html');
for (const type of ['button', 'checkbox', 'file', 'image', 'radio', 'reset', 'submit']) {
diff --git a/tests/page/page-select-option.spec.ts b/tests/page/page-select-option.spec.ts
index e9808b4349..115d0526ff 100644
--- a/tests/page/page-select-option.spec.ts
+++ b/tests/page/page-select-option.spec.ts
@@ -108,26 +108,6 @@ it('should select multiple options with attributes', async ({ page, server }) =>
expect(await page.evaluate(() => window['result'].onChange)).toEqual(['blue', 'gray', 'green']);
});
-it('should select options with sibling label', async ({ page, server }) => {
- await page.setContent(`
-
`);
- await page.selectOption('text=Choose a pet', 'cat');
- expect(await page.$eval('select', select => select.options[select.selectedIndex].text)).toEqual('Cat');
-});
-
-it('should select options with outer label', async ({ page, server }) => {
- await page.setContent(`
`);
- await page.selectOption('text=Choose a pet', 'cat');
- expect(await page.$eval('select', select => select.options[select.selectedIndex].text)).toEqual('Cat');
-});
-
it('should respect event bubbling', async ({ page, server }) => {
await page.goto(server.PREFIX + '/input/select.html');
await page.selectOption('select', 'blue');
diff --git a/tests/page/page-set-input-files.spec.ts b/tests/page/page-set-input-files.spec.ts
index c162478938..5bff029501 100644
--- a/tests/page/page-set-input-files.spec.ts
+++ b/tests/page/page-set-input-files.spec.ts
@@ -142,13 +142,6 @@ it('should work @smoke', async ({ page, asset }) => {
expect(await page.$eval('input', input => input.files[0].name)).toBe('file-to-upload.txt');
});
-it('should work with label', async ({ page, asset }) => {
- await page.setContent(`
`);
- await page.setInputFiles('text=Choose a file', asset('file-to-upload.txt'));
- expect(await page.$eval('input', input => input.files.length)).toBe(1);
- expect(await page.$eval('input', input => input.files[0].name)).toBe('file-to-upload.txt');
-});
-
it('should set from memory', async ({ page }) => {
await page.setContent(`
`);
await page.setInputFiles('input', {
diff --git a/tests/page/retarget.spec.ts b/tests/page/retarget.spec.ts
new file mode 100644
index 0000000000..b331949725
--- /dev/null
+++ b/tests/page/retarget.spec.ts
@@ -0,0 +1,219 @@
+/**
+ * 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('
');
+ const span = await page.$('text=Target');
+ let done = false;
+ const promise = span.waitForElementState('enabled').then(() => done = true);
+ await giveItAChanceToResolve(page);
+ expect(done).toBe(false);
+ await span.evaluate(span => (span.parentElement.parentElement as HTMLFieldSetElement).disabled = false);
+ await promise;
+});
+
+it('should wait for enclosing enabled button', async ({ page, server }) => {
+ await page.setContent('');
+ await page.click('text=Click target');
+ expect(await page.evaluate('__CLICKED')).toBe(true);
+});
+
+it('click should climb up to a anchor', async ({ page }) => {
+ // For Firefox its not allowed to return anything: https://bugzilla.mozilla.org/show_bug.cgi?id=1392046
+ // Note the intermediate div - it is necessary, otherwise
is not recognized as a clickable link.
+ await page.setContent(`
`);
+ await page.click('#inner');
+ expect(await page.evaluate('__CLICKED')).toBe(true);
+});
+
+it('click should climb up to a [role=link]', async ({ page }) => {
+ await page.setContent(`
`);
+ await page.click('#inner');
+ expect(await page.evaluate('__CLICKED')).toBe(true);
+});
+
+
+it('should fill input with label', async ({ page }) => {
+ await page.setContent(`
`);
+ await page.fill('text=Fill me', 'some value');
+ expect(await page.$eval('input', input => input.value)).toBe('some value');
+});
+
+it('should fill input with label 2', async ({ page }) => {
+ await page.setContent(`
`);
+ await page.fill('text=Fill me', 'some value');
+ expect(await page.$eval('input', input => input.value)).toBe('some value');
+});
+
+it('should fill input with span inside the label', async ({ page }) => {
+ await page.setContent(`
`);
+ await page.fill('text=Fill me', 'some value');
+ expect(await page.$eval('input', input => input.value)).toBe('some value');
+});
+
+it('should fill input inside the label', async ({ page }) => {
+ await page.setContent(`
`);
+ await page.fill('input', 'some value');
+ expect(await page.$eval('input', input => input.value)).toBe('some value');
+});
+
+it('should fill textarea with label', async ({ page }) => {
+ await page.setContent(`
`);
+ await page.fill('text=Fill me', 'some value');
+ expect(await page.$eval('textarea', textarea => textarea.value)).toBe('some value');
+});
+
+it('should selectOption with sibling label', async ({ page, server }) => {
+ await page.setContent(`
+
`);
+ await page.selectOption('text=Choose a pet', 'cat');
+ expect(await page.$eval('select', select => select.options[select.selectedIndex].text)).toEqual('Cat');
+});
+
+it('should selectOption with outer label', async ({ page, server }) => {
+ await page.setContent(`
`);
+ await page.selectOption('text=Choose a pet', 'cat');
+ expect(await page.$eval('select', select => select.options[select.selectedIndex].text)).toEqual('Cat');
+});
+
+it('setInputFiles should work with label', async ({ page, asset }) => {
+ await page.setContent(`
`);
+ await page.setInputFiles('text=Choose a file', asset('file-to-upload.txt'));
+ expect(await page.$eval('input', input => input.files.length)).toBe(1);
+ expect(await page.$eval('input', input => input.files[0].name)).toBe('file-to-upload.txt');
+});