标签: cypress

Cypress - 选择下拉选项不会将预期的项目添加到列表中

我有一个下拉菜单,可以从选项中选择多个项目,这些选项应将所选项目添加到文本/标签/显示字段。仅当用户单击选项外部时,下拉选项才会关闭。否则它会保持原状等待下一个输入(因此,一旦我选择了所有选项,我就会模拟单击下拉列表的标签)。但是,所选项目不会添加到标签/文本字段。

手动单击页面上的项目即可添加它们。仅通过 cypress 它不起作用。在此处输入图像描述正如您在所附图像上看到的,所选项目已添加到上面。这是在网站上手动执行的。

下面是我正在尝试使用的代码。labelField 是保存“权限”标签选择器的变量。userDetails.permission 对象键保存要选择的选项。注意:我尝试过使用 cy.click() 参数,例如超时和 waitforanimation。还使用了.trigger(“点击”)。

cy.wrap(labelField.next()).find('.multiselect__select').click();
cy.wrap(labelField.next()).within(() => {
    userDetails.permission.forEach(($item) => {
        cy.get('.multiselect__element').contains($item).click({ timeout: 2000 });
    });
});
cy.wrap(labelField).click();  // click on label to hide the options after choosing required items. 
Run Code Online (Sandbox Code Playgroud)

javascript drop-down-menu cypress

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

Cypress:如何读取文本文件,但即使文件不存在也继续执行?

我想写入一个文本文件,但如果它已经存在,我想先清理它。

如果它不存在,我想创建它并开始写入它。

我多次尝试清除文件(如果文件存在),但如果不存在则继续执行,但是该方法

cy.readFile() 
Run Code Online (Sandbox Code Playgroud)

如果找不到文件,我的执行总是会崩溃。

例如:

function clearFile(filePath) {
  try {
    // Read the contents of the file.
    const fileContents = cy.readFile(filePath, { encoding: "utf-8" });
  
    // If the file exists, clear it.
    if (fileContents) {
      cy.writeFile(filePath, "");
    }
  } catch (err) {
    // Ignore the error if the file does not exist.
    if (err.code === "ENOENT") {
      // The file does not exist.
    } else {
      // Rethrow the error if it is not a file not found error. …
Run Code Online (Sandbox Code Playgroud)

javascript typescript cypress

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

Cypress - 如果条件失败则终止函数

这是我们应用程序的用户界面。

在上面的截图中,有 4 个产品。每个未挑选的产品都会有一个Pick按钮。按钮右侧Pick是数量。如果用户单击该Pick按钮,该产品将列在 下PICKED ITEMS。如果用户点击该Pick按钮Product #13 次,则该按钮将从列表中删除UNPICKED ITEMS,并移至PICKED ITEMS列表中。

现在我想编写一个 Cypress e2e 测试,它将单击Pick按钮X次数,其中X是 下所有产品的总数UNPICKED ITEMS。在下面的屏幕截图中,总数应为 10,因为其他 2 个已被选中。

2这是我尝试过的

3但即使单击所有按钮后它仍继续运行

cypress

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

如何使用 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
查看次数

我如何在 Playwright 中复制这个 cy.intercept?

我希望将我的测试套件从 Cypress 迁移到 Playwright。当我处理 API 请求时遇到了障碍。

在我的测试套件中,我想等待网络请求完成并返回 200 响应,然后再进行下一个操作。

我的问题是网络请求 url 包含动态值,之前在 Cypress 中我将“*”作为通配符,Playwright 中的替代方案是什么?

我的代码中有以下 cy.intercept:

cy.intercept('GET',`${apiUrl}/employee/*/information`).as('GETemployeeInformation');
Run Code Online (Sandbox Code Playgroud)

在继续测试步骤之前,我在测试套件中使用 cy.wait 调用此拦截,我尝试使用以下内容在 Playwright 中复制此内容:

async isSignedIn() {
    await this.page.waitForResponse(response => response.url().includes("/employee/*/information") && response.status() === 200);
  }
Run Code Online (Sandbox Code Playgroud)

javascript automation cypress playwright

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

在我的测试文件(spec.js)中上传本地服务器和端点时出错

我有以下问题:

我正在使用 Cypress 进行自动化测试。我创建了一个本地服务器,一个端点,我总是需要在测试之前启动并在测试之后始终关闭。

我尝试了一种方法,但出现以下错误:

Error: Webpack Compilation Error
./node_modules/mysql2/node_modules/lru-cache/dist/mjs/index.js 51:11
Module parse failed: Unexpected character '#' (51:11)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|      length;
|      private constructor
>     static #constructing = false;
|     static create(max) {
|         const HeapCls = getUintArray(max);
 @ ./node_modules/mysql2/lib/parsers/parser_cache.js 3:12-32
 @ ./node_modules/mysql2/promise.js
Run Code Online (Sandbox Code Playgroud)

有谁能够帮助我?

我上传到服务器的文件(index.js):

const express = require("express");
const app = express();
const port = 3000;
const programmingLanguagesRouter …
Run Code Online (Sandbox Code Playgroud)

javascript automated-tests mysql2 cypress

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

使用 Cypress 循环遍历不一致的父对象

我正在使用 Cypress 编写自动化测试用例。

我需要循环遍历该元素的所有子元素并验证其数据。问题是,除了第一个孩子之外,所有孩子都是带有<a>标签和值属性的对象。href

第一个被包装到span创建以下层次结构中:
parent -> span -> a with href value

如何组织循环?

我尝试删除 span 元素,但它被删除时<a>里面有一个子元素

html cypress

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

Chai 断言包含 or for 字符串

我试图遍历一个元素列表,并想断言主体包含这两个值中的一个。我正在尝试使用以下内容,但它只能让我断言一个值。

expect(cellText).includes(toDateFormat);
Run Code Online (Sandbox Code Playgroud)

如何做出允许我断言具有 OR 条件的多个值的断言?

javascript mocha.js node.js chai cypress

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

溢出时赛普拉斯滚动问题:自动

我正在测试一个包含 div 的网络应用程序

\n
<div style="overflow: auto; max-height: 429px;" \xe2\x80\xa6\n
Run Code Online (Sandbox Code Playgroud)\n

其中包含一张大桌子。我看到桌子周围有滚动条。现在我希望 Cypress 单击表中的一个元素。如果该元素隐藏在某个地方,那就没问题。Cypress 会自动滚动到那里。但如果该元素隐藏在右侧的某个位置,Cypress 将不会滚动到正确的位置,而是会抱怨:

\n
\n

CypressError:10050ms后超时重试:cy.click()失败,因为该元素的中心从视图中隐藏:`<input type =“radio”\ xe2 \ x80 \ xa6

\n
\n

这是为什么?我能做些什么?

\n

我正在使用最新的赛普拉斯(13.6.2)。

\n

编辑:事实证明存在两个不同的问题:

\n
    \n
  1. 对于某些元素,Cypress 确实会自动滚动,但没有滚动到正确的位置。
  2. \n
  3. 对于极少数元素,Cypress 根本不会自动滚动。
  4. \n
\n

第一个问题发生在“overflow: auto”内的宽表中。当我将显示行为从默认的“顶部”切换到“中心”后,第二个问题发生在没有任何溢出上下文的情况下。

\n

cypress

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

赛普拉斯 Iframe 找不到 0.contentDocument

我正在尝试对需要上传用户的应用程序运行一些测试。我们使用 usecsv 来处理页面上 iframe 中上传的文档。当尝试使用多种不同的方法来对其进行测试时,我不断遇到 cypress 错误:

4000 毫秒后超时重试:cy.its() 出错,因为该属性:0.contentDocument您的主题上不存在。

我尝试与不同的网站进行比较,看看我的命令是否正确:

describe("iFrame", () => {
 
    beforeEach(() => {
      cy.visit('https://kitchen.applitools.com/ingredients/iframe');
    });
   
    it('should find a table in the iframe', () => {
      cy.get('iframe[src="/ingredients/table"]')
        .its('0.contentDocument').its('body').then(cy.wrap);
    });
  });`
Run Code Online (Sandbox Code Playgroud)
<iframe id="the-kitchen-table" title="The Kitchen - Table" 
  width="800" height="800" 
  src="/ingredients/table">
</iframe>
Run Code Online (Sandbox Code Playgroud)

其按预期工作。

针对我的应用程序运行类似的操作时:

describe("Sets up benefits, edits them and verifies functionality", () => {
    it("Changes employee start date for gratuity calculations", () => {
      cy.visit("/");

...
      cy.get('iframe[src="https://app.usecsv.com/importer"]')  
        .its('0.contentDocument').its('body').then(cy.wrap);
    });
})
Run Code Online (Sandbox Code Playgroud)
<iframe src="https://app.usecsv.com/importer"></iframe>
Run Code Online (Sandbox Code Playgroud)

在这种情况下,我收到上述错误。当只是尝试时cy.get('iframe[src="https://app.usecsv.com/importer"]')没有错误,所以我假设它确实找到了 …

iframe cypress

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