[英]Cypress: Page doesn't load within the second 'it' block for the click action
如果我在下面的單個“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'塊在登錄方法執行后工作正常。 然后它會阻止僅單擊正確的元素,但頁面永遠不會加載。
PS如果我在單個“it”塊下編寫代碼,頁面加載並正常工作。
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()
中保留您的 cookies 以確保您在所有it()
塊中保持登錄狀態。 您可以在cypress 文檔中閱讀更多內容。
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', () => {
// ...
})
})
更新:
可以通過存儲 session_id 來解決這個問題。
Cypress.Cookies.defaults({
preserve: "session_id"
})
我見過這種行為,當第一個it case
開始並且沒有完成站點中的一些 xhr 請求時 - 結果賽普拉斯在第二個 it 案例開始期間繼續該過程。 對於我發現的每個案例,最好的解決方案是將每個案例分開放在不同的文件中
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.