Reactjs 我需要进入一个新窗口,点击按钮后弹出

Reactjs 我需要进入一个新窗口,点击按钮后弹出,reactjs,automated-tests,qa,cypress,Reactjs,Automated Tests,Qa,Cypress,有人能帮忙吗 这是我无法解决的问题 我需要进入一个新窗口,点击按钮后弹出 我使用了cy.get('.app-card\uu content')。单击()可以单击名为“创建新插件”的按钮。在我点击按钮后,应用程序在一个新窗口上创建,我不知道如何获得该窗口并继续我的测试 这个新的窗口URL是动态的,每次有人点击它,应用程序ID的数量就会增加 例> 我能够登录到该网站并创建一个新的应用程序,但是,我不知道如何用URL抓取新窗口 很抱歉,我使用Cypress仅两天,这是一个我知道的新手问题 任何帮助都是

有人能帮忙吗

这是我无法解决的问题

我需要进入一个新窗口,点击按钮后弹出

我使用了cy.get('.app-card\uu content')。单击()可以单击名为“创建新插件”的按钮。在我点击按钮后,应用程序在一个新窗口上创建,我不知道如何获得该窗口并继续我的测试

这个新的窗口URL是动态的,每次有人点击它,应用程序ID的数量就会增加

例>

我能够登录到该网站并创建一个新的应用程序,但是,我不知道如何用URL抓取新窗口

很抱歉,我使用Cypress仅两天,这是一个我知道的新手问题

任何帮助都是非常受欢迎的

干杯

我无法使此代码正常工作:

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('user@website.io', {delay:110}).should('have.value', 'user@website.io')
        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


})
我需要创建一个新的应用程序,弹出一个新的窗口,抓住新的窗口,继续测试的其余部分


我还需要继续登录新窗口,因为我需要保存应用程序。

据我所知,在Cypress测试中,您不能处理多个选项卡/窗口。只需查看文档的这一部分:

当我面对这个问题时,我使用了他们提供的解决方法,所以你不需要“抓取”其他窗口;如果可以的话,选择这个:

// 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()
当然,只有在元素确实具有该属性时,才能使用该属性


看看他们为这个主题提供的其他解决方案:

我刚刚解决了一个类似的问题。也许你可以把它作为参考。 在我的例子中,新窗口在单击按钮后打开,url是动态的

cy.window().then(win => {
    cy.stub(win, 'open').as('windowOpen');
});

// you can try exclude the 'should' below
// in my code it worked without this 'should' first
// after merging the latest changes this part failed somehow though no change was made here
// after investigation I found that the stub argument was not ready immediately
// so I added 'should' here to wait the argument load
// before visiting the url contained within it

cy.get('@windowOpen').should('be.calledWith', Cypress.sinon.match.string).then(stub => {
    cy.visit(stub.args[0][0]);
    stub.restore;
});