0

我正在尝试通过插件方法(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'));

4

1 回答 1

0

看来 baseURL 可能丢失了。cy.visit()正在寻找参考 baseURL 的东西。我没有在 build.json 文件中看到任何定义,这可能会修复错误以添加 baseURL,“https://www.google.co.uk”,然后将身份验证参数放入 env{} 部分,每您链接中的示例。

于 2021-11-12T23:20:08.370 回答