测试不会在以下时间后运行:
cy.visit('http://tembo-urgent-care.web.app/')
Cypress 只需作为浏览器打开此页面,这样我就可以手动与其交互。如果我尝试另一个页面,例如YouTube - 工作正常,我的测试已运行。 另外,如果我将此 URL 放入配置文件中,则在运行后 npx cypress 在选择浏览器后运行,我什至无法选择测试来运行。它只是像在浏览器中一样打开页面(如视频中所示)。
执行 npx cypress open 后我看到的内容
我有 Windows 11 和 MacOS。除了 Windows 11 上的 Mozilla Firefox 和 Edge 浏览器外,两者都存在此问题。Cypress v12.17.3。
跑步后
cy.visit('http://tembo-urgent-care.web.app/')
测试应该与此页面交互。
我尝试运行的脚本:
describe('template spec', () => {
it('"Start visit" redirects user to the form page', () => {
cy.visit('https://tembo-urgent-care.web.app/');
});
});
有些网页不喜欢在 iframe 内运行(Cypress 就是这么做的)。这显然不是。
这里给出了一个实验性的自定义命令无法使用 Cypress 加载特定的 URL ,它允许您的测试在子窗口中运行。 (仅在 Chrome 上测试)。
Cypress.Commands.add('openWindow', (url, features) => {
const w = Cypress.config('viewportWidth')
const h = Cypress.config('viewportHeight')
if (!features) {
features = `width=${w}, height=${h}`
}
console.log('openWindow %s "%s"', url, features)
return new Promise(resolve => {
if (window.top.aut) {
console.log('window exists already')
window.top.aut.close()
}
// https://developer.mozilla.org/en-US/docs/Web/API/Window/open
window.top.aut = window.top.open(url, 'aut', features)
// letting page enough time to load and set "document.domain = localhost"
// so we can access it
setTimeout(() => {
cy.state('document', window.top.aut.document)
cy.state('window', window.top.aut)
resolve()
}, 10000)
})
})
it('tests tembo login', () => {
cy.openWindow('https://tembo-urgent-care.web.app/')
cy.get('button').click()
cy.get('input[placeholder="Your full name"]')
.should('be.visible')
.type('my patient name')
cy.get('input[placeholder="Your full name"]')
.should('have.value', 'my patient name')
})
由于应用程序是 Vue,替代方案是使用 Vue 组件测试。
这样可以避免Cypress打开完整网页时出现的问题。