Testing 使用TestCafe评估颜色变化

Testing 使用TestCafe评估颜色变化,testing,css-selectors,automated-tests,e2e-testing,testcafe,Testing,Css Selectors,Automated Tests,E2e Testing,Testcafe,要独立于静态文本,我需要检查选择器的RGB值。 我发现 将要更改的元素为: <div class="cl-asset-wfstate" style="background-color: rgb(244, 159, 79);"></div> <div class="cl-asset-wfstate" style="background-color: rgb(92, 195, 55);"></div> 但这是行不通的。这个断言永远不会得到解决。 有

要独立于静态文本,我需要检查选择器的RGB值。 我发现

将要更改的元素为:

<div class="cl-asset-wfstate" style="background-color: rgb(244, 159, 79);"></div>

<div class="cl-asset-wfstate" style="background-color: rgb(92, 195, 55);"></div>
但这是行不通的。这个断言永远不会得到解决。
有什么建议吗?

如果我理解正确,您有
div
元素,该元素在测试执行期间会更改其颜色。 如果是,则不需要执行此行:

const bgcolour=wait选择器('div.cl-asset-wfstate')。getStyleProperty('background-color')

因为在这种情况下,
bgcolour
变量将包含一个不变的值

我修改了您的示例以演示如何实现您的场景:

HTML:


另请参见:

您是否从断言中收到任何错误消息?如果是这样,请添加它:)要添加到我以前的注释中,我已经尝试了-
。getStyleProperty
正在返回正确的值,并且断言正在按预期传递。您可能会遇到与颜色断言无关的其他问题基于我的代码,代码将等待背景颜色为rgb(9219555)。但如果没有rgb(9219555),它将失败。意味着测试用例将停止。
<div class="cl-asset-wfstate" style="background-color: rgb(244, 159, 79);"></div>

<div class="cl-asset-wfstate" style="background-color: rgb(92, 195, 55);"></div>
const bgcolour = await Selector('div.cl-asset-wfstate').getStyleProperty('background-color');
await t.expect(bgcolour).eql('rgb(92, 195, 55)', {timeout: 5000})
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<div class="cl-asset-wfstate" style="background-color: rgb(0, 0, 0);">test</div>

<script>
    setTimeout(function () {
        document.querySelector('div').style.backgroundColor = 'rgb(92, 195, 55)';
    }, 3000);
</script>
</body>
</html>
import { Selector } from 'testcafe';

fixture `fixture`
    .page `../pages/index.html`;

test('1', async t => {
    const selector = Selector('div.cl-asset-wfstate');
    const opacity  = await selector.getStyleProperty('opacity');

    await t.expect(opacity).eql('1', {timeout: 5000});
    await t.expect(selector.getStyleProperty('background-color')).eql('rgb(92, 195, 55)', {timeout: 5000})
});