2022-05-10 22:47:04 -07:00
|
|
|
// ***********************************************
|
|
|
|
|
// This example commands.js shows you how to
|
|
|
|
|
// create various custom commands and overwrite
|
|
|
|
|
// existing commands.
|
|
|
|
|
//
|
|
|
|
|
// For more comprehensive examples of custom
|
|
|
|
|
// commands please read more here:
|
|
|
|
|
// https://on.cypress.io/custom-commands
|
|
|
|
|
// ***********************************************
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// -- This is a parent command --
|
|
|
|
|
// Cypress.Commands.add('login', (email, password) => { ... })
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// -- This is a child command --
|
|
|
|
|
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// -- This is a dual command --
|
|
|
|
|
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// -- This will overwrite an existing command --
|
|
|
|
|
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
|
|
|
|
|
|
2022-11-16 13:21:23 +05:30
|
|
|
import { interceptURL, verifyResponseStatusCode } from '../common/common';
|
|
|
|
|
import { BASE_URL, LOGIN } from '../constants/constants';
|
|
|
|
|
|
2022-05-10 22:47:04 -07:00
|
|
|
Cypress.Commands.add('loginByGoogleApi', () => {
|
|
|
|
|
cy.log('Logging in to Google');
|
|
|
|
|
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.request({
|
|
|
|
|
method: 'GET',
|
|
|
|
|
url: 'https://www.googleapis.com/oauth2/v3/userinfo',
|
|
|
|
|
headers: { Authorization: `Bearer ${access_token}` },
|
|
|
|
|
}).then(({ body }) => {
|
|
|
|
|
cy.log(body);
|
|
|
|
|
const userItem = {
|
|
|
|
|
token: id_token,
|
|
|
|
|
user: {
|
|
|
|
|
googleId: body.sub,
|
|
|
|
|
email: body.email,
|
|
|
|
|
givenName: body.given_name,
|
|
|
|
|
familyName: body.family_name,
|
|
|
|
|
imageUrl: body.picture,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
window.localStorage.setItem('googleCypress', JSON.stringify(userItem));
|
|
|
|
|
window.localStorage.setItem('oidcIdToken', id_token);
|
2022-05-11 23:35:13 -07:00
|
|
|
cy.visit('/');
|
2022-05-10 22:47:04 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2022-05-18 12:22:50 +05:30
|
|
|
|
|
|
|
|
Cypress.Commands.add('goToHomePage', () => {
|
2022-10-03 16:22:08 +05:30
|
|
|
cy.get('[data-testid="whats-new-dialog"]').should('be.visible');
|
2022-05-18 12:22:50 +05:30
|
|
|
cy.get('[data-testid="closeWhatsNew"]').click();
|
2022-10-03 16:22:08 +05:30
|
|
|
cy.get('[data-testid="whats-new-dialog"]').should('not.exist');
|
2022-05-18 12:22:50 +05:30
|
|
|
});
|
2022-05-18 23:20:41 +05:30
|
|
|
|
|
|
|
|
Cypress.Commands.add('clickOnLogo', () => {
|
|
|
|
|
cy.get('#openmetadata_logo > [data-testid="image"]').click();
|
|
|
|
|
});
|
2022-08-10 14:46:50 +05:30
|
|
|
|
2022-09-19 18:43:39 +05:30
|
|
|
const resizeObserverLoopErrRe = /^[^(ResizeObserver loop limit exceeded)]/;
|
2022-08-10 14:46:50 +05:30
|
|
|
Cypress.on('uncaught:exception', (err) => {
|
2022-09-19 18:43:39 +05:30
|
|
|
/* returning false here prevents Cypress from failing the test */
|
|
|
|
|
if (resizeObserverLoopErrRe.test(err.message)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-11-16 13:21:23 +05:30
|
|
|
|
|
|
|
|
Cypress.Commands.add('storeSession', (username, password) => {
|
|
|
|
|
/*
|
|
|
|
|
Reference docs for session https://docs.cypress.io/api/commands/session
|
|
|
|
|
Its currently Experimental feature, but cypress is encouraging to use this feature
|
|
|
|
|
as Cypress.Cookies.preserveOnce() and Cypress.Cookies.defaults() has been deprecated
|
|
|
|
|
*/
|
2022-11-23 12:42:22 +05:30
|
|
|
|
2022-11-16 13:21:23 +05:30
|
|
|
cy.session([username, password], () => {
|
|
|
|
|
cy.visit('/');
|
|
|
|
|
cy.get('[id="email"]').should('be.visible').clear().type(username);
|
|
|
|
|
cy.get('[id="password"]').should('be.visible').clear().type(password);
|
|
|
|
|
interceptURL('POST', '/api/v1/users/login', 'login');
|
|
|
|
|
cy.get('[data-testid="login"]')
|
|
|
|
|
.contains('Login')
|
|
|
|
|
.should('be.visible')
|
|
|
|
|
.click();
|
|
|
|
|
verifyResponseStatusCode('@login', 200);
|
|
|
|
|
cy.url().should('eq', `${BASE_URL}/my-data`);
|
|
|
|
|
cy.get('[data-testid="tables"]').should('be.visible');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Cypress.Commands.add('login', () => {
|
|
|
|
|
cy.storeSession(LOGIN.username, LOGIN.password);
|
|
|
|
|
cy.visit('/');
|
|
|
|
|
cy.goToHomePage();
|
|
|
|
|
});
|