Skip to content

Commit

Permalink
Merge pull request #13 from YusukeIwaki/keyboard_spec
Browse files Browse the repository at this point in the history
add RSpec: keyboard
  • Loading branch information
YusukeIwaki authored Jul 28, 2020
2 parents 8d4f436 + 950617e commit 8499070
Show file tree
Hide file tree
Showing 6 changed files with 421 additions and 20 deletions.
5 changes: 3 additions & 2 deletions lib/puppeteer/element_handle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,11 @@ def type_text(text, delay: nil)
define_async_method :async_type_text

# @param key [String]
# @param text [String]
# @param delay [number|nil]
def press(key, delay: nil)
def press(key, delay: nil, text: nil)
focus
@page.keyboard.press(key, delay: delay)
@page.keyboard.press(key, delay: delay, text: text)
end

define_async_method :async_press
Expand Down
5 changes: 3 additions & 2 deletions lib/puppeteer/keyboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,10 @@ def type_text(text, delay: nil)
define_async_method :async_type_text

# @param key [String]
# @param text [String]
# @return [Future]
def press(key, delay: nil)
down(key)
def press(key, delay: nil, text: nil)
down(key, text: text)
if delay
sleep(delay.to_i / 1000.0)
end
Expand Down
20 changes: 4 additions & 16 deletions spec/integration/click_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@
</head>
<body>
<textarea></textarea>
<script src='mouse-helper.js'></script>
<script>
globalThis.result = '';
globalThis.textarea = document.querySelector('textarea');
Expand Down Expand Up @@ -425,7 +424,6 @@
<title>Scrollable test</title>
</head>
<body>
<script src='mouse-helper.js'></script>
<script>
for (let i = 0; i < 100; i++) {
let button = document.createElement('button');
Expand Down Expand Up @@ -539,7 +537,6 @@
<title>Rotated button test</title>
</head>
<body>
<script src="mouse-helper.js"></script>
<button onclick="clicked();">Click target</button>
<style>
button {
Expand Down Expand Up @@ -583,19 +580,6 @@
end
end

def attach_frame(page, frame_id, url)
js = <<~JAVASCRIPT
async function attachFrame(frameId, url) {
const frame = document.createElement('iframe');
frame.src = url;
frame.id = frameId;
document.body.appendChild(frame);
await new Promise((x) => (frame.onload = x));
return frame;
}
JAVASCRIPT
page.evaluate_handle(js, frame_id, url).as_element.content_frame
end

context 'with button inside an iframe' do
sinatra do
Expand Down Expand Up @@ -624,6 +608,8 @@ def attach_frame(page, frame_id, url)
end

context 'without device scale factor' do
include Utils::AttachFrame

before {
page.goto('http://127.0.0.1:4567/')
attach_frame(page, 'button-test', '/button')
Expand All @@ -637,6 +623,8 @@ def attach_frame(page, frame_id, url)
end

context 'with device scale factor' do
include Utils::AttachFrame

before {
page.viewport = Puppeteer::Viewport.new(width: 400, height: 400, device_scale_factor: 5)
unless page.evaluate('() => window.devicePixelRatio') == 5
Expand Down
Loading

0 comments on commit 8499070

Please sign in to comment.