|
| 1 | +/** |
| 2 | + * Copyright 2023 Google Inc. All rights reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import expect from 'expect'; |
| 18 | + |
| 19 | +import {getTestState, setupTestBrowserHooks} from './mocha-utils.js'; |
| 20 | + |
| 21 | +describe('Autofill', function () { |
| 22 | + setupTestBrowserHooks(); |
| 23 | + describe('ElementHandle.autofill', () => { |
| 24 | + it('should fill out a credit card', async () => { |
| 25 | + const {page, server} = await getTestState(); |
| 26 | + await page.goto(server.PREFIX + '/credit-card.html'); |
| 27 | + const name = await page.waitForSelector('#name'); |
| 28 | + await name!.autofill({ |
| 29 | + creditCard: { |
| 30 | + number: '4444444444444444', |
| 31 | + name: 'John Smith', |
| 32 | + expiryMonth: '01', |
| 33 | + expiryYear: '2030', |
| 34 | + cvc: '123', |
| 35 | + }, |
| 36 | + }); |
| 37 | + expect( |
| 38 | + await page.evaluate(() => { |
| 39 | + const result = []; |
| 40 | + for (const el of document.querySelectorAll('input')) { |
| 41 | + result.push(el.value); |
| 42 | + } |
| 43 | + return result.join(','); |
| 44 | + }) |
| 45 | + ).toBe('John Smith,4444444444444444,01,2030,Submit'); |
| 46 | + }); |
| 47 | + }); |
| 48 | +}); |
0 commit comments