赛普拉斯命令不适用于网络请求

时间:2020-01-22 00:18:41

标签: cypress

以下代码通过Node运行时有效,但是当我尝试将其作为Cypress命令运行时,出现“ Cypress命令超时超过4000毫秒,我不确定为什么。

我的cypress / support / commands.js具有以下代码:

const AWS = require('aws-sdk'), region = "us-east-1", secretName = "portal-
secrets", secret, decodedBinarySecret;
const client = new AWS.SecretsManager({region: region});
function GetTestCredentials() {
  return new Promise(function (resolve, reject) {
    client.getSecretValue({SecretId: secretName}, function (err, data) {
      const loginValues = [];
      if (err) {
          throw err;
      } else {
        secret = JSON.parse(data.SecretString);
        loginValues['username'] = secret[devUsernameSecretsKey];
        loginValues['password'] = secret[devPasswordSecretsKey];
        resolve(loginValues);
      }
    });
  });
}

Cypress.Commands.add('getTestCredentials', () => {
  console.log('get creds')
  return GetTestCredentials();
});

我的测试文件将调用此命令,并且应该为凭据提供一个值,但是没有给出任何值,我得到了超时:

describe('Get Login Credentials from AWS', function() {
  context('Get Login Credentials from AWS', function() {
    it('Should have a username and password value from AWS', function() {
      cy['getTestCredentials']().then(creds => {
        console.log(creds);
        expect(creds['username']).length.gt(1);
      });
    });
  });
});

我不确定为什么它可以在Node中工作而不能在Cypress中工作?任何帮助将不胜感激:thumbsup:

0 个答案:

没有答案