我尝试运行一个测试,首先,它将获得x-auth-token
,我将该令牌存储在txt文件中,然后获得该令牌并存储在我的commands.js
文件中,如下所示:
Cypress.Commands.add("getAllNoteIDs", () => {
let notes_ids = [];
cy.readFile("cypress/user_data/token.txt").then((token) => {
cy.log("Token is "+token)
}) // Here I am getting correct token
cy.request({
method: "GET",
url: "https://practice.expandtesting.com/notes/api/notes",
form: true,
failOnStatusCode: false,
timeout: 30000,
headers: {
accept: "application/json",
"x-auth-token":
cy.readFile("cypress/user_data/token.txt").then((token) => {
cy.log(token)
}),
},
}).then((response) => {
cy.log(response)
const responseBodyKeys = Cypress._.keys(response.body);
cy.log(responseBodyKeys)
cy.log(response.body['message'])
let results = response.body.data;
for (let i of results) {
notes_ids.push(i.id);
}
cy.wrap(notes_ids);
});
});
字符串
每当我运行这个命令,我得到以下错误:
但是,如果我直接在那里添加token,它运行得很好。我不想遵循这种做法。对此有什么解决方案?
1条答案
按热度按时间5f0d552i1#
x-auth-token类型为
promise
字符串
改变代码
型