Skip to content
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

feat: add nativeElementsSize options #26

Conversation

aakapustin
Copy link
Contributor

Added option nativeElementsSize to define the expected sizes of native elements. This will prevent switching to the native context before taking a screenshot

@aakapustin aakapustin changed the title feat: add _nativeElementsSize options feat: add nativeElementsSize options Apr 1, 2024
Copy link
Member

@DudaGod DudaGod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job. It remains to correct the config options and merge everything into one commit.

@@ -42,6 +48,60 @@ const getParser = () => {
? thr('Each browser must have "commands" option')
: assertArrayOfStrings(value, 'commands');
}
}),
nativeElementsSize: section({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any documentation for this option. Let's add it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation added at README

validate: (value, _config, currentNode) => {
if (
(!_.isNull(value) && !_.isNumber(value)) ||
(_.isNull(value) && !isNativeElementsSizeEmpty(currentNode))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if one of the values is declared (for example bottomToolbarHeight) then in this case we will fall here with error "topToolbarHeight" must be a number but got ....

Why not just declare nativeElementsSize as option (without section) and check each option inside validate? You can look at this example - https://github.com/gemini-testing/hermione/blob/master/src/config/browser-options.js#L160-L173

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, nativeElementsSize declaration is updated

throw new Error(`"webviewWidth" must be a number but got ${value === null ? 'null' : typeof value}`);
}
}
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To my mind these options must looks like:

nativeElementsSize: {
  topToolbar: {width, height}, // or 100x200,
  bottomToolbar: {width, height}, // or 100x200,
  webview: {width, height}, // or 100x200,
}

This will reduce the number of options and if the width is needed, you will not need to add another option topToolbarWidth. What do you think?

Example how we validate windowSize in hermione - https://github.com/gemini-testing/hermione/blob/master/src/config/browser-options.js#L258-L274

this._nativeElementsSize.topToolbarHeight &&
this._nativeElementsSize.bottomToolbarHeight &&
this._nativeElementsSize.webviewHeight &&
this._nativeElementsSize.webviewWidth
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you check every option like that? Looks like in you validate you can just check that this._nativeElementsSize is not empty.

left: Math.max(Math.floor((webviewWidth - bodyWidth) / 2 * pixelRatio), 0),
top: Math.max(Math.floor(topToolbarHeight * pixelRatio), 0)
};
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we can invert the condition to reduce the amount of nested code

) {
let {topToolbarHeight, bottomToolbarHeight, webviewWidth, webviewHeight} = this._nativeElementsSize;

if (await browser.getOrientation() === 'LANDSCAPE') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

@aakapustin aakapustin force-pushed the HERMIONE-1405.expected_native_elements_size branch from db564a7 to 096abe9 Compare April 2, 2024 18:52
@aakapustin aakapustin requested a review from DudaGod April 2, 2024 19:28
Copy link
Member

@DudaGod DudaGod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything else is fine.

height: 654,
width: 390
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we will need to choose default values for each version of safari in some next releases. In order not to force the user to specify them.

README.md Outdated
@@ -20,6 +20,17 @@ Plugin has following configuration:
* **enabled** (optional) `Boolean` – enable/disable the plugin, by default plugin is enabled;
* **browsers** (required) `Object` - the list of browsers to use for wrap commands;
* **commands** (required) `Array` - commands which will be wrapped.
* **nativeElementsSize** (optional) `Object` - the map of native elements sizes for the browser;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we specify that the values should be specified without taking into account the pixel ratio?
I would also add that when specifying these values, the speed of taking screenshots increases.


describe('"calcWebViewCoordsNative" method', () => {
it('should use _nativeElementsSize if exists', async () => {
sinon.stub(utils, '_nativeElementsSize').value({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use private fields in test files. Here you just need to call mkUtilsStub with the necessary arguments (send nativeElementsSize as second argument`).

I didn't notice this problem at the first review.

@aakapustin aakapustin force-pushed the HERMIONE-1405.expected_native_elements_size branch from 096abe9 to db05d6f Compare April 8, 2024 08:47
@DudaGod DudaGod force-pushed the HERMIONE-1405.expected_native_elements_size branch from db05d6f to 56a7091 Compare April 8, 2024 10:42
@DudaGod DudaGod merged commit 0fbd984 into gemini-testing:master Apr 8, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants