小编Ala*_*paz的帖子

vue 3 + vite + cypress:无效的 JS 语法。安装@vitejs/plugin-vue来处理.vue文件

我想使用“cypress组件测试”与vite + vue 3

我应用与 cypress 文档相同的配置(请参阅上面的第一个链接)。我还尝试从 cypress 的 github 示例中重现该示例。

但我有错误:

[plugin:vite:import-analysis] 无法解析导入分析源,因为内容包含无效的 JS 语法。安装 @vitejs/plugin-vue 来处理 .vue 文件。

我的项目在运行 vite 服务器时有效,但在使用 Cypress 时无效......

您对这个问题有什么想法吗?

我的配置:

  • 包.json
{
  "dependencies": {
    "@vue/vue3-jest": "^27.0.0-alpha.3",
    "vue": "^3.2.16",
    "vue-router": "^4.0.12"
  },
  "devDependencies": {
    "@cypress/vite-dev-server": "^2.2.0",
    "@cypress/vue": "^3.0.5",
    "@vitejs/plugin-vue": "^1.9.4",
    "@vue/babel-preset-app": "^4.5.15",
    "@vue/cli-plugin-router": "~4.5.0",
    "babel-jest": "^27.3.1",
    "cypress": "^9.0.0",
    "jest": "^27.3.1",
    "vite": "^2.6.4",
  }
}
Run Code Online (Sandbox Code Playgroud)
  • vite.config.js
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

export default defineConfig({
  plugins: …
Run Code Online (Sandbox Code Playgroud)

javascript cypress vuejs3 vite

8
推荐指数
1
解决办法
5761
查看次数

Cypress 10 显示“‘task’事件尚未在 setupNodeEvents 方法中注册。您必须在使用 cy.task() 之前注册它”

在 cypress.config.js 中,我尝试注册任务/插入事件并完全按照其指南中的记录设置我的环境配置。

但是,当尝试在 setupNodeEvents 中使用“on”时,我在标题中收到有关需要注册它的错误。

另外,要注意的是,在传递两个参数(on、config)时,配置文件不会获取 env 变量。仅当我将配置放在第一位或单独配置时,环境变量才会通过。

另外,我的任务在测试类中正确编码。我知道这一点是因为它们在 cypress 9 的早期版本中工作得很好,但如果有人认为这就是问题的所在,我可以分享它们

/// <reference types="cypress" />
const { defineConfig } = require('cypress');

module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on,config) {
      
      if (config.env == undefined) {
        return {
          baseUrl: "intentionally blank",
          env: {
            env: "test",
            schedulerBaseUrl: "intentionally blank",
            signInUrl: "intentionally blank",
            enableAccessibility: true,
            takeScreenShot: false,
            suites: "",
          },
        };
      }
      else if (config.env == 'development') {
        return {
          baseUrl: "https://blank.blank.com:blank",
          env: {
            environment: "development",
            schedulerBaseUrl: "intentionally blank",
            signInUrl: "intentionally blank",
            enableAccessibility: …
Run Code Online (Sandbox Code Playgroud)

javascript cypress

8
推荐指数
1
解决办法
6538
查看次数

选定选项上的赛普拉斯 IF-ELSE

我想检查是否在字段 1 中选择了“法国”选项,然后在字段 2 中选择了“欧元”选项。

如果在字段 1 中选择了“美国”选项,那么在字段 2 中我选择了“美元”选项。

在此输入图像描述

cy.get('State').then(($btn) => {
          // assert on the text
          if ($btn.text().to.equal('France')) {
               cy.get('#vs3__combobox > .vs__actions').click() //Expands
               cy.get('#dialog-2').contains('Euro').click() //Selects
          } else {
               cy.get('#vs3__combobox > .vs__actions').click() //Expands
               cy.get('#dialog-2').contains('Dollars').click() //Selects
          }
  })
Run Code Online (Sandbox Code Playgroud)

但我无法正确理解,而且我是 Cypress / Javascript 的新手。

谢谢

select cypress

2
推荐指数
1
解决办法
76
查看次数

在 Cypress 中,您可以在 Element 上调用 .click() 方法而不识别错误吗?

我有一个 Angular 应用程序,正在为其创建 Cypress E2E。

该应用程序的一个页面有一个表,其中第三列包含一个类名“link ng-star-inserted”的链接,我希望测试在找到特定行后单击该链接。

我实际上已经进行了执行此操作的测试 - 事实上该链接已被单击。

但它不是很优雅,它将 .click() 方法标记为错误(即使它确实有效)。

我正在寻找一种方法,让它不将 .click() 方法标记为错误。

这是我的代码...

cy.get(SELECTOR.dataTableBody).should('be.visible')
        .contains('tr', 'Text I am looking for in the row I want')
        .then($row => {
            cy.log('found it');
            cy.log('on row ' + $row.index());

            //Yes this is kind of ugly.  I tried it every other way I could think of and this is the only way it worked
            let cellWithLink = $row.find('td:nth-child(3)');
            cellWithLink.children().get(0).getElementsByClassName('link ng-star-inserted').item(0).click();
            
});
Run Code Online (Sandbox Code Playgroud)

这是 IDE 将 click() 标记为错误的镜头 - 尽管它确实有效。

在此输入图像描述

非常感谢!

typescript e2e-testing angular cypress e2e

2
推荐指数
1
解决办法
57
查看次数

在 cypress 中使用显式等待机制时无法覆盖默认超时

我正在使用 cypress-wait-until 插件在我们的框架中应用显式等待。当我使用它时,给定的最大时间是 30000 毫秒,因此理想情况下,它应该等待最多 300000 毫秒(30 秒)才能使元素可见,但它会在 4 秒后超时,这是 cypress 命令的默认超时。

    cy.waitUntil(() => cy.get('div.tabs div:nth-child(3)').should('be.visible') ,{timeout:30000})
Run Code Online (Sandbox Code Playgroud)

我想知道我应该在哪个文件中进行哪些更改,以便我可以覆盖为 cypress 规定的默认超时。如果社区在这方面提供一些解决方案,那就太好了。

javascript visibility ui-automation cypress cypress-wait-until

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

Cypress - “失败是因为你混淆了异步和同步代码”

我有一个可以访问 API 的 Cypress 测试。返回一个项目列表,我希望它基本上进行轮询,直到我得到正确的原因(最多 30 次)。

返回的示例是

{
   "items":[
      {
         "reason":"incorrect"
      },
      {
         "reason":"correct"
      }
   ]
}
Run Code Online (Sandbox Code Playgroud)

我有以下函数,如果返回正确的原因,它会轮询并返回响应。否则会抛出错误

function pollStatusReason(id, reason, attempts = 0) {
    const url = `http://someurl/${id}`;

    if (attempts > 30) throw `Too many attempts to get reason: ${reason}`;

    return cy.request({
        method: 'GET',
        url: url,
    }).then((response) => {
        if (response.status != 200) {
            pollStatusReason(id, reason, attempts + 1);
        } else {
            const items = response.body.items;
            for (let i = 0; i < items.length; i++) {
                if (items[i].reason …
Run Code Online (Sandbox Code Playgroud)

javascript recursion for-loop cypress

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