Skip to content

Commit 52ae218

Browse files
authored
fix(fill): allow filling more input types (microsoft#4563)
This includes invalid types that are no recognized by the browser.
1 parent 1fa7e86 commit 52ae218

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

src/server/injected/injectedScript.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ export class InjectedScript {
281281
}
282282
if (element.nodeName.toLowerCase() === 'input') {
283283
const input = element as HTMLInputElement;
284-
const type = (input.getAttribute('type') || '').toLowerCase();
285-
const kDateTypes = new Set(['date', 'time', 'datetime', 'datetime-local']);
284+
const type = input.type.toLowerCase();
285+
const kDateTypes = new Set(['date', 'time', 'datetime', 'datetime-local', 'month', 'week']);
286286
const kTextInputTypes = new Set(['', 'email', 'number', 'password', 'search', 'tel', 'text', 'url']);
287287
if (!kTextInputTypes.has(type) && !kDateTypes.has(type)) {
288288
progress.log(` input of type "${type}" cannot be filled`);

test/page-fill.spec.ts

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ it('should fill textarea with label', async ({page}) => {
5454

5555
it('should throw on unsupported inputs', async ({page, server}) => {
5656
await page.goto(server.PREFIX + '/input/textarea.html');
57-
for (const type of ['color', 'file']) {
57+
for (const type of ['button', 'checkbox', 'file', 'image', 'radio', 'range', 'reset', 'submit']) {
5858
await page.$eval('input', (input, type) => input.setAttribute('type', type), type);
5959
let error = null;
6060
await page.fill('input', '').catch(e => error = e);
@@ -64,7 +64,7 @@ it('should throw on unsupported inputs', async ({page, server}) => {
6464

6565
it('should fill different input types', async ({page, server}) => {
6666
await page.goto(server.PREFIX + '/input/textarea.html');
67-
for (const type of ['password', 'search', 'tel', 'text', 'url']) {
67+
for (const type of ['password', 'search', 'tel', 'text', 'url', 'invalid-type']) {
6868
await page.$eval('input', (input, type) => input.setAttribute('type', type), type);
6969
await page.fill('input', 'text ' + type);
7070
expect(await page.evaluate(() => window['result'])).toBe('text ' + type);
@@ -79,7 +79,7 @@ it('should fill date input after clicking', async ({page, server}) => {
7979
});
8080

8181
it('should throw on incorrect date', (test, { browserName }) => {
82-
test.skip(browserName === 'webkit');
82+
test.skip(browserName === 'webkit', 'WebKit does not support date inputs');
8383
}, async ({page}) => {
8484
await page.setContent('<input type=date>');
8585
const error = await page.fill('input', '2020-13-05').catch(e => e);
@@ -92,8 +92,36 @@ it('should fill time input', async ({page}) => {
9292
expect(await page.$eval('input', input => input.value)).toBe('13:15');
9393
});
9494

95+
it('should fill month input', async ({page}) => {
96+
await page.setContent('<input type=month>');
97+
await page.fill('input', '2020-07');
98+
expect(await page.$eval('input', input => input.value)).toBe('2020-07');
99+
});
100+
101+
it('should throw on incorrect month', (test, { browserName }) => {
102+
test.skip(browserName !== 'chromium', 'Only Chromium supports month inputs');
103+
}, async ({page}) => {
104+
await page.setContent('<input type=month>');
105+
const error = await page.fill('input', '2020-13').catch(e => e);
106+
expect(error.message).toContain('Malformed value');
107+
});
108+
109+
it('should fill week input', async ({page}) => {
110+
await page.setContent('<input type=week>');
111+
await page.fill('input', '2020-W50');
112+
expect(await page.$eval('input', input => input.value)).toBe('2020-W50');
113+
});
114+
115+
it('should throw on incorrect week', (test, { browserName }) => {
116+
test.skip(browserName !== 'chromium', 'Only Chromium supports week inputs');
117+
}, async ({page}) => {
118+
await page.setContent('<input type=week>');
119+
const error = await page.fill('input', '2020-123').catch(e => e);
120+
expect(error.message).toContain('Malformed value');
121+
});
122+
95123
it('should throw on incorrect time', (test, { browserName }) => {
96-
test.skip(browserName === 'webkit');
124+
test.skip(browserName === 'webkit', 'WebKit does not support time inputs');
97125
}, async ({page}) => {
98126
await page.setContent('<input type=time>');
99127
const error = await page.fill('input', '25:05').catch(e => e);
@@ -107,7 +135,7 @@ it('should fill datetime-local input', async ({page, server}) => {
107135
});
108136

109137
it('should throw on incorrect datetime-local', (test, { browserName }) => {
110-
test.skip(browserName === 'webkit' || browserName === 'firefox');
138+
test.skip(browserName !== 'chromium', 'Only Chromium supports datetime-local inputs');
111139
}, async ({page, server}) => {
112140
await page.setContent('<input type=datetime-local>');
113141
const error = await page.fill('input', 'abc').catch(e => e);

0 commit comments

Comments
 (0)