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 ability to disable animations in assertView #794

Merged
merged 1 commit into from
Oct 19, 2023

Conversation

KuznetsovRoman
Copy link
Member

Что сделано

Добавил возможность отключать анимации при вызове assertView

}
};

exports.cleanupFrameAnimations = function cleanupFrameAnimations() {
Copy link
Member Author

Choose a reason for hiding this comment

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

В процессе отключения анимации, в руты вставляются style-элементы.
Эта функция __cleanupAnimation убирает из DOM-дерева эти элементы

@@ -125,6 +147,43 @@ function prepareScreenshotUnsafe(areas, opts) {
};
}

function disableFrameAnimationsUnsafe() {
Copy link
Member Author

Choose a reason for hiding this comment

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

frame - потому что это происходит только в текущем фрейме (iframe тут не трогаются)

@@ -125,6 +147,43 @@ function prepareScreenshotUnsafe(areas, opts) {
};
}

function disableFrameAnimationsUnsafe() {
var everyElementSelector = "*:not(#hermione-q.hermione-w.hermione-e.hermione-r.hermione-t.hermione-y)";
var everythingSelector = ["", "::before", "::after"]
Copy link
Member Author

Choose a reason for hiding this comment

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

По итогу тут получаем сильный селектор, на который матчатся все элементы, ::before и ::after

Comment on lines +165 to +171
"{",
" animation-delay: 0ms !important;",
" animation-duration: 0ms !important;",
" animation-timing-function: step-start !important;",
" transition-timing-function: step-start !important;",
" scroll-behavior: auto !important;",
"}"
Copy link
Member Author

Choose a reason for hiding this comment

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

отключаем анимации, транзишены и делаем "грубый" скролл

].join("\n");

root.appendChild(styleElement);
styleElements.push(styleElement);
Copy link
Member Author

Choose a reason for hiding this comment

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

В этом массиве хранятся style-элементы, которые удаляются из дерева при последующем вызове window.__cleanupAnimation

const currImgInst = await screenShooter.capture(page, screenshoterOpts);
const currImgInst = await screenShooter
.capture(page, screenshoterOpts)
.finally(() => browser.cleanupScreenshot(opts));
Copy link
Member Author

Choose a reason for hiding this comment

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

prepareScreenshot имеет сайд-эффекты в виде добавленных в DOM-дерево элементов. Тут эти сайд-эффекты чистим

Comment on lines +78 to +90
// https://github.com/webdriverio/webdriverio/issues/11396
if (this._config.automationProtocol === "webdriver" && opts.disableAnimation) {
await this._disableIframeAnimations();
}
Copy link
Member Author

Choose a reason for hiding this comment

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

В webdriver можем отключить анимацию во всех айфреймах. В devtools они отключаются только в текущем фрейме
Отключение анимации для родительского фрейма происходит в самом prepareScreenshot

@@ -13,6 +13,7 @@ module.exports = {
diffColor: "#ff00ff",
tolerance: 2.3,
antialiasingTolerance: 4,
disableAnimation: true,
Copy link
Member Author

Choose a reason for hiding this comment

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

breaking change

Copy link
Member

Choose a reason for hiding this comment

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

Для hermione@7 нужно выставить в false

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.

в остальном /ok

@@ -125,6 +147,43 @@ function prepareScreenshotUnsafe(areas, opts) {
};
}

function disableFrameAnimationsUnsafe() {
var everyElementSelector = "*:not(#hermione-q.hermione-w.hermione-e.hermione-r.hermione-t.hermione-y)";
Copy link
Member

Choose a reason for hiding this comment

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

А почему hermione-q - это id, а остальные hermione-* - это классы? Или так и задумано?

Copy link
Member Author

Choose a reason for hiding this comment

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

Это не имеет значения. Главное, чтоб у селектора был и айдишник, и несколько классов, тогда он будет специфичнее даже селектора по айдишнику

@@ -13,6 +13,7 @@ module.exports = {
diffColor: "#ff00ff",
tolerance: 2.3,
antialiasingTolerance: 4,
disableAnimation: true,
Copy link
Member

Choose a reason for hiding this comment

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

Для hermione@7 нужно выставить в false

return this._clientBridge.call("cleanupFrameAnimations");
}

async _cleanupIframeAnimations() {
Copy link
Member

Choose a reason for hiding this comment

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

Я бы для этого метода и _disableIframeAnimations написал хелпер. Они же отличаются только вызовом одной функции, а все остальное в них одинаковое.

@KuznetsovRoman KuznetsovRoman force-pushed the HERMIONE-1129 branch 2 times, most recently from be854ca to 087f111 Compare October 19, 2023 08:52
BREAKING CHANGE: assertView now disables animations by default
@KuznetsovRoman KuznetsovRoman merged commit bb4a8d6 into master Oct 19, 2023
2 checks passed
@KuznetsovRoman KuznetsovRoman deleted the HERMIONE-1129 branch October 19, 2023 09:05
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