chore: move cypress-v2 to cypress

This commit is contained in:
Wing-Kam Wong
2022-09-06 11:40:22 +08:00
parent d628a5f4aa
commit db2b6bf006
87 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,597 @@
// ***********************************************
// 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
// ***********************************************
// @author Roman Rezinkin roman.rezinkin@hotmail.com
//
// -- 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) => { ... })
import "cypress-file-upload";
import { isXcdb, isPostgres } from "./page_objects/projectConstants";
require("@4tw/cypress-drag-drop");
// for waiting until page load
Cypress.Commands.add("waitForSpinners", () => {
cy.visit("http://localhost:3000/signup", {
retryOnNetworkFailure: true,
timeout: 1200000,
headers: {
"Accept-Encoding": "gzip, deflate",
},
});
cy.get(".nc-form-signup").should("exist")
});
Cypress.Commands.add("signinOrSignup", (_args) => {
const args = Object.assign(
{ username: "user@nocodb.com", password: "Password123." },
_args
);
cy.wait(1000);
// signin/signup
cy.get("body").then(($body) => {
// cy.wait(1000)
cy.url().then((url) => {
if (!url.includes("/projects")) {
// handle initial load
if ($body.find(".welcome-page").length > 0) {
cy.wait(8000);
cy.get("body").trigger("mousemove");
cy.snip("LetsBegin");
cy.contains("Let's Begin").click();
cy.get('input[type="text"]', { timeout: 12000 }).type(
args.username
);
cy.get('input[type="password"]').type(args.password);
cy.snip("SignUp");
cy.get('button:contains("SIGN UP")').click();
// handle signin
} else {
cy.get('input[type="text"]', { timeout: 12000 }).type(
args.username
);
cy.get('input[type="password"]').type(args.password);
cy.snip("SignIn");
cy.get('button:contains("SIGN IN")').click();
}
} else if (url.includes("/signin")) {
cy.get('input[type="text"]', { timeout: 12000 }).type(
args.username
);
cy.get('input[type="password"]').type(args.password);
cy.snip("SignIn");
cy.get('button:contains("SIGN IN")').click();
}
});
});
// indicates page-load complete
cy.get(".nc-noco-brand-icon", { timeout: 12000 }).should("exist");
});
// for opening/creating a rest project
Cypress.Commands.add("openOrCreateRestProject", (_args) => {
const args = Object.assign({ new: false }, _args);
// signin/signup
cy.signinOrSignup();
cy.get(".nc-new-project-menu").should("exist");
cy.snip("ProjectPage");
cy.get("body").then(($body) => {
const filter = args.meta
? ".nc-meta-project-row"
: ":not(.nc-meta-project-row)";
// if project exist open
if (
$body.find(".nc-rest-project-row").filter(filter).length &&
!args.new
) {
cy.get(".nc-rest-project-row").filter(filter).first().click();
} else {
cy.contains("New Project")
.trigger("onmouseover")
.trigger("mouseenter");
if (args.meta) {
cy.get(".nc-create-xc-db-project").click();
cy.url({ timeout: 6000 }).should("contain", "#/project/xcdb");
cy.get(".nc-metadb-project-name").type(
"test_proj" + Date.now()
);
cy.contains("button", "Create", { timeout: 3000 }).click();
} else {
cy.get(".nc-create-external-db-project").click();
cy.url({ timeout: 6000 }).should("contain", "#/project");
cy.get(".database-field input").click().clear().type("sakila");
cy.contains("Test Database Connection").click();
cy.contains("Ok & Save Project", { timeout: 3000 }).click();
}
}
});
cy.url({ timeout: 20000 }).should("contain", "#/nc/");
});
Cypress.Commands.add("refreshTableTab", () => {
cy.task("log", `[refreshTableTab]`);
cy.get(".nc-project-tree")
.find(".v-list-item__title:contains(Tables)", { timeout: 10000 })
.should("exist")
.first()
.rightclick({ force: true });
cy.getActiveMenu()
.find('[role="menuitem"]')
.contains("Tables Refresh")
.should("exist")
.click({ force: true });
cy.toastWait("Tables refreshed");
});
// tn: table name
// rc: row count. validate row count if rc!=0
Cypress.Commands.add("openTableTab", (tn, rc) => {
cy.task("log", `[openTableTab] ${tn} ${rc}`);
cy.get(`.nc-project-tree-tbl-${tn}`)
.should("exist")
.first()
.click();
// kludge to make new tab active
// cy.get('.ant-tabs-tab-btn')
// .contains(tn)
// .should('exist')
// .click();
cy.wait(3000);
cy.get('.xc-row-table.nc-grid').should('exist');
// wait for page rendering to complete
if (rc != 0) {
cy.get(".nc-grid-row").should("have.length", rc);
}
});
Cypress.Commands.add("closeTableTab", (tn) => {
cy.task("log", `[closeTableTab] ${tn}`);
cy.get('.ant-tabs-tab-btn')
.contains(tn)
.should('exist')
.parent()
.parent()
.find('button')
.click();
// subsequent tab open commands will fail if tab is not closed completely
cy.wait(1000);
});
Cypress.Commands.add("openOrCreateGqlProject", (_args) => {
const args = Object.assign({ new: false, meta: false }, _args);
cy.signinOrSignup();
cy.get(".nc-new-project-menu").should("exist");
cy.get("body").then(($body) => {
const filter = args.meta
? ".nc-meta-project-row"
: ":not(.nc-meta-project-row)";
// if project exist open
if (
$body.find(".nc-graphql-project-row").filter(filter).length &&
!args.new
) {
cy.get(".nc-graphql-project-row").filter(filter).first().click();
} else {
cy.contains("New Project")
.trigger("onmouseover")
.trigger("mouseenter");
if (args.meta) {
cy.get(".nc-create-xc-db-project").click();
cy.url({ timeout: 6000 }).should("contain", "#/project/xcdb");
cy.contains("GRAPHQL APIs").closest("label").click();
cy.get(".nc-metadb-project-name").type(
"test_proj" + Date.now()
);
cy.contains("button", "Create", { timeout: 3000 }).click();
} else {
cy.get(".nc-create-external-db-project").click();
cy.url({ timeout: 6000 }).should("contain", "#/project");
cy.contains("GRAPHQL APIs").closest("label").click();
cy.get(".database-field input").click().clear().type("sakila");
cy.contains("Test Database Connection").click();
cy.contains("Ok & Save Project").should('exist').click();
}
}
});
cy.url({ timeout: 20000 }).should("contain", "#/nc/");
});
let LOCAL_STORAGE_MEMORY = {};
let LOCAL_STORAGE_MEMORY_v2 = {};
Cypress.Commands.add("saveLocalStorage", (name) => {
if(name) {
cy.task('log', `[saveLocalStorage] ${name}`);
LOCAL_STORAGE_MEMORY_v2[name] = {}
Object.keys(localStorage).forEach((key) => {
LOCAL_STORAGE_MEMORY_v2[name][key] = localStorage[key];
});
return;
}
LOCAL_STORAGE_MEMORY = {};
Object.keys(localStorage).forEach((key) => {
LOCAL_STORAGE_MEMORY[key] = localStorage[key];
});
cy.printLocalStorage();
});
Cypress.Commands.add("restoreLocalStorage", (name) => {
if(name) {
cy.task('log', `[restoreLocalStorage] ${name}`);
Object.keys(LOCAL_STORAGE_MEMORY_v2[name]).forEach((key) => {
localStorage.setItem(key, LOCAL_STORAGE_MEMORY_v2[name][key]);
});
return;
}
cy.deleteLocalStorage().then(() => {
Object.keys(LOCAL_STORAGE_MEMORY).forEach((key) => {
localStorage.setItem(key, LOCAL_STORAGE_MEMORY[key]);
});
cy.printLocalStorage();
});
});
Cypress.Commands.add("deleteLocalStorage", () => {
Object.keys(LOCAL_STORAGE_MEMORY).forEach((key) => {
localStorage.removeItem(key);
});
});
Cypress.Commands.add('printLocalStorage', () => {
cy.task('log', `[printLocalStorage]`);
cy.task('log', JSON.stringify(localStorage, null, 2));
cy.task('log', JSON.stringify(LOCAL_STORAGE_MEMORY, null, 2));
})
Cypress.Commands.add("getActiveModal", () => {
return cy.get(".ant-modal-content:visible").last()
});
Cypress.Commands.add("getActiveMenu", () => {
return cy.get(".ant-dropdown-content:visible").last();
});
Cypress.Commands.add("getActivePopUp", () => {
return cy.get(".ant-menu-submenu-popup:visible").last();
})
Cypress.Commands.add("getActiveSelection", () => {
return cy.get(".ant-select-dropdown:visible").last();
})
Cypress.Commands.add("getActiveDrawer", () => {
return cy.get(".ant-drawer-content:visible").last();
});
Cypress.Commands.add("getActivePicker", () => {
return cy.get(".ant-picker-dropdown :visible").last();
});
Cypress.Commands.add("createTable", (name) => {
cy.task("log", `[createTableTab] ${name}`);
cy.wait(1000);
cy.get('.nc-add-new-table').should('exist').click();
cy.wait(1000);
cy.getActiveModal().find(`input[type="text"]:visible`)
.click()
.clear()
.type(name)
// submit button
cy.getActiveModal().find("button.ant-btn-primary:visible").click();
cy.wait(1000)
cy.get('.xc-row-table.nc-grid').should('exist');
// cy.get('.ant-tabs-tab-active > .ant-tabs-tab-btn').contains(name).should("exist");
cy.url().should("contain", `table/${name}`);
cy.get(`.nc-project-tree-tbl-${name}`).should("exist");
cy.wait(1000)
});
Cypress.Commands.add("deleteTable", (name, dbType) => {
cy.get(`.nc-project-tree-tbl-${name}`).should("exist").rightclick();
cy.getActiveMenu().find('[role="menuitem"]').contains("Delete").click();
cy.getActiveModal().find("button").contains("Yes").click();
cy.toastWait(`Deleted table successfully`);
});
Cypress.Commands.add("renameTable", (oldName, newName) => {
// right click on project table name
cy.get(`.nc-project-tree-tbl-${oldName}`)
.should('exist')
.first()
.rightclick();
// choose rename option from menu
cy.getActiveMenu()
.find('[role="menuitem"]')
.contains("Rename")
.click({ force: true });
// feed new name
cy.getActiveModal().find("input").clear().type(newName);
// submit
cy.getActiveModal().find("button").contains("Submit").click();
cy.toastWait("Table renamed successfully");
});
Cypress.Commands.add("createColumn", (table, columnName) => {
cy.get(".nc-project-tree")
.find(".v-list-item__title:contains(Tables)")
.should('exist')
.first()
.click();
cy.get(".nc-project-tree")
.contains(table)
.should('exist')
.first()
.click({ force: true });
cy.get(`.project-tab:contains(${table}):visible`).should("exist");
cy.get(".v-window-item--active .nc-grid tr > th:last button").click({
force: true,
});
cy.get(".nc-column-name-input input").clear().type(columnName);
cy.getActiveMenu("Menu_CreateColumn");
cy.get(".nc-col-create-or-edit-card").contains("Save").click();
cy.get("th:contains(new_column)").should("exist");
});
Cypress.Commands.add("toastWait", (msg) => {
// cy.get('.ant-message-notice-content:visible', { timout: 30000 }).should('exist')
cy.get('.ant-message-notice-content:visible', { timout: 30000 }).contains(msg).should('exist')
cy.get('.ant-message-notice-content:visible', { timout: 12000 }).should('not.exist')
});
// vn: view name
// rc: expected row count. validate row count if rc!=0
Cypress.Commands.add("openViewsTab", (vn, rc) => {
cy.task("log", `[openViewsTab] ${vn} ${rc}`);
cy.get(`.nc-project-tree-tbl-${vn}`, { timeout: 10000 }).should("exist")
.first()
.click({ force: true });
// kludge to make new tab active
cy.get('.ant-tabs-tab-btn')
.contains(vn)
.should('exist')
.click({ force: true });
// wait for page rendering to complete
if (rc != 0) {
cy.get('.xc-row-table.nc-grid').should('exist');
cy.get(".nc-grid-row").should("have.length", rc);
}
});
Cypress.Commands.add("closeViewsTab", (vn) => {
cy.task("log", `[closeViewsTab] ${vn}`);
cy.get('.ant-tabs-tab-btn')
.contains(vn)
.should('exist')
.parent()
.parent()
.find('button')
.click();
});
// Support for screen-shots
//
let screenShotDb = [];
// snip entire screen
Cypress.Commands.add("snip", (filename) => {
if (
true === Cypress.env("screenshot") &&
false === screenShotDb.includes(filename)
) {
let storeName = `${screenShotDb.length}_${filename}`;
screenShotDb.push(filename);
cy.wait(1000);
cy.screenshot(storeName, { overwrite: true });
}
});
// snip current modal
Cypress.Commands.add("snipActiveModal", (filename) => {
if (
true === Cypress.env("screenshot") &&
false === screenShotDb.includes(filename)
) {
let storeName = `${screenShotDb.length}_${filename}`;
screenShotDb.push(filename);
cy.wait(1000);
// cy.getActiveModal().screenshot(filename, {
// padding: 0,
// overwrite: true,
// });
cy.screenshot(storeName, { overwrite: true });
}
});
// snip current menu
Cypress.Commands.add("snipActiveMenu", (filename) => {
if (
true === Cypress.env("screenshot") &&
false === screenShotDb.includes(filename)
) {
let storeName = `${screenShotDb.length}_${filename}`;
screenShotDb.push(filename);
cy.wait(1000);
// cy.getActiveMenu().screenshot(filename, {
// padding: 0,
// overwrite: true,
// });
cy.screenshot(storeName, { overwrite: true });
}
});
// pre-test file hook
Cypress.Commands.add("fileHook", () => {
window.localStorage.setItem('vueuse-color-scheme', 'light')
});
Cypress.Commands.add("signOut", () => {
// sign out
cy.visit(`/`);
cy.get('.nc-project-page-title', {timeout: 30000}).contains("My Projects").should("be.visible");
cy.get('.nc-menu-accounts', {timeout: 30000}).should('exist').click();
cy.getActiveMenu().find('.ant-dropdown-menu-item').eq(1).click();
cy.wait(5000);
cy.get('button:contains("SIGN")').should('exist')
});
// Drag n Drop
// refer: https://stackoverflow.com/a/55409853
/*
const getCoords = ($el) => {
const domRect = $el[0].getBoundingClientRect()
const coords = { x: domRect.left + (domRect.width / 2 || 0), y: domRect.top + (domRect.height / 2 || 0) }
return coords
}
const dragTo = (subject, to, opts) => {
opts = Cypress._.defaults(opts, {
// delay inbetween steps
delay: 0,
// interpolation between coords
steps: 0,
// >=10 steps
smooth: false,
})
if (opts.smooth) {
opts.steps = Math.max(opts.steps, 10)
}
const win = subject[0].ownerDocument.defaultView
const elFromCoords = (coords) => win.document.elementFromPoint(coords.x, coords.y)
const winMouseEvent = win.MouseEvent
const send = (type, coords, el) => {
el = el || elFromCoords(coords)
el.dispatchEvent(
new winMouseEvent(type, Object.assign({}, { clientX: coords.x, clientY: coords.y }, { bubbles: true, cancelable: true }))
)
}
const toSel = to
function drag (from, to, steps = 1) {
const fromEl = elFromCoords(from)
const _log = Cypress.log({
$el: fromEl,
name: 'drag to',
message: toSel,
})
_log.snapshot('before', { next: 'after', at: 0 })
_log.set({ coords: to })
send('mouseover', from, fromEl)
send('mousedown', from, fromEl)
cy.then(() => {
return Cypress.Promise.try(() => {
if (steps > 0) {
const dx = (to.x - from.x) / steps
const dy = (to.y - from.y) / steps
return Cypress.Promise.map(Array(steps).fill(), (v, i) => {
i = steps - 1 - i
let _to = {
x: from.x + dx * (i),
y: from.y + dy * (i),
}
send('mousemove', _to, fromEl)
return Cypress.Promise.delay(opts.delay)
}, { concurrency: 1 })
}
})
.then(() => {
send('mousemove', to, fromEl)
send('mouseover', to)
send('mousemove', to)
send('mouseup', to)
_log.snapshot('after', { at: 1 }).end()
})
})
}
const $el = subject
const fromCoords = getCoords($el)
const toCoords = getCoords(cy.$$(to))
drag(fromCoords, toCoords, opts.steps)
}
Cypress.Commands.addAll(
{ prevSubject: 'element' },
{
dragTo,
}
)
*/

View File

@@ -0,0 +1,32 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************
// Import commands.js using ES2015 syntax:
import "./commands";
// https://www.cypress.io/blog/2020/02/12/working-with-iframes-in-cypress/
import "cypress-iframe";
// Alternatively you can use CommonJS syntax:
// require('./commands')
Cypress.on("uncaught:exception", (err, runnable) => {
// returning false here prevents Cypress from
// failing the test
console.log("uncaught:exception");
console.log(err);
console.log(runnable);
return false;
});

View File

@@ -0,0 +1,547 @@
import { projectsPage } from "./navigation";
const path = require("path");
/**
* Delete the downloads folder to make sure the test has "clean"
* slate before starting.
*/
export const deleteDownloadsFolder = () => {
const downloadsFolder = Cypress.config("downloadsFolder");
cy.task("deleteFolder", downloadsFolder);
};
export class _settingsPage {
constructor() {
// menu
this.TEAM_N_AUTH = "teamAndAuth";
this.APPSTORE = "appStore";
this.PROJ_METADATA = "metaData";
this.AUDIT = "audit";
// submenu
this.USER_MANAGEMENT = "usersManagement";
this.API_TOKEN_MANAGEMENT = "apiTokenManagement";
this.APPS = "new";
this.METADATA = "metaData";
this.UI_ACCESS_CONTROL = "acl";
this.AUDIT_LOG = "audit";
}
openMenu(menuId) {
// open settings tab
// cy.get('.nc-team-settings').should('exist').click()
// cy.get(`[data-menu-id=${menuId}]`).should('exist').click()
cy.get('.nc-project-menu').should('exist').click()
cy.getActiveMenu().find(`[data-menu-id="teamAndSettings"]`).should('exist').click()
cy.get(`[data-menu-id=${menuId}]`).should('exist').click()
}
openTab(tabId) {
cy.get(`[data-menu-id=${tabId}]`).should('exist').last().click()
}
closeMenu() {
cy.getActiveModal().find('.nc-modal-close').click({ force: true });
}
openProjectMenu() {
cy.get('.nc-project-menu').should('exist').click()
}
}
// main page
export class _mainPage {
constructor() {
// Top Left items
this.HOME = 0;
this.AUDIT = 0;
this.APPSTORE = 2;
this.TEAM_N_AUTH = 3;
this.PROJ_METADATA = 4;
this.ROLE_VIEW = 5;
this.ROLE_VIEW_EDITOR = 6;
this.ROLE_VIEW_COMMENTER = 7;
this.ROLE_VIEW_VIEWER = 8;
this.ROLE_VIEW_RESET = 9;
this.roleURL = {};
}
toolBarTopLeft(toolBarItem) {
return cy
.get("header.v-toolbar", { timeout: 20000 })
.eq(0)
.find("a")
.eq(toolBarItem);
}
toolBarTopRight(toolBarItem) {
return cy
.get("header.v-toolbar", { timeout: 20000 })
.eq(0)
.find("button")
.eq(toolBarItem);
}
navigationDraw(item) {
// open settings tab
cy.get('.nc-project-menu').should('exist').click()
cy.getActiveMenu().find(`[data-menu-id="teamAndSettings"]`).should('exist').click()
switch (item) {
case this.AUDIT:
return cy.get(".nc-settings-audit:visible").should("exist");
case this.APPSTORE:
return cy.get(".nc-settings-appstore:visible").should("exist");
case this.TEAM_N_AUTH:
return cy.get(".nc-settings-teamauth:visible").should("exist");
case this.PROJ_METADATA:
return cy.get(".nc-settings-projmeta:visible").should("exist");
}
}
// add new user to specified role
//
addNewUserToProject = (userCred, roleType) => {
let linkText;
let roleIndex = ["creator", "editor", "commenter", "viewer"].indexOf(roleType)
// click on New User button, feed details
cy.get('button.nc-invite-team').click();
cy.get('input[placeholder="E-mail"]')
.type(userCred.username)
cy.get('.ant-select.nc-user-roles').click();
// opt-in requested role & submit
// cy.getActiveSelection().contains(roleType).click({force: true});
cy.getActiveSelection().find('.nc-role-option').eq(roleIndex).should('exist').click()
cy.getActiveModal().find("button.ant-btn-primary").click();
cy.toastWait("Successfully updated the user details");
// get URL, invoke
cy.getActiveModal()
.find(".ant-alert-message")
.then(($obj) => {
linkText = $obj.text().trim();
cy.log(linkText);
this.roleURL[roleType] = linkText;
cy.get("body").click("right");
});
};
addExistingUserToProject = (emailId, role) => {
cy.get('.v-list-item:contains("Team & Auth")').click();
cy.get(`tr:contains(${emailId})`)
.find(".mdi-plus", { timeout: 2000 })
.click();
cy.get(`tr:contains(${emailId})`)
.find(".mdi-pencil-outline", { timeout: 2000 })
.click();
cy.get("label:contains(Select User Role)").click();
// opt-in requested role & submit
//
cy.getActiveMenu().contains(role).click();
cy.get(".nc-invite-or-save-btn").click();
cy.toastWait("Successfully updated the user details");
this.roleURL[role] =
"http://localhost:3000/#/user/authentication/signin";
};
getCell = (columnHeader, cellNumber) => {
return cy.get(
`:nth-child(${cellNumber}) > [data-title="${columnHeader}"]`
).last();
};
getPagination = (pageNumber) => {
if (pageNumber == "<")
return cy.get(".nc-pagination > .ant-pagination-prev");
if (pageNumber == ">")
return cy.get(".nc-pagination > .ant-pagination-next");
return cy.get(
`.nc-pagination > .ant-pagination-item.ant-pagination-item-${pageNumber}`
);
};
getRow = (rowIndex) => {
return cy.get(".xc-row-table").find("tr").eq(rowIndex);
};
addColumn = (colName, tableName) => {
cy.get(".nc-column-add").click({
force: true,
});
cy.getActiveMenu().find('input.nc-column-name-input', { timeout: 3000 })
.should('exist')
.clear()
.type(colName);
cy.get(".ant-btn-primary").contains("Save").should('exist').click();
cy.toastWait(`Column created`);
cy.get(`th[data-title="${colName}"]`).should("exist");
};
addColumnWithType = (colName, colType, tableName) => {
cy.get(".nc-column-add").click({
force: true,
});
cy.getActiveMenu().find('input.nc-column-name-input', { timeout: 3000 })
.should('exist')
.clear()
.type(colName);
// change column type and verify
cy.get(".nc-column-type-input").last().click();
cy.getActiveSelection().find('.ant-select-item-option').contains(colType).click();
cy.get(".ant-btn-primary:visible").contains("Save").click();
cy.toastWait(`Column created`);
cy.get(`th[data-title="${colName}"]`).should("exist");
};
deleteColumn = (colName) => {
cy.get(`th:contains(${colName})`).should("exist");
cy.get(`th:contains(${colName}) .nc-icon.ant-dropdown-trigger`)
.trigger("mouseover", { force: true })
.click({ force: true });
cy.wait(500)
cy.get(".nc-column-delete").click();
cy.wait(500)
cy.get(".nc-column-delete").should("not.be.visible");
cy.get(".ant-btn-dangerous:visible").contains("Delete").click();
cy.wait(500)
cy.get(`th:contains(${colName})`).should("not.exist");
};
getAuthToken = () => {
let obj = JSON.parse(localStorage["vuex"]);
return obj["users"]["token"];
};
configureSMTP = (from, host, port, secure) => {
cy.getActiveModal().find('.nc-app-store-card-SMTP').click().then((obj) => {
cy.wrap(obj).find('.nc-app-store-card-install').click({ force: true });
})
cy.getActiveModal().find('#form_item_from').should('exist').clear().type(from)
cy.getActiveModal().find('#form_item_host').should('exist').clear().type(host)
cy.getActiveModal().find('#form_item_port').should('exist').clear().type(port)
// cy.getActiveModal().find('#form_item_secure').should('exist').clear().type(secure)
cy.getActiveModal().find("button").contains("Save").click();
cy.toastWait('Successfully installed and email notification will use SMTP configuration');
settingsPage.closeMenu()
};
resetSMTP = () => {
cy.getActiveModal().find('.nc-app-store-card-SMTP').click().then((obj) => {
cy.wrap(obj).find('.nc-app-store-card-reset').click({ force: true });
})
cy.getActiveModal().find("button").contains("Confirm").click();
cy.toastWait("Plugin uninstalled successfully");
settingsPage.closeMenu()
};
shareView = () => {
return cy.get(".nc-btn-share-view").should("exist");
};
shareViewList = () => {
cy.get(".nc-actions-menu-btn").should('exist').click();
return cy.getActiveMenu().find('.ant-dropdown-menu-item').contains('Shared View List');
};
downloadCsv = () => {
cy.get(".nc-actions-menu-btn").should('exist').click();
return cy.getActiveMenu().find('.ant-dropdown-menu-item').contains('Download as CSV');
};
downloadExcel = () => {
cy.get(".nc-actions-menu-btn").should('exist').click();
return cy.getActiveMenu().find('.ant-dropdown-menu-item').contains('Download as XLSX');
};
uploadCsv = () => {
cy.get(".nc-actions-menu-btn").should('exist').click();
return cy.getActiveMenu().find('.ant-dropdown-menu-item').contains('Upload CSV');
};
automations = () => {
cy.get(".nc-actions-menu-btn").should('exist').click();
return cy.getActiveMenu().find('.ant-dropdown-menu-item').contains('Webhooks');
};
hideField = (field) => {
cy.get(`th[data-title="${field}"]`).should("be.visible");
cy.get(".nc-fields-menu-btn").click();
cy.wait(500)
cy.getActiveMenu().find(`.nc-fields-list label:contains(${field}):visible`).click();
cy.wait(500)
cy.get(".nc-fields-menu-btn").click();
cy.wait(500)
cy.get(`th[data-title="${field}"]`).should("not.exist");
};
unhideField = (field) => {
cy.get(`th[data-title="${field}"]`).should("not.exist");
cy.get(".nc-fields-menu-btn").click();
cy.wait(500)
cy.getActiveMenu().find(`.nc-fields-list label:contains(${field}):visible`).click();
cy.wait(500)
cy.get(".nc-fields-menu-btn").click();
cy.wait(500)
cy.get(`th[data-title="${field}"]`).should("be.visible");
};
sortField = (field, criteria) => {
cy.get(".nc-sort-menu-btn").click();
cy.wait(500)
cy.getActiveMenu().contains("Add Sort Option").click();
cy.wait(500)
// cy.get(".nc-sort-field-select div").first().click().type(field);
cy.get(".nc-sort-field-select div").first().click();
cy.wait(500)
cy.get('.ant-select-dropdown:visible').find(`.ant-select-item`).contains(new RegExp("^" + field + "$", "g")).should('exist').click();
cy.wait(500)
cy.get(".nc-sort-dir-select div").first().click();
cy.wait(500)
cy.get('.ant-select-dropdown:visible').find(`.ant-select-item`).contains(criteria).should('exist').click();
cy.wait(500)
cy.get(".nc-sort-menu-btn").click();
cy.wait(500)
};
clearSort = () => {
cy.get(".nc-sort-menu-btn").click();
cy.wait(500)
cy.get(".nc-sort-item-remove-btn").click();
cy.wait(500)
cy.get(".nc-sort-item-remove-btn:visible").should("not.exist");
cy.get(".nc-sort-menu-btn").click();
cy.wait(500)
};
filterField = (field, operation, value) => {
cy.get(".nc-filter-menu-btn").click();
cy.wait(500)
cy.contains("Add Filter").click();
cy.wait(500)
// cy.get(".nc-filter-field-select").should("exist").last().click().type(field);
cy.get(".nc-filter-field-select").should("exist").last().click();
cy.wait(500)
cy.get('.ant-select-dropdown:visible').should('exist').find(`.ant-select-item`).contains(new RegExp("^" + field + "$", "g")).should('exist').click();
cy.wait(500)
cy.get(".nc-filter-operation-select").should("exist").last().click();
cy.wait(500)
cy.get('.ant-select-dropdown:visible').should('exist').find(`.ant-select-item`).contains(operation).should('exist').click();
cy.wait(500)
if (operation != "is null" && operation != "is not null") {
cy.get(".nc-filter-value-select")
.should("exist")
.last()
.type(value);
cy.get(".nc-filter-operation-select").last().click();
cy.wait(500)
}
cy.get(".nc-filter-menu-btn").click();
cy.wait(500)
};
filterReset = () => {
cy.get(".nc-filter-menu-btn").click();
cy.wait(500)
cy.get(".nc-filter-item-remove-btn").click();
cy.wait(500)
cy.get(".nc-filter-item-remove-btn").should("not.exist");
cy.get(".nc-filter-menu-btn").click();
cy.wait(500)
};
// delete created views
//
deleteCreatedViews = () => {
this.shareViewList().click();
cy.get('th:contains("View Link")')
.should("be.visible")
.parent()
.parent()
.next()
.find("tr")
.each(($tableRow) => {
cy.log($tableRow[0].childElementCount);
// one of the row would contain seggregation header ('other views)
if (5 == $tableRow[0].childElementCount) {
cy.wrap($tableRow).find(".nc-icon").last().click();
cy.wait(100);
}
})
.then(() => {
cy.toastWait("Deleted shared view successfully");
cy.getActiveModal().find("button.ant-modal-close").should('exist').click();
});
};
// download CSV & verify
// download folder is configurable in cypress.
// trigger download
// wait for a while & check in configured download folder for the intended file
// if it exists, verify it against 'expectedRecords' passed in as parameter
//
downloadAndVerifyCsv = (filename, verifyCsv, role) => {
if(role === 'commenter' || role === 'viewer') {
cy.get(".nc-actions-menu-btn").click();
cy.getActiveMenu().find('.nc-project-menu-item').contains('Download as CSV').click();
} else {
cy.get(".nc-actions-menu-btn").click();
cy.getActiveMenu().find('.nc-project-menu-item').contains('Download').click();
cy.wait(1000);
cy.get('.nc-project-menu-item').contains('Download as CSV').should('exist').click();
}
cy.toastWait("Successfully exported all table data").then(() => {
// download folder path, read from config file
const downloadsFolder = Cypress.config("downloadsFolder");
let filePath = path.join(downloadsFolder, filename);
// append download folder path with filename to generate full file path, retrieve file
cy.readFile(filePath).then((fileData) => {
// from CSV, split into records (rows)
const rows = fileData.replace(/\r\n/g, "\n").split("\n");
verifyCsv(rows);
deleteDownloadsFolder();
});
});
};
downloadAndVerifyCsvFromSharedView = (filename, verifyCsv) => {
cy.get(".nc-actions-menu-btn").click();
cy.get('.nc-project-menu-item').contains('Download as CSV').should('exist').click();
cy.toastWait("Successfully exported all table data").then(() => {
// download folder path, read from config file
const downloadsFolder = Cypress.config("downloadsFolder");
let filePath = path.join(downloadsFolder, filename);
// append download folder path with filename to generate full file path, retrieve file
cy.readFile(filePath).then((fileData) => {
// from CSV, split into records (rows)
const rows = fileData.replace(/\r\n/g, "\n").split("\n");
verifyCsv(rows);
deleteDownloadsFolder();
});
});
};
getIFrameCell = (columnHeader, cellNumber) => {
return cy
.iframe()
.find(
`tbody > :nth-child(${cellNumber}) > [data-col="${columnHeader}"]`
);
};
// https://docs.cypress.io/guides/core-concepts/variables-and-aliases#Sharing-Context
getDatatype = (tableName, columnName) => {
cy.window().then((win) => {
const col = win.$nuxt.$store.state.meta.metas[tableName].columns;
let dataType = "";
col.forEach((element) => {
if (element.cn == columnName) dataType = element.uidt;
});
cy.wrap(dataType).as("ncDatatype");
});
};
openMetaTab() {
// open Project metadata tab
//
settingsPage.openMenu(settingsPage.PROJ_METADATA)
settingsPage.openTab(settingsPage.METADATA)
}
closeMetaTab() {
// close Project metadata tab
settingsPage.closeMenu()
}
metaSyncValidate(tbl, msg) {
cy.get(".nc-btn-metasync-reload")
.should("exist")
.click();
cy.wait(2000);
cy.get(`.nc-metasync-row-${tbl}`).contains(msg).should("exist");
cy.get(".nc-btn-metasync-sync-now")
.should("exist")
.click()
.then(() => {
cy.toastWait(`Table metadata recreated successfully`);
});
cy.get(".nc-metasync-row").then((row) => {
for (let i = 0; i < row.length; i++) {
cy.wrap(row).contains("No change identified").should("exist");
}
});
}
tabReset() {
// temporary disable (kludge)
// mainPage.toolBarTopLeft(mainPage.HOME).click({ force: true });
// cy.get(".project-row").should("exist").click({ force: true });
// projectsPage.waitHomePageLoad();
// option-2
// cy.openTableTab("Country", 0);
// cy.get(".mdi-close").click({ multiple: true });
// cy.get("button.ant-tabs-tab-remove").click({ multiple: true });
// cy.get('.ant-tabs-tab-remove').should('not.exist')
}
toggleRightSidebar() {
cy.get(".nc-toggle-right-navbar").should("exist").click();
}
}
export const mainPage = new _mainPage();
export const settingsPage = new _settingsPage();
/**
* @copyright Copyright (c) 2021, Xgene Cloud Ltd
*
* @author Raju Udava <sivadstala@gmail.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

View File

@@ -0,0 +1,317 @@
import { roles, staticProjects, defaultDbParams } from "./projectConstants";
///////////////////////////////////////////////////////////
// Sign in/ Sign up page
// list of hard-wired URL that can be used by nocodb
// suffix to baseUrl needs to be defined here
//
const urlPool = {
ncUrlBase: "/",
ncUrlSignUp: "#/signup",
ncUrlSignIn: "#/signin",
};
export class _loginPage {
// prefix: baseUrl
go(urlKey) {
cy.visit(urlKey);
}
// visit SignIn URL, enter credentials passed as parameters
//
signIn(userCredentials) {
this.go(urlPool.ncUrlBase);
cy.get('input[type="text"]', { timeout: 20000 }).type(
userCredentials.username
);
cy.get('input[type="password"]').type(userCredentials.password);
cy.get('button:contains("SIGN IN")').click();
this.waitProjectPageLoad();
}
// visit SignUp URL, enter credentials passed as parameters
//
signUp(userCredentials) {
this.go(urlPool.ncUrlSignUp);
cy.get('input[type="text"]', { timeout: 20000 }).type(
userCredentials.username
);
cy.get('input[type="password"]').type(userCredentials.password);
cy.get('button:contains("SIGN UP")').click();
this.waitProjectPageLoad();
}
// logout signed up user
//
signOut() {
cy.get(".nc-user-menu").click();
cy.get(".nc-user-menu-signout").click();
this.waitLoginPageLoad();
}
// delay/ wait utility routines
//
waitProjectPageLoad() {
cy.get(".nc-new-project-menu").should("exist");
}
waitLoginPageLoad() {
cy.get(".nc-form-signin").should("exist");
}
// standard pre-project activity
//
loginAndOpenProject(apiType, dbType) {
loginPage.signIn(roles.owner.credentials);
projectsPage.openConfiguredProject(apiType, dbType);
// if (dbType === "mysql") {
// projectsPage.openProject(staticProjects.externalREST.basic.name);
// } else if (dbType === "xcdb") {
// projectsPage.openProject(staticProjects.sampleREST.basic.name);
// } else if (dbType === "postgres") {
// projectsPage.openProject(staticProjects.pgExternalREST.basic.name);
// }
//
// // kludge: wait for page load to finish
// cy.wait(2000);
// // close team & auth tab
// cy.get('button.ant-tabs-tab-remove').should('exist').click();
// cy.wait(1000);
}
}
///////////////////////////////////////////////////////////
// Projects page
export class _projectsPage {
// Project creation options
//
// {dbType, apiType, name}
// for external database, {databaseType, hostAddress, portNumber, username, password, databaseName}
openConfiguredProject(apiType, dbType) {
if (dbType === "mysql") {
projectsPage.openProject(staticProjects.externalREST.basic.name);
} else if (dbType === "xcdb") {
projectsPage.openProject(staticProjects.sampleREST.basic.name);
} else if (dbType === "postgres") {
projectsPage.openProject(staticProjects.pgExternalREST.basic.name);
}
// kludge: wait for page load to finish
cy.wait(4000);
// close team & auth tab
cy.get('button.ant-tabs-tab-remove').should('exist').click();
cy.wait(1000);
}
// Open existing project
//
openProject(projectName) {
cy.get(".ant-table-row").contains(`${projectName}`).should("exist").click();
// takes a while to load project
this.waitHomePageLoad();
}
// Create new project
// Input:
// projectData {dbType, apiType, name}
// dbCredentials {databaseType, hostAddress, portNumber, username, password, databaseName}
// Returns: projectName
//
// To configure
// SSL & advanced parameters
// Database type selection
//
createProject(projectData, cred) {
cy.get("body", { timeout: 2000 });
let projectName = projectData.name;
if (projectData.name == "") projectName = "test_proj" + Date.now();
// click on "New Project"
cy.get(".nc-new-project-menu").should("exist").click();
if ("none" == projectData.dbType) {
// Subsequent form, select (+ Create) option
cy.get(".nc-create-xc-db-project", { timeout: 20000 }).last().click({
force: true,
});
// wait for page load by verifying required elements
cy.get(".nc-metadb-project-name").should("exist");
cy.contains("button", "Create").should("exist");
cy.wait(1000)
// feed project name
cy.get(".nc-metadb-project-name", { timeout: 20000 }).clear().type(
projectName
);
// Submit
cy.contains("button", "Create", { timeout: 20000 }).click();
// takes a while to load project
this.waitHomePageLoad();
return projectName;
}
// dbType == 'external'
else {
// Subsequent form, select (+ Create by connection to external database) option
cy.get(".nc-create-external-db-project", { timeout: 20000 }).last().click({
force: true,
});
// wait for page load by verifying required elements
cy.get('.nc-extdb-host-database').should('exist');
cy.get('.nc-extdb-proj-name').should('exist');
cy.get('.nc-extdb-btn-test-connection').should('exist');
// CY goes too fast at times, so wait for the page to load
cy.wait(1000);
cy.get('.nc-extdb-proj-name').clear().type(projectName);
if (cred.databaseType === 1) {
cy.get('.nc-extdb-db-type').should('exist').click();
cy.getActiveSelection().find('.ant-select-item-option').contains("PostgreSQL").click();
}
if (cred.databaseName !== "") {
cy.get('.nc-extdb-host-database').clear().type(cred.databaseName);
}
// Test database connection
cy.contains("Test Database Connection", { timeout: 20000 }).click();
// Create project
cy.contains("Ok & Save Project", { timeout: 20000 }).click();
cy.wait(5000)
// takes a while to load project
this.waitHomePageLoad();
return projectName;
}
}
// // create REST default project (sakila DB)
// //
// createDefaulRestProject() {
// return this.createProject(
// { dbType: 1, apiType: 0, name: "" },
// defaultDbParams
// );
// }
// // search project with given key
// // return project-name array
// //
// searchProject(projectNameKey) {
// cy.get('input[placeholder="Search Project"]').type(projectNameKey);
//
// const projectName = [];
//
// cy.get("table tr")
// .each((tableRow) => {
// cy.wrap(tableRow)
// .find("td")
// .eq(0)
// .find(".title")
// .then((input) => {
// projectName.push(input.text());
// });
// })
// .then(() => {
// // TBD: validate project name to contain search key
// console.log(projectName);
// return projectName;
// });
// }
// remove specified project entry
//
deleteProject(projectName) {
cy.log("Delete project: " + projectName);
cy.get(".nc-noco-brand-icon").should('exist').click();
cy.get(".ant-table-row").contains(`${projectName}`).should("exist")
.then(($obj) => {
cy.log($obj)
cy.wrap($obj).parent().parent().find('.ant-table-cell').last().click()
})
// pop-up, submit
cy.getActiveModal().find('button:contains("Yes")').click({});
}
// remove all projects created
//
// 1. read all project names to be deleted, store in array
// 2. invoke delete project for each entry in array
//
// deleteAllProject() {
// const projectName = []
// cy.get('table tr').each((tableRow) => {
// cy.wrap(tableRow).find('td').eq(0).find('.title').then((input) => {
// projectName.push(input.text())
// })
// })
// .then(() => {
// console.log(projectName)
// projectName.forEach(element => {
// // bring back the DOM to normalcy
// cy.get('div').parentsUntil('body')
// this.deleteProject(element)
// // wait needed for pop up to disapper
// this.waitDeletePageLoad()
// })
// })
// }
waitHomePageLoad() {
cy.url({ timeout: 50000 }).should("contain", "/#/nc/p_");
}
}
export const loginPage = new _loginPage();
export const projectsPage = new _projectsPage();
/**
* @copyright Copyright (c) 2021, Xgene Cloud Ltd
*
* @author Raju Udava <sivadstala@gmail.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

View File

@@ -0,0 +1,158 @@
export const defaultDbParams = {
databaseType: 0, // MySQL
hostAddress: "localhost",
portNumber: "3306",
username: "root",
password: "password",
databaseName: "sakila",
};
export const defaultPgDbParams = {
databaseType: 1, // Postgres
hostAddress: "localhost",
portNumber: "5432",
username: "postgres",
password: "password",
databaseName: "postgres",
};
// database
// validation details
// advSettings: left navigation bar (audit, metadata, auth, transient view modes)
// editSchema: create table, add/update/delete column
// editData: add/ update/ delete row, cell contents
// editComment: add comment
// shareView: right navigation bar (share options)
export const roles = {
owner: {
name: "owner",
credentials: { username: "user@nocodb.com", password: "Password123." },
validations: {
advSettings: true,
editSchema: true,
editData: true,
editComment: true,
shareView: true,
},
},
creator: {
name: "creator",
credentials: {
username: "creator@nocodb.com",
password: "Password123.",
},
validations: {
advSettings: true,
editSchema: true,
editData: true,
editComment: true,
shareView: true,
},
},
editor: {
name: "editor",
credentials: {
username: "editor@nocodb.com",
password: "Password123.",
},
validations: {
advSettings: false,
editSchema: false,
editData: true,
editComment: true,
shareView: false,
},
},
commenter: {
name: "commenter",
credentials: {
username: "commenter@nocodb.com",
password: "Password123.",
},
validations: {
advSettings: false,
editSchema: false,
editData: false,
editComment: true,
shareView: false,
},
},
viewer: {
name: "viewer",
credentials: {
username: "viewer@nocodb.com",
password: "Password123.",
},
validations: {
advSettings: false,
editSchema: false,
editData: false,
editComment: false,
shareView: false,
},
},
};
// default projects
//
export const staticProjects = {
sampleREST: {
basic: { dbType: "none", apiType: "REST", name: "sampleREST" },
config: {},
},
sampleGQL: {
basic: { dbType: "none", apiType: "GQL", name: "sampleGQL" },
config: {},
},
externalREST: {
basic: { dbType: "external", apiType: "REST", name: "externalREST" },
config: defaultDbParams,
},
externalGQL: {
basic: { dbType: "external", apiType: "GQL", name: "externalGQL" },
config: defaultDbParams,
},
pgExternalREST: {
basic: { dbType: "external", apiType: "REST", name: "pgExtREST" },
config: defaultPgDbParams,
},
pgExternalGQL: {
basic: { dbType: "external", apiType: "GQL", name: "pgExternalGQL" },
config: defaultPgDbParams,
},
};
// return TRUE if test suite specified is activated from env-variables
//
export const isTestSuiteActive = (apiType, dbType) => {
const env = Cypress.env("testMode");
return env.some(
(element) => element.apiType === apiType && element.dbType === dbType
);
};
let currentTestMode = { apiType: null, dbType: null };
let xcdbProjectString = ``;
export function setCurrentMode(apiType, dbType) {
currentTestMode = { apiType: apiType, dbType: dbType };
}
export function getCurrentMode() {
return currentTestMode;
}
export function isXcdb() {
return currentTestMode.dbType === "xcdb";
}
export function isPostgres() {
return currentTestMode.dbType === "postgres";
}
export function setProjectString(projStr) {
xcdbProjectString = projStr;
}
export function getProjectString() {
return xcdbProjectString;
}