autofill-spec.ts 1020 B

12345678910111213141516171819202122232425262728
  1. import { BrowserWindow } from 'electron';
  2. import * as path from 'path';
  3. import { delay } from './spec-helpers';
  4. import { expect } from 'chai';
  5. import { closeAllWindows } from './window-helpers';
  6. const fixturesPath = path.resolve(__dirname, 'fixtures');
  7. describe('autofill', () => {
  8. afterEach(closeAllWindows);
  9. it('can be selected via keyboard', async () => {
  10. const w = new BrowserWindow({ show: true });
  11. await w.loadFile(path.join(fixturesPath, 'pages', 'datalist.html'));
  12. w.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'Tab' });
  13. const inputText = 'clap';
  14. for (const keyCode of inputText) {
  15. w.webContents.sendInputEvent({ type: 'char', keyCode });
  16. await delay(100);
  17. }
  18. w.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'Down' });
  19. w.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'Enter' });
  20. const value = await w.webContents.executeJavaScript("document.querySelector('input').value");
  21. expect(value).to.equal('Eric Clapton');
  22. });
  23. });