有人可以帮忙吗?
这是我无法解决的问题。
我需要访问单击按钮后弹出的新窗口。
我使用了cy.get('。app-card__content')。点击()点击名为Create a new plugin的按钮。单击按钮后,应用程序在新窗口中创建,我不知道如何获取窗口并继续测试。
这个新窗口URL是动态的,每次有人点击它时,App ID的数量都会增加。
例如。 > https://www.website.io/apps/app_name/standalone?id=DYNAMIC_ID_NUMBER
我能够登录网站并创建一个新的应用程序,但是,我不知道如何使用URL获取新窗口。
对不起,我只使用赛普拉斯2天,这是我知道的新手问题。
任何帮助都非常受欢迎。
干杯。
我无法使用此代码:
describe('window open', function () {
beforeEach(function () {
cy.visit('/index.html', {
onBeforeLoad(win) {
cy.stub(win, 'open').as('windowOpen')
}
})
})
it('see window open being called with url', function () {
cy.get('#open-window').click()
cy.get('@windowOpen').should('be.calledWith', 'page1.html')
})
})
Here is the code I wrote:
// This test consists of Accessing Staging and Create a new App.
// Go to website.io.
describe('Staging Test v1', function(){
it('Accessing Staging', function(){
cy.visit('https://www.website.io')
cy.wait(2000)
})
// Get login button.
it('Get login button', function(){
cy.get('.signed-out-container > .signInTab').click()
cy.wait(2000)
})
// Fill out the modal and log in
it('Fill out the modal and log in', function(){
cy.get('#sign_in_email').type('[email protected]', {delay:110}).should('have.value', '[email protected]')
cy.wait(1000)
cy.get('#new_sign_in_password').type('password', {delay:110}).should('have.value', 'password')
cy.wait(1000)
cy.get('#sign-in-submit').click()
cy.wait(6000)
})
// Click on new Create New Plugin button.
it('Click on create a new plugin button', function(){
cy.get('.dashboard-header__create-new-container > .button').should('be.visible').click({force:true})
cy.wait(2000)
})
// Search and create a new App
it('Search and create a new App', function(){
cy.get('.app-search__search-input').click({force:true}).type('App name', {force:true})
cy.wait(3000)
cy.get('.app-card__content').click()
cy.wait(10000)
})
// Grab the new window to continue the test
// Need to find out how to grab the new window passing along cookies and sessions to remain logged in.
// Develop part 2 of the test
})
我需要创建一个新的应用程序,它弹出一个新窗口,抓住新窗口并继续其余的测试。
我还需要保持登录新窗口,因为我需要保存应用程序。
据我所知,您无法在赛普拉斯测试中处理多个选项卡/窗口。只需看看文档的这一部分:
https://docs.cypress.io/guides/references/trade-offs.html#Multiple-tabs
当我面对这个问题时,我使用了他们为此提供的解决方法,因此您无需“抓住”其他窗户;如果可以,请选择以下内容:
// We can remove the offending attribute - target='_blank'
// that would normally open content in a new tab.
cy.get('.app-card__content').invoke('removeAttr', 'target').click()
当然,如果您的元素具有该属性,则只能使用此属性。
看看他们为这个主题提供的其他解决方案:https://github.com/cypress-io/cypress-example-recipes/blob/master/examples/testing-dom__tab-handling-links/cypress/integration/tab_handling_anchor_links_spec.js