Невозможно использовать функцию внутри теста Cypress - PullRequest
0 голосов
/ 21 апреля 2020

Регистрация пользователя через Cypress. При этом я должен получить сообщение о подтверждении через Gmail, поэтому я попытался получить тело электронной почты, используя gamil api, в файле js в функции

"use strict";
const fs = require("fs");
const { promisify } = require("util");
const { google } = require("googleapis");
const { OAuth2Client } = require("google-auth-library");
const gmail = google.gmail("v1");
// Promisify with promise
const readFileAsync = promisify(fs.readFile);
const gmailGetMessagesAsync = promisify(gmail.users.messages.get);
const gmailListMessagesAsync = promisify(gmail.users.messages.list);
const TOKEN_DIR = __dirname;
const TOKEN_PATH = TOKEN_DIR + "/gmail-nodejs-quickstart.json"; 
// Specify the access token file
const main = async () => {
// Get credential information
const content = await readFileAsync(__dirname + "/client_secret.json"); 
// specify the client secret file
const credentials = JSON.parse(content); 
// credential
// authentication
const clientSecret = credentials.installed.client_secret;
const clientId = credentials.installed.client_id;
const redirectUrl = credentials.installed.redirect_uris[0];
const oauth2Client = new OAuth2Client(clientId, clientSecret, redirectUrl);
const token = await readFileAsync(TOKEN_PATH);
oauth2Client.credentials = JSON.parse(token);
let res = await gmailListMessagesAsync({
    auth: oauth2Client,
    userId: 'me',
    maxResults: 1
});
//const newestMessageId = res.messages[0].id; 
const newestMessageId = res["data"]["messages"][0]["id"];

res = await gmailGetMessagesAsync({
    auth: oauth2Client,
    userId: 'me',
    id: newestMessageId
});
};

module.exports.conformation = main;

In register.spe c. js

const gmaild = require ('./getLabels');
describe('Test cases for ', function () {
    before(function () {


       cy.visit('/');

    })

     it('', function () {
   cy.log("test");
        console.log(gmaild. conformation());
     })

   })

Таким образом, когда я пытаюсь, я не могу использовать функцию внутри кипариса, поэтому есть ли другой способ.

...