Mar*_*ral 2 automated-tests qa reactjs cypress
有人可以帮忙吗?
这是我无法解决的问题。
我需要访问单击按钮后弹出的新窗口。
我使用 cy.get('.app-card__content').click() 单击名为 Create a new plugin 的按钮。单击按钮后,应用程序将在新窗口上创建,但我不知道如何获取该窗口并继续我的测试。
这个新窗口 URL 是动态的,每次有人点击它时,App ID 的数字都会增加。
例如。> https://www.website.io/apps/app_name/standalone?id=DYNAMIC_ID_NUMBER
我能够登录网站并创建一个新应用程序,但是,我不知道如何使用 URL 获取新窗口。
抱歉,我只使用 Cypress 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('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
})
Run Code Online (Sandbox Code Playgroud)
我需要创建一个新应用程序,它会弹出一个新窗口,抓取新窗口并继续其余的测试。
我还需要在新窗口中保持登录状态,因为我需要保存应用程序。
据我所知,在 Cypress 测试中您不能处理多个选项卡/窗口。只需看看文档的这一部分:
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()
Run Code Online (Sandbox Code Playgroud)
当然,如果您的元素确实具有该属性,则只能使用它。
看看他们为此主题提供的其他解决方案:https : //github.com/cypress-io/cypress-example-recipes/blob/master/examples/testing-dom__tab-handling-links/cypress/integration/tab_handling_anchor_links_spec .js
归档时间: |
|
查看次数: |
6467 次 |
最近记录: |