赛普拉斯:页面不会在点击操作的第二个"it"块内加载



如果我在下面的单个"It"块中进行了编码,那么对于同一个点击事件来说,它可以很好地工作。

工作代码:

describe('Test Suite', () => {
it('Test case 1', () => {
//Test 1
//Test 2
})
})

不工作:

describe('Test Suite', () => {
it('Test case 1', () => {
//Test 1
})
it('Test case 2', () => {
//Test 2
})
})

下面是我的代码片段,第一个"it"块在登录方法执行后工作正常。第二,它只阻止单击右侧元素,但页面永远不会加载。

p。S.如果我在单个"it"块下编写代码,Page就会加载并正常工作。

describe('Fund Manager Suite', () => {
//Checking Fund Manager page loading 
before(() => {
cy.visit('xxxxxxxxxxxxx')
cy.login('xxxxx', 'xxxxx')
})

it('fund manager navigation works', () => {
cy.location('pathname').should('equal', '/xxxxx')
cy.get('#appSwitcher').click()
cy.get('#appSwitcher > .dropdown > .dropdown-menu > :nth-child(2) > a').click()
cy.location('pathname').should('equal', '/xxxxx')
cy.get('.k-grid-table').find('tr').should('have.length', 5)
})
it('fund detail works', () => {
cy.get('.product > :nth-child(2)').click()
cy.location('pathname').should('equal', '/xxxxx')
// Fund Detail - Search
cy.get('#s2id_autogen31').type('Rach')
cy.get('#select2-result-label-32').click()
cy.get('#searchSubmit').click()
cy.get('#DataTables_Table_0').find('tr').should('have.length', 10)

})
}) 

执行屏幕截图代码段屏幕截图

您必须在beforeEach()中保留cookie,以确保在所有it()块中保持登录状态。你可以在柏树文档中阅读更多。

describe('Dashboard', () => {
before(() => {
// log in only once before any of the tests run.
// your app will likely set some sort of session cookie.
// you'll need to know the name of the cookie(s), which you can find
// in your Resources -> Cookies panel in the Chrome Dev Tools.
cy.login()
})
beforeEach(() => {
// before each test, we can automatically preserve the
// 'session_id' and 'remember_token' cookies. this means they
// will not be cleared before the NEXT test starts.
//
// the name of your cookies will likely be different
// this is an example
Cypress.Cookies.preserveOnce('session_id', 'remember_token')
})
it('displays stats', () => {
// ...
})
it('can do something', () => {
// ...
})
it('opens a modal', () => {
// ...
})
})

我见过这样的行为,当第一个it case开始并没有完成站点中的一些xhr请求时,结果是Cypry在第二个it情况开始时继续该过程。对于我发现的每个案例,最好的解决方案是将每个案例分离在不同的文件中

更新:

能够通过存储session_id来解决此问题。

Cypress.Cookies.defaults({
preserve: "session_id"
})

相关内容

最新更新