小编A.G*_*ens的帖子

将现有屏幕截图与赛普拉斯中的实时应用程序进行比较时出现错误

如果我确实将屏幕截图与实时应用程序进行比较,那么它就会失败。最好的方法是什么以及如何比较 Cypress 中的屏幕截图

输出:在 cypress 上获取错误日志

在此输入图像描述

用于比较屏幕截图的已安装依赖项

npm install --save-dev cypress-image-snapshot @types/cypress-image-snapshot

Run Code Online (Sandbox Code Playgroud)
// code on commond.js file.
const compareSnapshotCommand = require('cypress-image-diff-js/dist/command')
compareSnapshotCommand();

 // code on cypress.config.json 
 const getCompareSnapshotsPlugin = require('cypress-image-diff-js/dist/plugin')
      getCompareSnapshotsPlugin(on, config)

// .js test scenario on test file 
describe('compare the homepage screen shot with the application homepage', () => {
    it('should compare the homepage', () => {
        cy.visit("/");
        cy.compareSnapshot('fixtures/healthcaresuccess-page.png', 0.001);
    }
Run Code Online (Sandbox Code Playgroud)

screenshot cypress

7
推荐指数
1
解决办法
853
查看次数

读取 cypress 表中的值并给我最新的值

我想在 Cypress 中检查名称文档列的所有行中的内容是否相同。比方说

名称 文件 签发日期
戈尔 2023年6月21日
戈尔 2023年5月30日

该表没有固定的行数。

在此输入图像描述

附加问题:如何检查最新的(发布日期列)是否位于顶部?

html-table cypress

0
推荐指数
1
解决办法
354
查看次数

如何使用 cypress 在 if 条件下传递断言,而不在断言失败时停止执行

我试图将断言传递给 if 条件,并在满足条件时执行一个逻辑,在条件失败时执行另一个逻辑。

由于测试因断言失败而失败,我无法达到预期的结果。

我尝试了以下...

if(cy.get("div").length \> 0) {
  cy.log("print this")
} else {
  cy.log("print this")
}
Run Code Online (Sandbox Code Playgroud)

或者

if(cy.get("div").should('have.length.greaterThan', 0) {
  cy.log("print this")
} else {
  cy.log("print this")
}
Run Code Online (Sandbox Code Playgroud)

javascript automation cypress cypress-conditional-testing

0
推荐指数
2
解决办法
254
查看次数

Bash 脚本无法执行 Cypress 的 NPM 脚本

我制作的 bash 脚本遇到了问题。对于上下文,我编写了 NPM 脚本来在命令行上运行 Cypress 测试。我的目标是拥有一个 bash 脚本来运行每个 NPM 脚本,并在命令行中执行 Cypress。另外供参考,我的 script.sh 位于项目文件夹中。

如果我从终端手动运行 NPM 脚本,就没有问题。赛普拉斯有效。这是我拥有的 NPM 脚本的示例:

"cypress:window": "./node_modules/.bin/cypress open",
Run Code Online (Sandbox Code Playgroud)

问题是当我将这些命令放入 bash 脚本中时。现在,当 script.sh 运行时,它以 code=1 执行,并且实际上根本不运行 Cypress。我的 script.sh 只是:

npm run cypress:window
Run Code Online (Sandbox Code Playgroud)

bash sh node.js npm cypress

-1
推荐指数
1
解决办法
411
查看次数