waitForStable
等待元素在指定毫秒數內穩定(不處於動畫狀態)。如果選擇器匹配 DOM 中至少一個穩定的元素,則返回 true,否則拋出錯誤。如果 reverse 標誌為 true,則當選擇器不匹配任何穩定元素時,命令將返回 true。
注意:最好禁用動畫,而不是使用此命令
用法
$(selector).waitForStable({ timeout, reverse, timeoutMsg, interval })
參數
名稱 | 類型 | 詳細資料 |
---|---|---|
options 可選 | WaitForOptions | waitForStable 選項(可選) |
options.timeout 可選 | 數字 | 以毫秒為單位表示的時間(預設設定基於 waitforTimeout 設定值) |
options.reverse 可選 | 布林值 | 如果為 true,則等待相反的結果(預設:false) |
options.timeoutMsg 可選 | 字串 | 如果存在,則覆蓋預設錯誤訊息 |
options.interval 可選 | 數字 | 檢查之間的間隔(預設:waitforInterval ) |
範例
index.html
<head>
<style>
div {
width: 200px;
height: 200px;
background-color: red;
}
#has-animation {
animation: 3s 0s alternate slidein;
}
@keyframes slidein {
from {
margin-left: 100%;
width: 300%;
}
to {
margin-left: 0%;
width: 100%;
}
}
</style>
</head>
<body>
<div #has-animation></div>
<div #has-no-animation></div>
</body>
waitForStable.js
it('should detect that element is instable and will wait for the element to become stable', async () => {
const elem = await $('#has-animation')
await elem.waitForStable({ timeout: 3000 });
});
it('should detect that element is stable and will not wait', async () => {
const elem = await $('#has-no-animation')
await elem.waitForStable();
});