我尝试访问放置身份服务器页面的 iframe 中的登录表单 我尝试了两种方式:
Cypress.Commands.add('login', () => {
cy.get('body .container')
.its('.aut-iframe')
.then(cy.wrap)
.its('0.contentDocument.body')
.then(cy.wrap)
.find('form')
.should('exist');
cy.url().then((url) => {
if (url.includes('identityserver')) {
document
.querySelector('.aut-iframe')
.contentDocument.querySelector('input[placeholder="Username"]').value =
'User';
}
});
});
在测试文件中我称之为登录
context('Page', () => {
beforeEach('LogIn-goToPage', () => {
cy.visit('http://localhost:4200/search');
cy.login();
});
如果我在控制台中放置查询选择器来设置输入,我会成功,但在 cypress 中我从不访问它