cypress 相关问题

赛普拉斯,一体化测试框架和断言库,包括自动等待,请求模拟和请求存根

如何在 Cypress 中更新夹具文件

我在cypress中有一个fixture文件,其中包含json数据 我希望在运行测试脚本时能够更新此固定文件中的字段 例如,固定装置文件将读取 { 他...

回答 2 投票 0

cypress 中缺少集成和插件文件夹

我已经生成了 cypress 文件夹..在其中我只能看到支持和固定文件夹。集成和插件文件夹丢失...请帮助解决

回答 2 投票 0

无法使用 Cypress 在同一选项卡中打开链接

我正在尝试使用 cypress 在同一选项卡中打开链接 我厌倦了使用 cy.get('a').eq(0).invoke('removeAttr', 'target').click() 但没有成功。检查 HTML 文件后我发现没有

回答 2 投票 0

有人可以帮忙找到关于赛普拉斯自动化的研究吗

我是测试之旅的新手。所以我对学习自动化测试很感兴趣。帮我想个办法。 有人帮助指导告诉我学习自动化的好方法。目前我在

回答 1 投票 0

Cypress - 使用 cypress:open 和 cypress:run 的不同结果

我在 vue2 中有这个简单的页面(未找到的页面)(但它是简单的纯 HTML): 未找到.vue 那... 我在 vue2 中有这个简单的页面(未找到的页面)(但它是简单的纯 HTML): NotFound.vue <template> <section> <base-card> <h2 id="notFoundTitle">This isn't the page you are looking for.</h2> <p> 404 - This page could not be found - check out all our <router-link to="/coaches">coaches</router-link> </p> </base-card> </section> </template> 现在我在 Cypress 中创建了这个简单的测试: notLogged.cy.js let siteUrl = 'https://my.site' describe('Tests for pages without login', () => { describe('Tests for the home page', () => { it('Tests the not found page', async () => { let url = siteUrl + '/stuff' cy.visit(url) let pageTitle = cy.get('#notFoundTitle') let pagePar = cy.get('p') expect(pageTitle).to.exist expect(pagePar).to.exist pageTitle.should('have.text', "This isn't the page you are looking for.") pagePar.should('contain', '404') }) }) }) 我的package.json文件是: { "name": "test_cy", "version": "1.0.0", "description": "", "main": "index.js", "type": "module", "scripts": { "cypress:open": "cypress open", "cypress:run": "cypress run notLogged.cy.js" }, "author": "", "license": "ISC", "devDependencies": { "cypress": "^13.6.3" } } 当我运行npm run cypress:run时,一切正常,并表示 2 个测试已通过。 但是当我运行 npm run cypress:open 并使用 chrome 进行 e2e 测试时,它会抛出一个荒谬的错误,如图所示: 但我不是在寻找p哪个'have.text'。 我正在寻找 p,其中 contains 字符串 404。 错误(从图像报告)是: assert expected '<p>' to have text 'This isn't the page you are looking for.', but the text was **'&nbsp;404 - This page could not be found - check out all our coaches'** (uncaught exception)AssertionError: Timed out retrying after 4000ms: expected '<p>' to have text 'This isn't the page you are looking for.', but the text was ' 404 - This page could not be found - check out all our coaches' 有人知道我做错的原因或什么吗? 在赛普拉斯文档中变量和别名它告诉你 您无法分配或使用任何 Cypress 命令的返回值。 命令排队并异步运行。 在内部,Cypress 跟踪链的 subject,并用它来评估断言。 断言之前的最后一个查询是 cy.get('p'),因此主题是 <p>,而不是变量 <h2> 中的 pageTitle。 编写此测试的标准方法是使用完整的命令链 cy.visit('https://vue-course-2023.web.app/stuff') cy.get('#notFoundTitle').should('exist') .and('have.text', "This isn't the page you are looking for.") cy.get('p').should('exist') .and('contain', '404') 或者使用别名,如果你想打破链条,出于某种原因 cy.visit('https://vue-course-2023.web.app/stuff') cy.get('#notFoundTitle').as('pageTitle') cy.get('p').as('pageParagraph') // some intermediate code cy.get('@pageTitle') .should('exist') .and('have.text', "This isn't the page you are looking for.") cy.get('@pageParagraph') .should('exist') .and('contain', '404')

回答 1 投票 0

cypress 中的规范文件是什么?

什么是规格文件?我在cypress、Angular和其他软件中看到过spec文件,但我不知道它是什么?有人能用通俗的语言解释一下吗?或者只是解释一下?

回答 1 投票 0

从范围选择器中选择日期

我正在尝试在范围选择器中添加两个日期。 这是选择日期的命令: Cypress.Commands.add('setDatePickerDate', (选择器, 日期) => { const MonthShort = [ '一月', 'f...

回答 1 投票 0

Cypress - 从范围选择器中选择日期

我正在尝试在范围选择器中添加两个日期。 这是选择日期的命令: Cypress.Commands.add('setDatePickerDate', (选择器, 日期) => { const MonthShort = [ '一月', 'f...

回答 1 投票 0

如何根据按钮文本点击特定div内的按钮?

在 Cypress 测试中,我尝试根据其文本单击嵌套在 div 内的特定按钮。 下面是我正在测试的 HTML 代码: 在 Cypress 测试中,我尝试根据其文本单击嵌套在 div 内的特定按钮。 下面是我正在测试的HTML代码: <div class="mat-menu-content"> <button>First button</button> <button>Second button</button> </div> 我想单击带有 Second button 文本的按钮。 我不能只使用 cy.contains('Second button'),因为 Second Button 文本出现在页面上的多个位置。 这是我尝试使用 Cypress 编写的内容: 单击 mat-menu-content div 内包含 Second button 文本 的按钮 有人可以告诉我如何做到这一点吗? 首先通过类名获取元素,然后搜索内容,最后调用 click() 方法。尝试这样的事情: cy.get('.mat-menu-content').contains('Second button').click() 有关更多信息,请查看此处的官方文档 .contains()非常强大,允许使用与文本配对的选择器,cy.contains('selector', 'Your text')。 对于您的场景,您需要使用与文本配对的 button 选择器来获取包含 Second button 的按钮。 cy.contains('button', 'Second button') // or if there are multiple buttons with 'Second button' text on the page cy.get('.mat-menu-content') .contains('button', 'Second button') .contains()还允许正则表达式匹配,我更喜欢在不区分大小写的情况下查找。 cy.contains('button', /second button/i) 如果页面有多个菜单,则只有打开菜单时才会显示项目按钮,并且一次只会打开一个菜单。 您可以继续,打开菜单后选择带有文本 Second button 的按钮。 cy.contains('button', 'Contacts Menu').click() // open the menu cy.contains('button', 'Second button').click() // select 2nd item 还有一个变体,在 .mat-menu-content 选择器之前添加 button cy.contains('.mat-menu-content button', 'Second button') // tighter criteria 如果网页上有多个 mat-menu-content,您可以使用 eq 访问特定的一个,然后使用 within() 将查询范围限定在 div.mat-menu-content 内 cy.get('mat-menu-content') .eq(0) .within(() => { //eq(0) points to the first occurance in the DOM cy.contains('button', 'Second button').click() }) 正如您想做的那样“单击包含第二个按钮文本的 mat-menu-content div 内的按钮”,我建议 cy.get('div.mat-menu-content button').contains('Second button').click() 这里有一个 get 命令可以完全满足您想要做的事情: cy.get('div.mat-menu-content button:contains("Second button")'

回答 7 投票 0

从 Jenkins 运行时打开 Cypress 浏览器

我在 Jenkins 中创建了一个自由式项目,我想在其中运行 Cypress。 在命令行中我使用了这个命令行: npx cypress run --browser chrome --headed --spec "cypress/integration/

回答 3 投票 0

如何在 Cypress 中通过 TypeScript 项目使用 xpath 定位器?

最初,xpath 插件在我的 cypress 项目中运行良好。安装了 Typescript 插件并从 javascript 移至 Typescript。现在它开始在 xpath 上抛出错误 属性“xpath”d...

回答 2 投票 0

访问新窗口 - cypress.io

问题就这么简单。在 Cypress 中,如何访问运行测试时打开的新窗口。 重新创建的步骤: 运行测试。进行一些操作后,会弹出新窗口(...

回答 8 投票 0

如何使用ESM项目的typescript在cypress中导入相关源代码?

我的打字稿项目(“type”:“module”)组织如下: 应用程序 - 源代码 - 实用程序 - 实用程序.ts - 其他代码 - 柏树 - 电子到电子 - 规格.cy.ts 包.json...

回答 2 投票 0

Cypress 页面对象模型模式。扩展元素属性

我有以下页面对象模型代表我的应用程序中的小部件 /** * 包含所有小部件的通用操作 */ 导出默认抽象类 AbstractWidget { 私有 widgetId:数字;...

回答 1 投票 0

将 Gmail 与 Cypress 连接

我可以有连接cypress和Gmail的所有步骤吗?! 我尝试连接但没有成功:( 我已填写表格,提交表格。电子邮件来自电子邮件地址,但现在我需要访问...

回答 1 投票 0

ENOENT:赛普拉斯中没有此类文件或目录错误

使用 GUI 运行 Cypress 时,出现此错误: 错误:ENOENT:没有这样的文件或目录,stat '/home/user/.config/Cypress/cy/product/projects/testProject-ba4506b83588731a9b974658caac8b40/

回答 1 投票 0

Cypress Open UI 不可见

当我运行命令 npx cypress open 时 cypress 窗口已启动,但由于某种原因 UI 不可见 我已经尝试过 npm install cypress@latest --save-dev,但它仍然不起作用 柏树

回答 3 投票 0

Cypress 无法在 Mac 服务器上使用无头模式

当我使用 SSH 连接到 MAC 服务器并运行 npx cypress run --browser chromium --headless 时,它会抛出 DevTools 监听 ws://127.0.0.1:61426/devtools/browser/fac110e3-5a3c-4ed1-9c20-64d59f44f1ec

回答 1 投票 0

Cypress如何处理一个iframe到另一个iframe中

主要目标是访问输入字段并提交一些数据。 问题 - 这些元素位于一个 iframe 中(我们不能添加任何属性,如 id 等),这些元素被包装在 ano 中...

回答 1 投票 0

使用 Cypress Github Action 将环境变量添加到服务器

我需要将一些环境变量传递给赛普拉斯在后台启动的服务器,例如在下面的启动属性下,如赛普拉斯文档中所述: - 名称:运行 e2e 测试

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.