我正在尝试通过插件方法(https://docs.cypress.io/api/plugins/configuration-api#Switch-between-multiple-configuration-files)使用环境变量,这以前有效,但最近已停止工作对我来说,任何指针都会很棒。
插件/index.js
const fs = require('fs-extra')
const path = require('path')
function getConfigurationByFile(file) {
const pathToConfigFile = path.resolve('cypress', 'config', `${file}.json`)
return fs.readJson(pathToConfigFile)
}
module.exports = (on, config) => {
const file = config.env.configFile || 'build'
return getConfigurationByFile(file)
}
配置文件 > build.json
{
"env": {
"StudentPortal": "https://www.google.co.uk"
}
}
用法
cy.visit(Cypress.env('StudentPortal'));
正如我所说,这曾经可以工作并且会访问 configFile 中的 URL,现在我只收到以下错误:
CypressError cy.visit() 必须使用 url 或包含 url 作为其第一个参数的选项对象调用了解更多 cypress/support/commands.js:17:8
15 | Cypress.Commands.add('StudentPortalLogin', (email, password) => { 16 |
17 | cy.visit(Cypress.env('StudentPortal'));