如何在 Cypress 中打开现有的 Cypress 测试。

huangapple go评论74阅读模式
英文:

How to open existing cypress tests in cypress

问题

如何在 Cypress 中打开现有的 Cypress 测试?
我有一个项目,已经有一些 Cypress 测试,但当我安装 Cypress 来获取所有项目的测试时,它创建了另一个 Cypress 文件夹,并且从未看到旧项目的测试?

谢谢

Zombie 在评论中说

import { defineConfig } from "cypress"; 

export default defineConfig({ 
  chromeWebSecurity: false, 
  screenshotOnRunFailure: true, 
  env: { PASSWORD: "xxx", }, 
  e2e: { url: "xxx", }, 
});
英文:

How can I open an existing cypress tests in cypress?
I have a project which already have some cypress tests but when I am installing cypress to get all the project's tests it is creating another cypress folder and never seeing the old projects tests?

Thank you

Zombie says in comments

import { defineConfig } from "cypress"; 

export default defineConfig({ 
  chromeWebSecurity: false, 
  screenshotOnRunFailure: true, 
  env: { PASSWORD: "xxx", }, 
  e2e: { url: "xxx", }, 
});

答案1

得分: 2

修复当前项目可能是一项艰巨的任务。

如果我是你,我会创建一个全新的空白项目,使用最新的 Cypress,并逐一将测试迁移到其中。

  • 创建一个新文件夹

  • 决定是否需要TypeScript,如果需要,请首先安装它

  • 安装 Cypress

  • 在没有测试或配置的情况下,打开 Cypress GUI 并允许其设置配置和支持文件夹

  • 当提供示例规范时,添加示例规范,并运行它 - 现在你的 Cypress 框架已激活

  • 将新配置与旧配置进行比较,尽量不要复制会破坏新配置的任何内容,然后再次运行示例测试以确保它仍然有效

  • 从旧项目中复制最简单的规范,

    • 进行测试,
    • 重复进行其他规范

然后,您可以针对每个无法正常工作的测试在Stack Overflow上提出具体问题,不需要猜测在旧项目中可能遇到的问题。

此外,我建议只在所有测试在本地正常工作后再添加CI

英文:

Fixing the current project will probably be an arduous task.

If I were you I'd create a new blank project with the latest Cypress, and move the tests across to it one by one.

  • make a new folder

  • decide if you want typescript, if so install it first

  • install Cypress

  • with no tests or configuration, open Cypress GUI and allow it to set up the folders and files for config and support

  • add the example spec when it is offered, and run it - now your Cypress framework is active

  • compare the new config with your old one, try not to copy anything that will break the new config, then run the example test again to make sure it still works

  • copy across the simplest spec from old project,

    • test it,
    • repeat for the rest

Then you can raise specific questions on SO for each test that does not work, and there is no guesswork about what issues you might have in the old project.

Also, I would add CI only after all tests are working locally.

答案2

得分: 0

看起来你正在设置一个TypeScript配置文件,但你试图将其运行得像JavaScript一样(根据你的注释:npx cypress run --config-file=cypress.config.js)。如果你的应用程序是JavaScript,你需要重写你的配置文件。如果应用程序是TypeScript,那么你需要将配置文件重命名为cypress.config.ts

请参考https://docs.cypress.io/guides/references/configuration

英文:

It seems to me that you are setting a TypeScript config file, but you are trying to run it as if it was JavaScript (from your comments: npx cypress run --config-file=cypress.config.js). If your app is JavaScript, you need to rewrite your configuration file. If the app is TypeScript, then you need to rename the configuration file as cypress.config.ts

Please, refer to https://docs.cypress.io/guides/references/configuration

huangapple
  • 本文由 发表于 2023年7月20日 16:13:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76727889.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定