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

fix: correctly screen elements inside iframes #856

Merged
merged 1 commit into from
Mar 7, 2024

Conversation

DudaGod
Copy link
Member

@DudaGod DudaGod commented Mar 6, 2024

What is done

getBoundingClientRect inside iframe returns DOMRect only inside this iframe and don't know nothing about offsets between this iframe and viewport. Therefore, a solution has been implemented that takes into account the indentation of the iframe

Fix issue - #349

@DudaGod DudaGod force-pushed the HERMIONE-636.fix_assert_elements_in_iframe branch from 17d0095 to 15e8488 Compare March 6, 2024 20:24
viewportHeight = document.documentElement.clientHeight,
documentWidth = document.documentElement.scrollWidth,
documentHeight = document.documentElement.scrollHeight,
var mainDocumentElem = util.getMainDocumentElem(),
Copy link
Member Author

Choose a reason for hiding this comment

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

If user use command browser.switchToFrame(<iframe>) in test then document.documentElement references to the document inside frame which has its own dimensions. It can't be used because getBoundingClientRect inside iframe returns rect only inside this iframe.

So I should use main document in order to correctly screen element inside iframe.

@@ -164,3 +164,76 @@ exports.getAbsoluteClientRect = function getAbsoluteClientRect(element, opts) {

return clientRect.translate(util.getScrollLeft(opts.scrollElem), util.getScrollTop(opts.scrollElem));
};

function getNestedBoundingClientRect(node, boundaryWindow) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Found solution in this package - https://github.com/suchipi/get-nested-bounding-client-rect/tree/master. The basic logic is taken from it with some modification for our use case.

@DudaGod DudaGod force-pushed the HERMIONE-636.fix_assert_elements_in_iframe branch from ce77d15 to 16bc710 Compare March 7, 2024 11:45
Copy link
Member

@KuznetsovRoman KuznetsovRoman left a comment

Choose a reason for hiding this comment

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

LGTM

@DudaGod DudaGod merged commit 9ecf164 into master Mar 7, 2024
2 checks passed
@DudaGod DudaGod deleted the HERMIONE-636.fix_assert_elements_in_iframe branch March 7, 2024 14:33
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.

None yet

2 participants