如何解决赛普拉斯测试
我正在尝试在我的应用中使用赛普拉斯进行集成测试,但是当该测试单击按钮时,我收到一个错误消息:account.jsx:344 PUT http:// localhost:3001 / accounts / updateaccountv2 401(未经授权)
我认为这表示未调用该API,但我不知道如何解决该问题。
这是我的代码:
/// <reference types="cypress" />
context('FATBBOAR',() => {
//-------------------- Connextion
beforeEach(() => {
cy.visit('http://localhost:3000/')
})
it('Connexion',() => {
// cy.visit('http://localhost:3000/')
cy.get('.fatb-btn.btn-connexion').click()
// cy.url().should('include','/');
// Get an input,type into it and verify that the value has been updated
cy.get('[name="cnx_mail"]')
.type('meryem.achemlal@gmail.com',{ force: true })
.should('have.value','meryem.achemlal@gmail.com')
cy.get('[name="cnx_pwd"]')
.type('admin1234','admin1234')
cy.contains('se connecter').click()
// cy.url().should('include','/')
// })
//-------------------- Mon compte
// it('Mon compte',() => {
cy.visit('http://localhost:3000/account')
cy.url().should('include','/account')
cy.contains('Mon compte').click()
cy.visit('http://localhost:3000/account')
// cy.get('Mon compte').click()
// $('[name="acc_email"]').on('keydown',(e) => {
// e.preventDefault()
// })
cy.get('[name="acc_email"]')
.type('meryem.achemlal@gmail.com')
.should('have.value','meryem.achemlal@gmail.com')
cy.get('[name="acc_nom"]')
.type('my namu')
.should('have.value','my namu')
cy.get('[name="acc_prenom"]')
.type('my prenom')
.should('have.value','my prenom')
cy.get('[name="acc_tel"]')
.type('0645126200')
.should('have.value','0645126200')
cy.get('[name="acc_pwd"]')
.type('admin1234','admin1234')
cy.get('Modifier').click()
// Get the token when Google/facebook Auth
const auth_head = document.cookie.split('.')[0];
const auth_payload = document.cookie.split('.')[1];
const auth_signature = document.cookie.split('.')[2];
var auth_token = auth_head + '.' + auth_payload + '.' + auth_signature;
var Aauth_token = auth_token.substr(6);
cy.request({
method: 'PUT',url: 'http://localhost:3001/accounts/updateaccountv2',// baseUrl is prepended to url
form: true,// indicates the body should be form urlencoded and sets Content-Type: application/x-www-form-urlencoded headers
headers: {
'Content-Type': 'application/json',authorization: `Bearer ${Aauth_token}`,},body: {
email: 'caci',nom: 'azaz1234',prenom: 'prinoum',tel: '0754121212'
}
})
// to prove we have a session
cy.getCookie('cypress-session-cookie').should('exist')
})
})
这是错误:
请有人帮忙,很难在互联网上找到解决方案 谢谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。