【发布时间】:2020-09-10 17:59:15
【问题描述】:
我正在尝试使用cy.exec 从赛普拉斯测试中调用外部脚本来创建一个环境变量,然后我想在测试中访问该环境变量。这可以使用Cypress.env(<environmental variable>)吗?
外部脚本如下:
const cypress = require('cypress');
const pkg = require('@glib/cypress-secrets');
const { createAuthApiKeyKubeSecret } = pkg;
const username = 'test-consumer';
const apikey = createAuthApiKeyKubeSecret(username);
console.log(apikey);
process.env.apikey = apikey;
此脚本由测试中的 before 函数调用。
describe("Test to create a capability", function () {
before(() => {
cy.exec('node create-secret.js');
});
after(() => {
cy.exec('node delete-secret.js', {log: true});
});
it('Checks on the Create page', function() {
cy.visit(Cypress.config().baseUrl + "?apikey=" + Cypress.env('apikey'));
// We need to check if we are on the correct page
// We just need to check two elements, a label and a button.
cy.contains('About the capability').should('exist');
cy.contains('button', 'Next Step').should('exist')
});
});
baseUrl 设置正确,但 apikey 环境变量返回未定义。
【问题讨论】:
标签: cypress