我有一个下拉菜单,可以从选项中选择多个项目,这些选项应将所选项目添加到文本/标签/显示字段。仅当用户单击选项外部时,下拉选项才会关闭。否则它会保持原状等待下一个输入(因此,一旦我选择了所有选项,我就会模拟单击下拉列表的标签)。但是,所选项目不会添加到标签/文本字段。
手动单击页面上的项目即可添加它们。仅通过 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) 我想写入一个文本文件,但如果它已经存在,我想先清理它。
如果它不存在,我想创建它并开始写入它。
我多次尝试清除文件(如果文件存在),但如果不存在则继续执行,但是该方法
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) 在上面的截图中,有 4 个产品。每个未挑选的产品都会有一个Pick按钮。按钮右侧Pick是数量。如果用户单击该Pick按钮,该产品将列在 下PICKED ITEMS。如果用户点击该Pick按钮Product #13 次,则该按钮将从列表中删除UNPICKED ITEMS,并移至PICKED ITEMS列表中。
现在我想编写一个 Cypress e2e 测试,它将单击Pick按钮X次数,其中X是 下所有产品的总数UNPICKED ITEMS。在下面的屏幕截图中,总数应为 10,因为其他 2 个已被选中。
我试图将断言传递给 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) 我希望将我的测试套件从 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) 我有以下问题:
我正在使用 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) 我正在使用 Cypress 编写自动化测试用例。
我需要循环遍历该元素的所有子元素并验证其数据。问题是,除了第一个孩子之外,所有孩子都是带有<a>标签和值属性的对象。href
第一个被包装到span创建以下层次结构中:
parent -> span -> a with href value。
如何组织循环?
我尝试删除 span 元素,但它被删除时<a>里面有一个子元素
我试图遍历一个元素列表,并想断言主体包含这两个值中的一个。我正在尝试使用以下内容,但它只能让我断言一个值。
expect(cellText).includes(toDateFormat);
Run Code Online (Sandbox Code Playgroud)
如何做出允许我断言具有 OR 条件的多个值的断言?
我正在测试一个包含 div 的网络应用程序
\n<div style="overflow: auto; max-height: 429px;" \xe2\x80\xa6\nRun Code Online (Sandbox Code Playgroud)\n其中包含一张大桌子。我看到桌子周围有滚动条。现在我希望 Cypress 单击表中的一个元素。如果该元素隐藏在某个地方,那就没问题。Cypress 会自动滚动到那里。但如果该元素隐藏在右侧的某个位置,Cypress 将不会滚动到正确的位置,而是会抱怨:
\n\n\nCypressError:10050ms后超时重试:
\ncy.click()失败,因为该元素的中心从视图中隐藏:`<input type =“radio”\ xe2 \ x80 \ xa6
这是为什么?我能做些什么?
\n我正在使用最新的赛普拉斯(13.6.2)。
\n编辑:事实证明存在两个不同的问题:
\n第一个问题发生在“overflow: auto”内的宽表中。当我将显示行为从默认的“顶部”切换到“中心”后,第二个问题发生在没有任何溢出上下文的情况下。
\n我正在尝试对需要上传用户的应用程序运行一些测试。我们使用 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"]')没有错误,所以我假设它确实找到了 …
cypress ×10
javascript ×6
automation ×2
chai ×1
cypress-conditional-testing ×1
html ×1
iframe ×1
mocha.js ×1
mysql2 ×1
node.js ×1
playwright ×1
typescript ×1