当我运行 Cypress 测试时,每次测试执行某些操作时,URL 都会显示在左侧的信息面板中。不幸的是,该 URL 非常长,导致信息面板无法读取。有没有办法隐藏URL?
describe('Test', () => {
it('load page', () => {
cy.visit("https://ultimateqa.com/automation")
cy.get('.et_pb_text_inner > ul > :nth-child(3) > a').click()
})
})
Run Code Online (Sandbox Code Playgroud)
cy.getIframeBody().find('#some-button')我在使用#some-button 元素尚不可用时遇到问题,因为 iframe 仍在加载,但 body 元素不为空,因此触发了 .find() 。
这是获取 iframe 主体的自定义命令
Cypress.Commands.add('getIframeBody', ()=> {
return cy.get('iframe.cy-external-link-container')
.its('0.contentDocument.body')
.should('not.empty')
.then(cy.wrap)
});
Run Code Online (Sandbox Code Playgroud)
我怎样才能在不使用的情况下做到这一点cy.wait()?
设想:
<tr>
<td id="type1">
<div><span></span></div>
</td>
<td id="type2">
<div><span></span></div>
</td>
</tr>
Run Code Online (Sandbox Code Playgroud)
cy.get('#type1').type('Abcd') // skips the initial letters ie,
// it actually types 'bcd' or 'cd'
Run Code Online (Sandbox Code Playgroud)
这里有一个问题:使用类型 #3817 时缺少字母。我可以看到这个问题已经解决,但我仍然面临这个问题。有什么解决方法吗?
所以我一直在本地主机上设置我的测试,但现在我想将它们设置为在几个不同的环境上运行,但在所有这些环境上我都有一个单独的baseUrl和apiUrl。dev 有:http://base.url.com和 api:http://base.url.com/api
prod 有:https://prod.url.com和 api:https://prod-api.url.com/v1
我已经阅读了这里的文档和一些帖子(尽管其中很多来自 cypress v10 之前),但我无法决定什么是最好的方法。我倾向于创建不同的配置文件(cypress-dev.config.ts、cypress-prod.config.ts 等),每个文件针对不同的环境,如下所示:
e2e: {
baseUrl: 'http://base.url.com',
env: {
apiURl: '..'
}}
Run Code Online (Sandbox Code Playgroud)
创建新的 npm 脚本,我将 cypress 设置为在特定环境中运行时使用正确的配置文件。
我考虑过使用一个配置文件,但我无法弄清楚到底如何做。
e2e: { env: {
development: {
baseUrl:'baseURlDev',
apiURl: 'apiUrlDev'
},
production: {
baseUrl:'baseURlProd',
apiURl: 'apiUrlProd'
},
staging: {
baseUrl:'baseURlStag'
apiURl: 'apiUrlStag' }
}}
Run Code Online (Sandbox Code Playgroud)
如何使用它是我的赛普拉斯代码。Cypress.env('环境类型.baseUrl')?? 我对此不太清楚。
或者也许还有我还没有考虑过的第三种巧妙的方法?
运行集成测试时出现错误:
0 passing (17s)
1 failure
1) Registration page
register new users allowed and update status in the database:
TypeError: Net.connect is not a function
at new Connection (webpack:///./node_modules/mysql2/lib/connection.js:50:0)
at ./node_modules/mysql2/index.js.exports.createConnection (webpack:///./node_modules/mysql2/index.js:10:0)
at Context.eval (webpack:///./cypress/integration/registration.spec.js:23:34)
Run Code Online (Sandbox Code Playgroud)
这是我的环境:
MySQL Workbench
MySQL Server 8.0.29
Run Code Online (Sandbox Code Playgroud)
我提出了本地后端,我可以访问数据库。这是我的代码:
const mysql2 = require('mysql2');
describe('Registration page', () => {
beforeEach(() => {
// visit the registration page
cy.visit('http://localhost:3000/registration');
});
it('register new users allowed and update status in the database', () => {
// fill out the registration form …Run Code Online (Sandbox Code Playgroud) HTML 屏幕截图

我无法使用我尝试过添加和不添加"includeShadowDom": true到 cypress.json 的 cypress 与影子 dom 按钮进行交互。
我尝试了下面代码的各种排列,但它始终无法找到该元素。
仅.shadow()与父级一起使用会显示错误,指出无法找到影子 dom。
cy.get('#r-searchField').shadow().find('#text-field-container').find('#search-clear').click()
Run Code Online (Sandbox Code Playgroud) cypress ×6
angular ×1
automation ×1
config ×1
cypress-log ×1
iframe ×1
mysql ×1
mysql2 ×1
shadow-dom ×1
testing ×1