Hi, how can we pull the data (dynamic value) from commands.js and use it in testFile.cy.js.
Scenario - I am accessing my Gmail account using commands.js >> getting the requested email body, then pulling the data from the body, and saving it in a variable >> now I want to .type the pulled email data (stored in a variable) in my testFile.cy.js.
commands.js
`///
// import xml2js Module
import { parseString } from "xml2js";
Cypress.Commands.add('loginByGoogleApi', () => {
cy.log('Logging in to Gmail')
cy.log(Cypress.env('googleRefreshToken'))
cy.request({
method: 'POST',
url: 'https://www.googleapis.com/oauth2/v4/token',
body: {
grant_type: 'refresh_token',
client_id: Cypress.env('googleClientId'),
client_secret: Cypress.env('googleClientSecret'),
refresh_token: Cypress.env('googleRefreshToken'),
},
}).then(({ body }) => {
const { access_token, id_token } = body
cy.log('Opening emails including code to verify')
cy.request({
method: 'GET',
url: 'https://mail.google.com/mail/feed/atom/verifyCode',
headers: { Authorization:
Bearer ${access_token}
},
}).then(({ body }) => {
parseString(body, function (err, results) {
let data = JSON.stringify(results)
let codeTitle = JSON.parse(data).feed.entry[0].title[0];
let code = codeTitle.replace('Chaine confirmation code: ','');
cy.log(code)
});
});
})
})
`
testFile.cy.js
> const { Code } = require("@chaine/keychaine");
>
>
> describe('Open login page', () => {
> it('Enter your email to login', () => {
> cy.visit('https://chaineapp.com/staging/login')
> cy.get('#field-1').click().type('paras@loadtap.com');
> cy.get('[class*="chakra-button css-yg51i0"]').click();
> cy.get('#pin-input-2-0').type(JSON.stringify(Code));
>
> })
> it('get code', () => {
> cy.loginByGoogleApi()
>
> })
> })