簡體   English   中英

賽普拉斯自動重定向到新 URL

[英]Cypress redirects automatically to the new URL

我寫了其中一個網頁的一些測試場景,但在自動重定向到一個特定 ng-container 的登錄頁面時仍然遇到問題。 我有 3 個測試場景,我運行它們的順序無關緊要 - 總是在第一個或第二個包含登錄數據的 cookie 被刪除並且用戶重定向到登錄頁面之后。 有什么方法可以防止重定向到另一個頁面並刪除 cookie?

import LoginPage from "xxx/LoginPage.spec.js";
import CreateUser from "xxx/CreateUser.spec.js";
import Functions from "Cxxx/Functions.spec.js";

describe('Check role selector', () => {

    const login = new LoginPage();
    const register = new CreateUser();
    const functions = new Functions();

    var usernameCreatedUser = functions.createUsernameAndNick();
    var nickCreatedUser = functions.createUsernameAndNick();

    before(() => {
        cy.visit('login')
        login.fillUsername(Cypress.env('correctUsername'))
        login.fillPassword(Cypress.env('correctPassword'))
        login.checkButtonLogin().should('be.enabled')
            .click()
        login.fillSMScode(Cypress.env('correctSMScode'))
        login.checkButtonLogin().should('be.enabled')
            .click()
        cy.visit('/control-panel/users/add')
        register.fillUsername(usernameCreatedUser)
        register.fillNick(nickCreatedUser)
        register.fillPassword(functions.createPassword())
        register.fillDivision(0)
        register.fillRole(0)
    })



    it('empty', () => {
        register.clearDivision()
        register.getButtonSave().should('be.disabled')
    })

    it('correct - select 2 divisions - only second is selected', () => {
        register.clearDivision()
        register.fillDivision(0)
        register.fillDivision(1)
        register.getDivision("Gdańsk", "Warszawa")
        register.fillDivision(1)
        register.getButtonSave().should('be.enabled')
        debugger 
    })

    it('correct - select 1 division', () => {        
        register.clearDivision()
        register.fillDivision(0)
        register.getDivision("Warszawa", "Gdańsk")
        register.getButtonSave().should('be.enabled')
        debugger
    })

})


class RegisterPage {

  fillDivision(value) {
    cy.get('[formcontrolname="divisionId"]').click()
    cy.get('[class="ng-option-label"]')
      .eq(value)
      .click()
  }

  clearDivision(){
    cy.get('[title="Clear all"]').eq(0)
    .should('be.visible')
    .click()
    cy.get('[formcontrolname="divisionId"]').contains('Wybierz')
    this.getDivisionError()
  }

  getDivision(value1, value2){
    cy.get('[role="combobox"]').contains(value1).should("have.not.value", value2)
  }

  getButtonSave() {
    return cy.get('button').contains('Zapisz')
  }
}
export default RegisterPage;


Console:

cypress_runner.js:174498 console.clear() was prevented due to 'Preserve log'
cypress_runner.js:174490 Command:   get
cypress_runner.js:174490 Yielded:   
(2) [span.ng-clear-wrapper, span.ng-clear-wrapper]
cypress_runner.js:174490 Elements:  2
cypress_runner.js:174490 Selector:  [title="Clear all"]
[Violation] 'click' handler took 213ms
cypress_runner.js:174498 console.clear() was prevented due to 'Preserve log'
cypress_runner.js:174490 Command:     eq
cypress_runner.js:174490 Selector:    0
cypress_runner.js:174490 Applied To:  
(2) [span.ng-clear-wrapper, span.ng-clear-wrapper]
cypress_runner.js:174490 Yielded:     
cypress_runner.js:174490 Elements:    1
[Violation] 'click' handler took 191ms
VM561 login:1 [DOM] Input elements should have autocomplete attributes (suggested: "current-password"): 
cypress_runner.js:174498 console.clear() was prevented due to 'Preserve log'
cypress_runner.js:174490 Command:  assert
cypress_runner.js:174490 Subject:  
jQuery.fn.init [span.ng-clear-wrapper, selector: "0", context: document]
cypress_runner.js:174490 Message:  expected <span.ng-clear-wrapper> to be visible
[Violation] 'click' handler took 227ms
cypress_runner.js:174498 console.clear() was prevented due to 'Preserve log'
cypress_runner.js:174490 Command:     click
cypress_runner.js:174490 Applied To:  
cypress_runner.js:174490 Elements:    1
cypress_runner.js:174490 Coords:      
{x: 867, y: 370}
cypress_runner.js:174542 MouseDown
[Violation] 'click' handler took 231ms
cypress_runner.js:174498 console.clear() was prevented due to 'Preserve log'
cypress_runner.js:174490 Event:        xhr
cypress_runner.js:174490 Method:       GET
cypress_runner.js:174490 URL:          https://xxx/admin-api/division-managed-objects
cypress_runner.js:174490 Status:       401 (Unauthorized)
cypress_runner.js:174490 Duration:     86
cypress_runner.js:174490 Stubbed:      No
cypress_runner.js:174490 Request:      
{headers: {…}, body: null}
cypress_runner.js:174490 Response:     
{headers: {…}, body: 401}
cypress_runner.js:174490 XHR:          
XMLHttpRequest {method: "GET", url: "https:/xxx/admin-api/division-managed-objects", id: "xhr330", __zone_symbol__ON_PROPERTYreadystatechange: ƒ, __zone_symbol__readystatechangefalse: Array(1), …}
cypress_runner.js:174498 console.clear() was prevented due to 'Preserve log'
cypress_runner.js:174490 Event:           new url
cypress_runner.js:174490 New Url:         https:/xxx/login
cypress_runner.js:174490 Url Updated By:  pushState
cypress_runner.js:174490 Args:            
(3) [{…}, "", "/login"]
cypress_runner.js:174498 console.clear() was prevented due to 'Preserve log'
cypress_runner.js:174490 Command:   get
cypress_runner.js:174490 Elements:  0
cypress_runner.js:174490 Selector:  [formcontrolname="divisionId"]
cypress_runner.js:174490 Error:     CypressError: Timed out retrying: Expected to find element: '[formcontrolname="divisionId"]', but never found it.


添加 cookie 白名單似乎有幫助:

  Cypress.Cookies.defaults({
                whitelist: 'AuthUser'
            })

但據我了解文檔,賽普拉斯應該只在特定測試文件中的所有測試場景之后清除 chacke - 不是每個測試場景?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM