Implement Basic input API

This patch implements Basic Input api:
- Page.focus(selector) - focuses element with selector
- Page.click(selector) - clicks element with selector
- Page.type(text) - types text into a focused element

Fixed #43.
This commit is contained in:
JoelEinbinder
2017-06-27 18:27:22 -07:00
committed by Andrey Lushnikov
parent 3d90ea38a9
commit d5a91650ae
4 changed files with 139 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>Button test</title>
</head>
<body>
<button onclick="clicked();">Click target</button>
<script>
window.result = 'Was not clicked';
function clicked() {
result = 'Clicked';
}
</script>
</body>
</html>

View File

@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>Textarea test</title>
</head>
<body>
<textarea></textarea>
<script>
window.result = '';
let textarea = document.querySelector('textarea');
textarea.addEventListener('input', () => result = textarea.value, false);
</script>
</body>
</html>

View File

@@ -339,6 +339,27 @@ describe('Puppeteer', function() {
expect(navigatedFrames.length).toBe(1);
}));
});
describe('input', function() {
it('should click the button', SX(async function() {
await page.navigate(STATIC_PREFIX + '/input/button.html');
await page.click('button');
expect(await page.evaluate(() => result)).toBe('Clicked');
}));
it('should type into the textarea', SX(async function() {
await page.navigate(STATIC_PREFIX + '/input/textarea.html');
await page.focus('textarea');
await page.type('Type in this text!');
expect(await page.evaluate(() => result)).toBe('Type in this text!');
}));
it('should click the button after navigation ', SX(async function() {
await page.navigate(STATIC_PREFIX + '/input/button.html');
await page.click('button');
await page.navigate(STATIC_PREFIX + '/input/button.html');
await page.click('button');
expect(await page.evaluate(() => result)).toBe('Clicked');
}));
});
});
// Since Jasmine doesn't like async functions, they should be wrapped