-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[java][bidi]: add BiDi method BrowsingContext.setViewport(null, null) to reset the mobile emulation mode
#16524
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
base: trunk
Are you sure you want to change the base?
Conversation
BrowsingContext.resetViewport
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||||
Implementation detail: according to BiDi spec (https://www.w3.org/TR/webdriver-bidi/#command-browsingContext-setViewport), we have to call method "setViewport" with "viewport" parameter equal to "null".
1263bc6 to
328267e
Compare
|
There is no |
|
I know :)
If we want Java api to exactly reflect BiDi API, then we should add method Look, currently we have two methods: public void setViewport(double width, double height) { ... }
public void setViewport(double width, double height, double devicePixelRatio) { ... }Or should we add method |
|
If Believe me, in .NET I introduced so many syntax sugar (like aliases), and now I am removing it. Low-level API should represent available API withoout addition magic (Selenium dreams it might auto-generated). But it is as is, I propose to not introduce "aliases". |
|
@nvborisenko Point taken. |
BrowsingContext.resetViewportBrowsingContext.resetViewport
432f797 to
ae3e084
Compare
BrowsingContext.resetViewportBrowsingContext.setViewport(null, null) to reset the mobile emulation mode
Please update the PR description to reflect that. |
done. |
…esetting mobile emulation mode
920dd54 to
97af1c4
Compare
User description
💥 What does this PR do?
This PR the existing method
BrowsingContext.setViewport(width, height)so that it allows 'null' arguments now.Calling
BrowsingContext.setViewport(null, null)reverts the viewport size to the initial size (in other words, disables "mobile emulation" mode and enables "desktop" mode).🔧 Implementation Notes
According to BiDi spec, we have to call method "setViewport" with "viewport" parameter equal to "null".
That's why I had to replace new APIs
Map.ofandMap.copyOf(which does not allownullvalues) by good old APIs (new HashMap()) that allownullvalues.🔄 Types of changes
PR Type
Enhancement, Tests
Description
Mark all 3 arguments of BiDi method
BrowsingContext.setViewport()as nullable (nullmeans reverting viewport to initial size)Replace
Map.copyOf()withHashMapto support null values in Command parametersAdd
toString()method toBrowsingContextInfofor better debuggingRefactor viewport tests with helper methods and improved assertions
Update test assertions to use modern AssertJ API patterns
Diagram Walkthrough
File Walkthrough
Command.java
Support null values in Command parametersjava/src/org/openqa/selenium/bidi/Command.java
Map.copyOf()withunmodifiableMap(new HashMap<>())to allownull parameter values
Collections.unmodifiableMapandHashMapspec
BrowsingContext.java
Make setViewport(width, height) BiDi method arguments nullablejava/src/org/openqa/selenium/bidi/browsingcontext/BrowsingContext.java
resetViewport()method nullableHashMapto construct parameters allowing null values per BiDispecification
BrowsingContextInfo.java
Add toString() method for debuggingjava/src/org/openqa/selenium/bidi/browsingcontext/BrowsingContextInfo.java
toString()override method for better object representationBrowsingContextTest.java
Refactor viewport tests and modernize assertionsjava/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextTest.java
getViewportSize()andgetDevicePixelRatio()toreduce code duplication
setViewport(null, null)functionality verifying viewport returnsto initial size
Assertionsinstead ofAssertionsForClassTypes)assertThatExceptionOfType()withassertThatThrownBy()and addmessage pattern matching
hasSize(),isNotEmpty(), andisEqualTo(newDimension())patternsCONTEXT_NOT_FOUNDpattern constant for exception messagevalidation