From 0e679d297c1e645d14299ffc804101ae26b1be25 Mon Sep 17 00:00:00 2001 From: Raju Udava Date: Mon, 6 Sep 2021 15:43:38 +0530 Subject: [PATCH] Cypress: Test-suite for Login page and Projects page Signed-off-by: Raju Udava --- cypress/integration/ncTest.spec.js | 53 +++++ cypress/support/page_objects/navigation.js | 221 +++++++++++++++++++++ 2 files changed, 274 insertions(+) create mode 100644 cypress/integration/ncTest.spec.js create mode 100644 cypress/support/page_objects/navigation.js diff --git a/cypress/integration/ncTest.spec.js b/cypress/integration/ncTest.spec.js new file mode 100644 index 0000000000..26a26ad32b --- /dev/null +++ b/cypress/integration/ncTest.spec.js @@ -0,0 +1,53 @@ +/** + * file: ncTest.Spec.js + * purpose: test-suite-1 + * author: raju udava + * date: 06 Sep 2020 + * + **/ + +import { loginPage, projectsPage } from "../support/page_objects/navigation" + +const activeCredentials = 0 + +const userCredentials = [ + { username: 'user@nocodb.com', password: 'Password123.' }] + +describe('Login & project page', () => { + + beforeEach(() => { + loginPage.signIn(userCredentials[activeCredentials]) + }) + + let projectName = '' + + it('1. Create project: NC_DB_NONE, NC_REST', () => { + const projectParams = { dbType: 0, apiType: 0, name: 'sampleREST' } + projectName = projectsPage.createProject(projectParams) + }) + + it('1a. Open existing project & refresh project list', () => { + projectsPage.refreshProject() + projectsPage.searchProject('sample') + projectsPage.openProject(projectName) + }) + + it('1b. Delete project: NC_DB_NONE, NC_REST', () => { + projectsPage.deleteProject(projectName) + }) + + it('2. Create project: NC_DB_NONE, NC_GQL', () => { + const projectParams = { dbType: 0, apiType: 1, name: 'sampleGQL' } + projectName = projectsPage.createProject(projectParams) + }) + + it('2a. Delete project: NC_DB_NONE, NC_GQL', () => { + projectsPage.deleteProject(projectName) + }) + + // Needs to be conditionally triggered if required + // + // it('N. Clean up: Delete call projects', () => { + // projectsPage.deleteAllProject() + // }) +}) diff --git a/cypress/support/page_objects/navigation.js b/cypress/support/page_objects/navigation.js new file mode 100644 index 0000000000..da1e2cf8f2 --- /dev/null +++ b/cypress/support/page_objects/navigation.js @@ -0,0 +1,221 @@ +/** + * file: navigation.js + * purpose: signUp/ projects page navigation options + * author: raju udava + * date: 06 Sep 2020 + * + **/ + + +/////////////////////////////////////////////////////////// +// 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: "#/user/authentication/signup", + ncUrlSignIn: "#/user/authentication/signin" +} + +export class _loginPage { + + // prefix: baseUrl + go(urlKey) { + cy.visit(urlKey) + } + + // visit SignIn URL, enter credentials passed as parameters + // + signIn(userCredentials) { + this.go(urlPool.ncUrlSignIn) + + cy.get('input[type="text"]').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"]').type(userCredentials.username) + cy.get('input[type="password"]').type(userCredentials.password) + cy.get('button:contains("SIGN UP")').click() + + this.waitProjectPageLoad() + } + + // delay/ wait utility routines + // + waitProjectPageLoad() { + cy.url({ timeout: 6000 }).should('contain', '#/project') + cy.wait(1000) + } +} + + +/////////////////////////////////////////////////////////// +// Projects page + +// DB type +const NC_DB_NONE = 0 +const NC_DB_EXISTING = 1 + +// API type +const NC_REST = 0 +const NC_GQL = 1 + + +export class _projectsPage { + + // Project creation options + // + + // {dbType, apiType, name} + + // Open existing project + // TODO: add projectName validation + // + openProject(projectName) { + cy.get('tbody').contains('tr', projectName).click() + + // takes a while to load project + this.waitHomePageLoad() + } + + // Create new project + // Input: {dbType, apiType, name} + // Returns: projectName + // + createProject(projectData) { + + cy.get('body', { timeout: 2000 }) + + if (NC_DB_NONE == projectData.dbType) { + + let projectName = projectData.name + + if (projectData.name == '') + projectName = 'test_proj' + Date.now() + + // click on "New Project" + cy.get(':nth-child(5) > .v-btn').click() + + // Subsequent form, select (+ Create) option + cy.get('.nc-create-xc-db-project').click({ force: true }) + + // feed project name + cy.get('.nc-metadb-project-name').type(projectName) + + // Radio button: defaults to NC_REST + if (NC_GQL == projectData.apiType) { + cy.contains('GRAPHQL APIs').closest('label').click(); + } + + // Submit + cy.contains('button', 'Create', { timeout: 3000 }).click() + + // takes a while to load project + this.waitHomePageLoad() + + return projectName + } + else { + + // Existing database connections + // TBD + + } + } + + + // Click on refresh key on projects page + // + refreshProject() { + cy.contains('My Projects').parent().find('button').click(); + cy.wait(1000) + } + + // 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 + // TODO: error handling + // + deleteProject(name) { + + // delete icon + cy.get('tbody').contains('tr', name).find('.mdi-delete-circle-outline').click() + this.waitDeletePageLoad() + + // pop-up, submit + cy.get('body').then((body) => { + cy.wrap(body).find('button').contains('Submit').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: 12000 }).should('contain', '?type=roles') + } + + waitDeletePageLoad() { + cy.wait(1000) + } +} + +export const loginPage = new _loginPage; +export const projectsPage = new _projectsPage;