简体   繁体   English

赛普拉斯自动重定向到新 URL

[英]Cypress redirects automatically to the new URL

I wrote some test scenarios of one of the webpage and I still face problem during automatic redirection to the login page for one specific ng-container.我写了其中一个网页的一些测试场景,但在自动重定向到一个特定 ng-container 的登录页面时仍然遇到问题。 I have 3 test scenarios and doesnt matter in witch order I run them - always after first or during the second cookie containing login data is deleted and user redirected to the login page.我有 3 个测试场景,我运行它们的顺序无关紧要 - 总是在第一个或第二个包含登录数据的 cookie 被删除并且用户重定向到登录页面之后。 Is any method to prevent redirecting to the another page and deleting 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.


Adding cookie whitelist seems to help:添加 cookie 白名单似乎有帮助:

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

But as I understand documentaion, Cypress should clear chacke only after all test scenarios in specific test file - not each test scenario?但据我了解文档,赛普拉斯应该只在特定测试文件中的所有测试场景之后清除 chacke - 不是每个测试场景?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM