mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
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:
committed by
Andrey Lushnikov
parent
3d90ea38a9
commit
d5a91650ae
15
test/assets/input/button.html
Normal file
15
test/assets/input/button.html
Normal 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>
|
||||
14
test/assets/input/textarea.html
Normal file
14
test/assets/input/textarea.html
Normal 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>
|
||||
21
test/test.js
21
test/test.js
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user