Updating tests to work with test Env

I've made some changes to the tests and commands file to allow for the tests to run within the Test env after the latest round of UI changes.

Some of these changes also allow for testing instances in which apps already exist - This is specific for the test env, the CI runs always have a clean instance
This commit is contained in:
Mitch-Budibase 2022-04-01 11:31:18 +01:00
parent aeea15e8db
commit f595112b38
9 changed files with 86 additions and 65 deletions

View File

@ -6,10 +6,6 @@ filterTests(['all'], () => {
cy.login() cy.login()
}) })
after(() => {
cy.deleteAllApps()
})
it("should change the icon and colour for an application", () => { it("should change the icon and colour for an application", () => {
// Search for test application // Search for test application
cy.applicationInAppTable("Cypress Tests") cy.applicationInAppTable("Cypress Tests")

View File

@ -3,25 +3,32 @@ import filterTests from '../support/filterTests'
filterTests(['smoke', 'all'], () => { filterTests(['smoke', 'all'], () => {
context("Create an Application", () => { context("Create an Application", () => {
beforeEach(() => { before(() => {
cy.login() cy.login()
cy.deleteApp("Cypress Tests")
}) })
it("should show the new user UI/UX", () => { if (!(Cypress.env("TEST_ENV"))) {
cy.visit(`${Cypress.config().baseUrl}/builder`) it("should show the new user UI/UX", () => {
cy.get(`[data-cy="create-app-btn"]`).contains('Start from scratch').should("exist") cy.visit(`${Cypress.config().baseUrl}/builder`)
cy.get(`[data-cy="import-app-btn"]`).should("exist") cy.get(`[data-cy="create-app-btn"]`).contains('Start from scratch').should("exist")
cy.get(`[data-cy="import-app-btn"]`).should("exist")
cy.get(".template-category-filters").should("exist")
cy.get(".template-categories").should("exist") cy.get(".template-category-filters").should("exist")
cy.get(".template-categories").should("exist")
cy.get(".appTable").should("not.exist")
}) cy.get(".appTable").should("not.exist")
})
}
it("should provide filterable templates", () => { it("should provide filterable templates", () => {
cy.visit(`${Cypress.config().baseUrl}/builder`) cy.visit(`${Cypress.config().baseUrl}/builder`)
cy.wait(500) cy.wait(500)
if (Cypress.env("TEST_ENV")) {
cy.get(".spectrum-Button").contains("Templates").click({force: true})
}
cy.get(".template-category-filters").should("exist") cy.get(".template-category-filters").should("exist")
cy.get(".template-categories").should("exist") cy.get(".template-categories").should("exist")
@ -39,14 +46,22 @@ filterTests(['smoke', 'all'], () => {
cy.visit(`${Cypress.config().baseUrl}/builder`) cy.visit(`${Cypress.config().baseUrl}/builder`)
cy.wait(500) cy.wait(500)
const appName = "A New App" // Start create app process. If apps already exist, click second button
cy.get(`[data-cy="create-app-btn"]`).click({ force: true })
cy.get(`[data-cy="create-app-btn"]`).contains('Start from scratch').click({force: true}) cy.request(`${Cypress.config().baseUrl}/api/applications?status=all`)
.its("body")
.then(val => {
if (val.length > 0) {
cy.get(`[data-cy="create-app-btn"]`).click({ force: true })
}
})
const appName = "Cypress Tests"
cy.get(".spectrum-Modal").within(() => { cy.get(".spectrum-Modal").within(() => {
//Auto fill //Auto fill
cy.get("input").eq(0).type(appName).should("have.value", appName).blur() cy.get("input").eq(0).type(appName).should("have.value", appName).blur()
cy.get("input").eq(1).should("have.value", "/a-new-app") cy.get("input").eq(1).should("have.value", "/cypress-tests")
cy.get(".spectrum-ButtonGroup").contains("Create app").should('not.be.disabled') cy.get(".spectrum-ButtonGroup").contains("Create app").should('not.be.disabled')
//Empty the app url - disabled create //Empty the app url - disabled create
@ -69,8 +84,7 @@ filterTests(['smoke', 'all'], () => {
it("should create the first application from scratch", () => { it("should create the first application from scratch", () => {
const appName = "Cypress Tests" const appName = "Cypress Tests"
cy.deleteApp(appName) cy.createApp(appName)
cy.createApp(appName, "This app is used for Cypress testing.")
cy.visit(`${Cypress.config().baseUrl}/builder`) cy.visit(`${Cypress.config().baseUrl}/builder`)
cy.wait(1000) cy.wait(1000)
@ -83,10 +97,19 @@ filterTests(['smoke', 'all'], () => {
cy.visit(`${Cypress.config().baseUrl}/builder`) cy.visit(`${Cypress.config().baseUrl}/builder`)
cy.wait(500) cy.wait(500)
// Navigate to Create new app section if apps already exist
cy.request(`${Cypress.config().baseUrl}/api/applications?status=all`)
.its("body")
.then(val => {
if (val.length > 0) {
cy.get(`[data-cy="create-app-btn"]`).click({ force: true })
}
})
cy.get(".template-category-filters").should("exist") cy.get(".template-category-filters").should("exist")
cy.get(".template-categories").should("exist") cy.get(".template-categories").should("exist")
//### Select nth template and choose to create? // Select template
cy.get('.template-category').eq(0).within(() => { cy.get('.template-category').eq(0).within(() => {
const card = cy.get('.template-card').eq(0).should("exist"); const card = cy.get('.template-card').eq(0).should("exist");
const cardOverlay = card.get('.template-thumbnail-action-overlay').should("exist") const cardOverlay = card.get('.template-thumbnail-action-overlay').should("exist")
@ -94,7 +117,7 @@ filterTests(['smoke', 'all'], () => {
cardOverlay.get("button").contains("Use template").should("exist").click({force: true}) cardOverlay.get("button").contains("Use template").should("exist").click({force: true})
}) })
//### CMD Create app from theme card // CMD Create app from theme card
cy.get(".spectrum-Modal").should('be.visible') cy.get(".spectrum-Modal").should('be.visible')
const templateName = cy.get(".spectrum-Modal .template-thumbnail-text") const templateName = cy.get(".spectrum-Modal .template-thumbnail-text")
@ -111,27 +134,22 @@ filterTests(['smoke', 'all'], () => {
cy.wait(1000) cy.wait(1000)
cy.applicationInAppTable(templateNameText) cy.applicationInAppTable(templateNameText)
cy.deleteAllApps() cy.deleteApp(templateNameText)
}); });
}) })
it("should display a second application and app filtering", () => { it("should display a second application and app filtering", () => {
// Create first app
const appName = "Cypress Tests" const appName = "Cypress Tests"
cy.deleteApp(appName) cy.createApp(appName)
cy.createApp(appName, "This app is used for Cypress testing.")
cy.visit(`${Cypress.config().baseUrl}/builder`) cy.visit(`${Cypress.config().baseUrl}/builder`)
cy.wait(500) cy.wait(500)
// Create second app
const secondAppName = "Second App Demo" const secondAppName = "Second App Demo"
cy.deleteApp(secondAppName) cy.createApp(secondAppName)
cy.get(`[data-cy="create-app-btn"]`).contains('Create new app').click({force: true})
cy.wait(500)
cy.url().should('include', '/builder/portal/apps/create')
cy.createAppFromScratch(secondAppName)
cy.visit(`${Cypress.config().baseUrl}/builder`) cy.visit(`${Cypress.config().baseUrl}/builder`)
cy.wait(500) cy.wait(500)
@ -140,7 +158,7 @@ filterTests(['smoke', 'all'], () => {
cy.searchForApplication(appName) cy.searchForApplication(appName)
cy.searchForApplication(secondAppName) cy.searchForApplication(secondAppName)
cy.deleteAllApps() cy.deleteApp(secondAppName)
}) })
}) })

View File

@ -7,10 +7,6 @@ filterTests(["smoke", "all"], () => {
cy.createTestApp() cy.createTestApp()
}) })
after(() => {
cy.deleteAllApps()
})
it("should create a new Table", () => { it("should create a new Table", () => {
cy.createTable("dog") cy.createTable("dog")
cy.wait(1000) cy.wait(1000)

View File

@ -4,11 +4,14 @@ filterTests(["smoke", "all"], () => {
context("Create a User and Assign Roles", () => { context("Create a User and Assign Roles", () => {
before(() => { before(() => {
cy.login() cy.login()
cy.visit(`${Cypress.config().baseUrl}/builder`)
cy.wait(500)
cy.createAppFromScratch("Initial App")
}) })
if (!(Cypress.env("TEST_ENV"))) {
after(() => {
cy.deleteAllApps()
})
}
it("should create a user", () => { it("should create a user", () => {
cy.visit(`${Cypress.config().baseUrl}/builder`) cy.visit(`${Cypress.config().baseUrl}/builder`)
cy.wait(1000) cy.wait(1000)

View File

@ -4,7 +4,6 @@ filterTests(['smoke', 'all'], () => {
context("Create a View", () => { context("Create a View", () => {
before(() => { before(() => {
cy.login() cy.login()
cy.deleteAllApps()
cy.createTestApp() cy.createTestApp()
cy.createTable("data") cy.createTable("data")

View File

@ -4,7 +4,6 @@ filterTests(["smoke", "all"], () => {
context("REST Datasource Testing", () => { context("REST Datasource Testing", () => {
before(() => { before(() => {
cy.login() cy.login()
cy.deleteAllApps()
cy.createTestApp() cy.createTestApp()
}) })

View File

@ -4,8 +4,7 @@ filterTests(["smoke", "all"], () => {
context("Query Level Transformers", () => { context("Query Level Transformers", () => {
before(() => { before(() => {
cy.login() cy.login()
cy.deleteAllApps() cy.createTestApp()
cy.createApp("Cypress Tests")
}) })
it("should write a transformer function", () => { it("should write a transformer function", () => {

View File

@ -15,6 +15,7 @@ filterTests(['all'], () => {
renameApp(appName, appRename) renameApp(appName, appRename)
cy.reload() cy.reload()
cy.wait(1000) cy.wait(1000)
cy.searchForApplication(appRename)
cy.get(".appTable").find(".title").should("have.length", 1) cy.get(".appTable").find(".title").should("have.length", 1)
cy.applicationInAppTable(appRename) cy.applicationInAppTable(appRename)
// Set app name back to Cypress Tests // Set app name back to Cypress Tests
@ -52,8 +53,6 @@ filterTests(['all'], () => {
cy.reload() cy.reload()
cy.wait(1000) cy.wait(1000)
cy.applicationInAppTable(appName) cy.applicationInAppTable(appName)
cy.get(".appTable").find(".title").should("have.length", 1)
}) })
xit("Should create two applications with the same name", () => { xit("Should create two applications with the same name", () => {
@ -82,7 +81,6 @@ filterTests(['all'], () => {
cy.reload() cy.reload()
cy.wait(1000) cy.wait(1000)
cy.applicationInAppTable(numberName) cy.applicationInAppTable(numberName)
cy.get(".appTable").find(".title").should("have.length", 1)
cy.reload() cy.reload()
cy.wait(1000) cy.wait(1000)
renameApp(numberName, specialCharName) renameApp(numberName, specialCharName)
@ -94,7 +92,7 @@ filterTests(['all'], () => {
}) })
const renameApp = (originalName, changedName, published, noName) => { const renameApp = (originalName, changedName, published, noName) => {
cy.applicationInAppTable(originalName) cy.searchForApplication(originalName)
cy.request(`${Cypress.config().baseUrl}/api/applications?status=all`) cy.request(`${Cypress.config().baseUrl}/api/applications?status=all`)
.its("body") .its("body")
.then(val => { .then(val => {

View File

@ -35,9 +35,17 @@ Cypress.Commands.add("login", () => {
Cypress.Commands.add("createApp", name => { Cypress.Commands.add("createApp", name => {
cy.visit(`${Cypress.config().baseUrl}/builder`) cy.visit(`${Cypress.config().baseUrl}/builder`)
cy.wait(500) cy.wait(500)
cy.get(`[data-cy="create-app-btn"]`).click({ force: true }) cy.get(`[data-cy="create-app-btn"]`).click({ force: true })
// If apps already exist
cy.request(`${Cypress.config().baseUrl}/api/applications?status=all`)
.its("body")
.then(val => {
if (val.length > 0) {
cy.get(`[data-cy="create-app-btn"]`).click({ force: true })
}
})
cy.get(".spectrum-Modal").within(() => { cy.get(".spectrum-Modal").within(() => {
cy.get("input").eq(0).type(name).should("have.value", name).blur() cy.get("input").eq(0).type(name).should("have.value", name).blur()
cy.get(".spectrum-ButtonGroup").contains("Create app").click() cy.get(".spectrum-ButtonGroup").contains("Create app").click()
@ -53,23 +61,30 @@ Cypress.Commands.add("deleteApp", name => {
.its("body") .its("body")
.then(val => { .then(val => {
if (val.length > 0) { if (val.length > 0) {
const appId = val.reduce((acc, app) => { if (Cypress.env("TEST_ENV")) {
if (name === app.name) { cy.searchForApplication(name)
acc = app.appId cy.get(".appTable").within(() => {
cy.get(".spectrum-Icon").eq(1).click()
})
} else {
const appId = val.reduce((acc, app) => {
if (name === app.name) {
acc = app.appId
}
return acc
}, "")
if (appId == "") {
return
} }
return acc
}, "")
if (appId == "") { const appIdParsed = appId.split("_").pop()
return const actionEleId = `[data-cy=row_actions_${appIdParsed}]`
cy.get(actionEleId).within(() => {
cy.get(".spectrum-Icon").eq(0).click()
})
} }
const appIdParsed = appId.split("_").pop()
const actionEleId = `[data-cy=row_actions_${appIdParsed}]`
cy.get(actionEleId).within(() => {
cy.get(".spectrum-Icon").eq(0).click()
})
cy.get(".spectrum-Menu").then($menu => { cy.get(".spectrum-Menu").then($menu => {
if ($menu.text().includes("Unpublish")) { if ($menu.text().includes("Unpublish")) {
cy.get(".spectrum-Menu").contains("Unpublish").click() cy.get(".spectrum-Menu").contains("Unpublish").click()
@ -335,8 +350,6 @@ Cypress.Commands.add("searchForApplication", appName => {
cy.get("input").eq(0).type(appName) cy.get("input").eq(0).type(appName)
}) })
}) })
// Confirms app exists after search
cy.applicationInAppTable(appName)
}) })
//Assumes there are no others //Assumes there are no others