-
-
Notifications
You must be signed in to change notification settings - Fork 144
Enable mobile emulation #527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
duncan-bayne
wants to merge
12
commits into
rubycdp:main
Choose a base branch
from
radiopaedia:94-expose-mobile
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
dd15f1a
Add ruby-lsp as an optional dependency
duncan-bayne 42184d6
Add debug Gem
duncan-bayne 6312a9d
Add mobile support to Page
duncan-bayne a071969
Add documentation for mobile option
duncan-bayne 33b16bd
Add mobile to browser options
duncan-bayne d950aad
Override the viewport size when mobile: true
duncan-bayne 6753f84
Update README
duncan-bayne 024dcc8
Fix Rubocop offenses
duncan-bayne 3dd7cc7
Tweak README to include mobile example
duncan-bayne 5524262
Revert "Add debug Gem"
duncan-bayne 1560ecd
Revert "Add ruby-lsp as an optional dependency"
duncan-bayne bd578fb
Remove automatic resizing from Ferrum
duncan-bayne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -235,4 +235,48 @@ | |
wait_for { message_b }.to eq("goodbye") | ||
end | ||
end | ||
|
||
describe "#resize" do | ||
def body_size | ||
{ | ||
height: page.evaluate("document.body.clientHeight"), | ||
width: page.evaluate("document.body.clientWidth") | ||
} | ||
end | ||
|
||
def is_mobile? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't really test whether mobile emulation is enabled, but I couldn't find a good way of doing that directly via JavaScript evaluation. So we use touch emulation as a proxy. |
||
page.evaluate("'ontouchstart' in window || navigator.maxTouchPoints > 0") | ||
end | ||
|
||
before do | ||
page.go_to("/") | ||
end | ||
|
||
context "given a different size" do | ||
it "resizes the page" do | ||
expect { page.resize(width: 2000, height: 1000) }.to change { body_size }.to(width: 2000, height: 1000) | ||
end | ||
end | ||
|
||
context "given a zero height" do | ||
it "does not change the height" do | ||
expect { page.resize(width: 2000, height: 0) }.not_to(change { body_size[:height] }) | ||
end | ||
end | ||
|
||
context "given a zero width" do | ||
it "does not change the width" do | ||
expect { page.resize(width: 0, height: 1000) }.not_to(change { body_size[:width] }) | ||
end | ||
end | ||
|
||
context "when mobile is true" do | ||
it "enables mobile emulation in the browser" do | ||
expect do | ||
page.resize(width: 0, height: 0, mobile: true) | ||
page.reload | ||
end.to change { is_mobile? }.to(true) | ||
end | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need flag for browser instantiation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My intent was to expose this via driver registration, as per Selenium.
I have a draft PR open for Cuprite that uses this; see e.g.:
https://github.com/rubycdp/cuprite/pull/292/files#diff-89eebfcbc0f14b6d989517837ca1e94fce4e2ce9a03233641cd936f2b8d2ed94