2020-06-09 13:52:00 +02:00
|
|
|
// ***********************************************
|
|
|
|
// For more comprehensive examples of custom
|
|
|
|
// commands please read more here:
|
|
|
|
// https://on.cypress.io/custom-commands
|
|
|
|
// ***********************************************
|
|
|
|
//
|
2020-06-11 12:04:31 +02:00
|
|
|
|
2021-10-11 12:33:54 +02:00
|
|
|
Cypress.on("uncaught:exception", () => {
|
2021-10-08 12:45:54 +02:00
|
|
|
return false
|
|
|
|
})
|
|
|
|
|
2021-04-15 14:23:42 +02:00
|
|
|
Cypress.Commands.add("login", () => {
|
2021-09-30 14:52:20 +02:00
|
|
|
cy.visit(`localhost:${Cypress.env("PORT")}/builder`)
|
2021-09-27 19:19:25 +02:00
|
|
|
cy.wait(2000)
|
2021-05-25 14:25:42 +02:00
|
|
|
cy.url().then(url => {
|
|
|
|
if (url.includes("builder/admin")) {
|
|
|
|
// create admin user
|
|
|
|
cy.get("input").first().type("test@test.com")
|
|
|
|
cy.get('input[type="password"]').first().type("test")
|
|
|
|
cy.get('input[type="password"]').eq(1).type("test")
|
|
|
|
cy.contains("Create super admin user").click()
|
|
|
|
}
|
2021-05-25 16:57:38 +02:00
|
|
|
if (url.includes("builder/auth/login") || url.includes("builder/admin")) {
|
|
|
|
// login
|
|
|
|
cy.contains("Sign in to Budibase").then(() => {
|
|
|
|
cy.get("input").first().type("test@test.com")
|
|
|
|
cy.get('input[type="password"]').type("test")
|
|
|
|
cy.get("button").first().click()
|
2021-09-27 19:19:25 +02:00
|
|
|
cy.wait(1000)
|
2021-05-25 16:57:38 +02:00
|
|
|
})
|
|
|
|
}
|
2021-04-15 19:29:11 +02:00
|
|
|
})
|
2021-04-15 13:14:50 +02:00
|
|
|
})
|
2020-06-11 12:04:31 +02:00
|
|
|
|
2021-05-04 12:32:22 +02:00
|
|
|
Cypress.Commands.add("createApp", name => {
|
2021-09-30 14:52:20 +02:00
|
|
|
cy.visit(`localhost:${Cypress.env("PORT")}/builder`)
|
2021-06-01 15:29:25 +02:00
|
|
|
cy.wait(500)
|
2021-11-15 16:25:58 +01:00
|
|
|
cy.request(`localhost:${Cypress.env("PORT")}/api/applications?status=all`).its('body').then((body) => {
|
|
|
|
if( body.length > 0) {
|
|
|
|
cy.get(".spectrum-Button").contains("Create app").click({ force: true })
|
|
|
|
}
|
|
|
|
})
|
2021-10-19 17:14:34 +02:00
|
|
|
cy.contains(/Start from scratch/).dblclick()
|
2021-10-14 17:45:27 +02:00
|
|
|
cy.get(".spectrum-Modal").within(() => {
|
|
|
|
cy.get("input").eq(0).type(name).should("have.value", name).blur()
|
|
|
|
cy.get(".spectrum-ButtonGroup").contains("Create app").click()
|
2021-11-15 16:25:58 +01:00
|
|
|
cy.wait(5000)
|
2021-10-14 17:45:27 +02:00
|
|
|
})
|
2021-11-15 16:25:58 +01:00
|
|
|
cy.createTable("Cypress Tests", true)
|
2020-06-11 12:04:31 +02:00
|
|
|
})
|
2020-08-05 16:18:28 +02:00
|
|
|
|
2021-11-15 16:25:58 +01:00
|
|
|
Cypress.Commands.add("deleteApp", name => {
|
2021-09-30 14:52:20 +02:00
|
|
|
cy.visit(`localhost:${Cypress.env("PORT")}/builder`)
|
2021-11-15 16:25:58 +01:00
|
|
|
cy.wait(2000)
|
2021-09-30 15:09:37 +02:00
|
|
|
cy.request(`localhost:${Cypress.env("PORT")}/api/applications?status=all`)
|
2021-11-15 16:25:58 +01:00
|
|
|
.its("body")
|
|
|
|
.then(val => {
|
|
|
|
if (val.length > 0) {
|
|
|
|
cy.searchForApplication(name)
|
|
|
|
cy.get(".appGrid").children().within(() => {
|
|
|
|
cy.get(".title").children().within(() => {
|
|
|
|
cy.get(".spectrum-Icon").click()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
cy.get(".spectrum-Menu").contains("Delete").click()
|
|
|
|
cy.get(".spectrum-Dialog-grid").within(() => {
|
|
|
|
cy.get("input").type(name)
|
|
|
|
})
|
|
|
|
cy.get(".spectrum-Button--warning").click()
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Cypress.Commands.add("deleteAllApps", () => {
|
|
|
|
cy.visit(`localhost:${Cypress.env("PORT")}/builder`)
|
|
|
|
cy.wait(500)
|
|
|
|
cy.request(`localhost:${Cypress.env("PORT")}/api/applications?status=all`)
|
|
|
|
.its("body")
|
|
|
|
.then(val => {
|
|
|
|
for (let i = 0; i < val.length; i++) {
|
|
|
|
cy.get(".spectrum-Heading").eq(1).then((app) => {
|
|
|
|
const name = app.text()
|
|
|
|
cy.get(".title").children().within(() => {
|
|
|
|
cy.get(".spectrum-Icon").eq(0).click()
|
|
|
|
})
|
|
|
|
cy.get(".spectrum-Menu").contains("Delete").click()
|
|
|
|
cy.get(".spectrum-Dialog-grid").within(() => {
|
|
|
|
cy.get("input").type(name)
|
|
|
|
cy.get(".spectrum-Button--warning").click()
|
|
|
|
})
|
|
|
|
cy.reload()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2021-03-05 14:52:26 +01:00
|
|
|
})
|
|
|
|
|
2021-03-05 15:36:38 +01:00
|
|
|
Cypress.Commands.add("createTestApp", () => {
|
|
|
|
const appName = "Cypress Tests"
|
2021-11-15 16:25:58 +01:00
|
|
|
cy.deleteApp(appName)
|
2021-03-05 15:36:38 +01:00
|
|
|
cy.createApp(appName, "This app is used for Cypress testing.")
|
|
|
|
})
|
|
|
|
|
2020-09-03 13:02:15 +02:00
|
|
|
Cypress.Commands.add("createTestTableWithData", () => {
|
|
|
|
cy.createTable("dog")
|
2020-10-05 12:13:09 +02:00
|
|
|
cy.addColumn("dog", "name", "Text")
|
2020-09-03 13:02:15 +02:00
|
|
|
cy.addColumn("dog", "age", "Number")
|
|
|
|
})
|
|
|
|
|
2021-11-15 16:25:58 +01:00
|
|
|
Cypress.Commands.add("createTable", (tableName, initialTable) => {
|
|
|
|
if (!initialTable) {
|
|
|
|
cy.get(".add-button").click()
|
|
|
|
}
|
|
|
|
cy.wait(7000)
|
|
|
|
cy.get(".spectrum-Modal").contains("Budibase DB").click().then(() => {
|
|
|
|
cy.get(".spectrum-Button").contains("Continue").click({ force: true })
|
|
|
|
})
|
2021-04-28 16:08:43 +02:00
|
|
|
cy.get(".spectrum-Modal").within(() => {
|
2021-09-28 13:26:38 +02:00
|
|
|
cy.wait(1000)
|
2021-05-03 09:31:09 +02:00
|
|
|
cy.get("input").first().type(tableName).blur()
|
|
|
|
cy.get(".spectrum-ButtonGroup").contains("Create").click()
|
2020-10-08 12:36:16 +02:00
|
|
|
})
|
2020-08-10 16:34:37 +02:00
|
|
|
cy.contains(tableName).should("be.visible")
|
|
|
|
})
|
2020-06-11 18:14:28 +02:00
|
|
|
|
2021-10-08 11:56:44 +02:00
|
|
|
Cypress.Commands.add(
|
|
|
|
"addColumn",
|
|
|
|
(tableName, columnName, type, multiOptions = null) => {
|
|
|
|
// Select Table
|
|
|
|
cy.selectTable(tableName)
|
|
|
|
cy.contains(".nav-item", tableName).click()
|
|
|
|
cy.contains("Create column").click()
|
|
|
|
|
|
|
|
// Configure column
|
|
|
|
cy.get(".spectrum-Modal").within(() => {
|
|
|
|
cy.get("input").first().type(columnName).blur()
|
|
|
|
|
|
|
|
// Unset table display column
|
|
|
|
cy.contains("display column").click({ force: true })
|
|
|
|
cy.get(".spectrum-Picker-label").click()
|
|
|
|
cy.contains(type).click()
|
|
|
|
|
|
|
|
// Add options for Multi-select Type
|
|
|
|
if (multiOptions !== null) {
|
|
|
|
cy.get(".spectrum-Textfield-input").eq(1).type(multiOptions)
|
|
|
|
}
|
2021-09-27 19:19:25 +02:00
|
|
|
|
2021-10-08 11:56:44 +02:00
|
|
|
cy.contains("Save Column").click()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
)
|
2020-08-05 16:18:28 +02:00
|
|
|
|
2021-05-04 12:32:22 +02:00
|
|
|
Cypress.Commands.add("addRow", values => {
|
2021-04-28 16:08:43 +02:00
|
|
|
cy.contains("Create row").click()
|
|
|
|
cy.get(".spectrum-Modal").within(() => {
|
2020-10-05 12:13:09 +02:00
|
|
|
for (let i = 0; i < values.length; i++) {
|
2021-05-03 09:31:09 +02:00
|
|
|
cy.get("input").eq(i).type(values[i]).blur()
|
2020-10-05 12:13:09 +02:00
|
|
|
}
|
2021-05-03 09:31:09 +02:00
|
|
|
cy.get(".spectrum-ButtonGroup").contains("Create").click()
|
2020-10-05 12:13:09 +02:00
|
|
|
})
|
2020-06-11 12:04:31 +02:00
|
|
|
})
|
|
|
|
|
2021-09-27 19:19:25 +02:00
|
|
|
Cypress.Commands.add("addRowMultiValue", values => {
|
|
|
|
cy.contains("Create row").click()
|
2021-10-08 11:56:44 +02:00
|
|
|
cy.get(".spectrum-Form-itemField")
|
|
|
|
.click()
|
|
|
|
.then(() => {
|
|
|
|
cy.get(".spectrum-Popover").within(() => {
|
|
|
|
for (let i = 0; i < values.length; i++) {
|
|
|
|
cy.get(".spectrum-Menu-item").eq(i).click()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
cy.get(".spectrum-Dialog-grid").click("top")
|
|
|
|
cy.get(".spectrum-ButtonGroup").contains("Create").click()
|
2021-09-27 19:19:25 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-05-25 19:06:56 +02:00
|
|
|
Cypress.Commands.add("createUser", email => {
|
|
|
|
// quick hacky recorded way to create a user
|
2020-08-05 16:18:28 +02:00
|
|
|
cy.contains("Users").click()
|
2021-05-25 19:06:56 +02:00
|
|
|
cy.get(".spectrum-Button--primary").click()
|
|
|
|
cy.get(".spectrum-Picker-label").click()
|
|
|
|
cy.get(".spectrum-Menu-item:nth-child(2) > .spectrum-Menu-itemLabel").click()
|
2021-06-02 19:28:05 +02:00
|
|
|
cy.get(
|
|
|
|
":nth-child(2) > .spectrum-Form-itemField > .spectrum-Textfield > .spectrum-Textfield-input"
|
|
|
|
)
|
|
|
|
.first()
|
|
|
|
.type(email, { force: true })
|
2021-05-25 19:06:56 +02:00
|
|
|
cy.get(".spectrum-Button--cta").click({ force: true })
|
2020-06-11 12:56:16 +02:00
|
|
|
})
|
|
|
|
|
2021-03-05 14:52:26 +01:00
|
|
|
Cypress.Commands.add("addComponent", (category, component) => {
|
|
|
|
if (category) {
|
|
|
|
cy.get(`[data-cy="category-${category}"]`).click()
|
|
|
|
}
|
2021-10-08 11:56:44 +02:00
|
|
|
if (component) {
|
2021-09-27 19:19:25 +02:00
|
|
|
cy.get(`[data-cy="component-${component}"]`).click()
|
|
|
|
}
|
2021-04-01 11:08:58 +02:00
|
|
|
cy.wait(1000)
|
2021-05-04 12:32:22 +02:00
|
|
|
cy.location().then(loc => {
|
2021-03-05 14:52:26 +01:00
|
|
|
const params = loc.pathname.split("/")
|
2021-03-08 12:57:56 +01:00
|
|
|
const componentId = params[params.length - 1]
|
|
|
|
cy.getComponent(componentId).should("exist")
|
|
|
|
return cy.wrap(componentId)
|
2021-03-05 14:52:26 +01:00
|
|
|
})
|
2020-06-11 16:40:07 +02:00
|
|
|
})
|
|
|
|
|
2021-05-04 12:32:22 +02:00
|
|
|
Cypress.Commands.add("getComponent", componentId => {
|
2021-03-05 14:52:26 +01:00
|
|
|
return cy
|
|
|
|
.get("iframe")
|
|
|
|
.its("0.contentDocument")
|
|
|
|
.should("exist")
|
|
|
|
.its("body")
|
|
|
|
.should("not.be.null")
|
|
|
|
.then(cy.wrap)
|
2021-09-20 13:20:34 +02:00
|
|
|
.find(`[data-id=${componentId}]`)
|
2020-06-11 18:14:28 +02:00
|
|
|
})
|
2020-06-24 17:16:06 +02:00
|
|
|
|
2020-06-24 17:20:58 +02:00
|
|
|
Cypress.Commands.add("navigateToFrontend", () => {
|
2021-09-27 19:19:25 +02:00
|
|
|
// Clicks on Design tab and then the Home nav item
|
2021-06-02 19:28:05 +02:00
|
|
|
cy.wait(1000)
|
2021-05-25 17:52:35 +02:00
|
|
|
cy.contains("Design").click()
|
2021-09-27 19:19:25 +02:00
|
|
|
cy.get(".spectrum-Search").type("/")
|
|
|
|
cy.get(".nav-item").contains("Home").click()
|
2020-06-24 17:16:06 +02:00
|
|
|
})
|
|
|
|
|
2021-11-15 16:25:58 +01:00
|
|
|
Cypress.Commands.add("navigateToDataSection", () => {
|
|
|
|
// Clicks on the Data tab
|
|
|
|
cy.wait(500)
|
|
|
|
cy.contains("Data").click()
|
|
|
|
})
|
|
|
|
|
2020-06-24 17:16:06 +02:00
|
|
|
Cypress.Commands.add("createScreen", (screenName, route) => {
|
2021-05-25 17:52:35 +02:00
|
|
|
cy.get("[aria-label=AddCircle]").click()
|
2021-04-28 16:08:43 +02:00
|
|
|
cy.get(".spectrum-Modal").within(() => {
|
2021-05-25 17:52:35 +02:00
|
|
|
cy.get("input").first().type(screenName)
|
|
|
|
cy.get("input").eq(1).type(route)
|
|
|
|
cy.get(".spectrum-Button--cta").click()
|
2020-06-24 17:20:58 +02:00
|
|
|
})
|
|
|
|
})
|
2021-09-16 10:03:57 +02:00
|
|
|
|
|
|
|
Cypress.Commands.add("expandBudibaseConnection", () => {
|
|
|
|
if (Cypress.$(".nav-item > .content > .opened").length === 0) {
|
|
|
|
// expand the Budibase DB connection string
|
|
|
|
cy.get(".icon.arrow").eq(0).click()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
Cypress.Commands.add("selectTable", tableName => {
|
|
|
|
cy.expandBudibaseConnection()
|
|
|
|
cy.contains(".nav-item", tableName).click()
|
|
|
|
})
|
2021-09-27 19:19:25 +02:00
|
|
|
|
|
|
|
Cypress.Commands.add("addCustomSourceOptions", totalOptions => {
|
2021-10-08 11:56:44 +02:00
|
|
|
cy.get(".spectrum-ActionButton")
|
|
|
|
.contains("Define Options")
|
|
|
|
.click()
|
|
|
|
.then(() => {
|
|
|
|
for (let i = 0; i < totalOptions; i++) {
|
|
|
|
// Add radio button options
|
|
|
|
cy.get(".spectrum-Button")
|
|
|
|
.contains("Add Option")
|
|
|
|
.click({ force: true })
|
|
|
|
.then(() => {
|
|
|
|
cy.wait(500)
|
|
|
|
cy.get("[placeholder='Label']").eq(i).type(i)
|
|
|
|
cy.get("[placeholder='Value']").eq(i).type(i)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
// Save options
|
|
|
|
cy.get(".spectrum-Button").contains("Save").click({ force: true })
|
2021-09-27 19:19:25 +02:00
|
|
|
})
|
2021-09-30 14:52:20 +02:00
|
|
|
})
|
2021-10-15 18:36:10 +02:00
|
|
|
|
|
|
|
Cypress.Commands.add("searchForApplication", appName => {
|
2021-11-15 16:25:58 +01:00
|
|
|
cy.wait(1000)
|
|
|
|
// Searches for the app
|
|
|
|
cy.get(".filter").then(() => {
|
|
|
|
cy.get(".spectrum-Textfield").within(() => {
|
|
|
|
cy.get("input").eq(0).type(appName)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
// Confirms app exists after search
|
|
|
|
cy.get(".appGrid").contains(appName)
|
|
|
|
})
|
|
|
|
|
|
|
|
Cypress.Commands.add("selectExternalDatasource", datasourceName => {
|
|
|
|
// Navigates to Data Section
|
|
|
|
cy.navigateToDataSection()
|
|
|
|
// Open Data Source modal
|
|
|
|
cy.get('.nav').within(() => {
|
|
|
|
cy.get(".add-button").click()
|
|
|
|
})
|
|
|
|
// Clicks specified datasource & continue
|
|
|
|
cy.get(".item-list").contains(datasourceName).click()
|
|
|
|
cy.get(".spectrum-Dialog-grid").within(() => {
|
|
|
|
cy.get(".spectrum-Button").contains("Continue").click({ force: true })
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Cypress.Commands.add("addSqlDatasourceConfig", (sqlType, noFetch) => {
|
|
|
|
// addExternalDatasource should be called prior to this
|
|
|
|
// Adds the config for specified SQL datasource & fetches tables
|
|
|
|
// Host IP Address
|
|
|
|
cy.wait(500)
|
|
|
|
cy.get(".spectrum-Dialog-grid").within(() => {
|
|
|
|
cy.get(".form-row").contains("Host").parent().children().within(() => {
|
|
|
|
cy.get(".spectrum-Textfield").within(() => {
|
|
|
|
cy.get("input").clear().type("3.251.63.170")
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
// Database Name
|
|
|
|
cy.get(".spectrum-Dialog-grid").within(() => {
|
|
|
|
cy.get(".form-row").contains("Database").parent().children().within(() => {
|
|
|
|
cy.get(".spectrum-Textfield").within(() => {
|
|
|
|
if (sqlType == "PostgreSQL") {
|
|
|
|
cy.get("input").clear().type("test")
|
|
|
|
}
|
|
|
|
if (sqlType == "MySQL") {
|
|
|
|
cy.get("input").clear().type("mysql")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
// User
|
|
|
|
cy.get(".spectrum-Dialog-grid").within(() => {
|
|
|
|
cy.get(".form-row").contains("User").parent().children().within(() => {
|
|
|
|
cy.get(".spectrum-Textfield").within(() => {
|
|
|
|
if (sqlType == "PostgreSQL") {
|
|
|
|
cy.get("input").clear().type("admin")
|
|
|
|
}
|
|
|
|
if (sqlType == "MySQL") {
|
|
|
|
cy.get("input").clear().type("root")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
// Password
|
|
|
|
cy.get(".spectrum-Dialog-grid").within(() => {
|
|
|
|
cy.get(".form-row").contains("Password").parent().children().within(() => {
|
|
|
|
cy.get(".spectrum-Textfield").within(() => {
|
|
|
|
if (sqlType == "PostgreSQL") {
|
|
|
|
cy.get("input").clear().type("8cb2b6f4-4b33-4e86-b790-74eee608a4e9")
|
|
|
|
}
|
|
|
|
if (sqlType == "MySQL") {
|
|
|
|
cy.get("input").clear().type("abdc321d-4d21-4fc7-8d20-f40ab9fe6db0")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
// Click to fetch tables
|
|
|
|
if (!noFetch){
|
|
|
|
cy.get(".spectrum-Dialog-grid").within(() => {
|
|
|
|
cy.get(".spectrum-Button").contains("Fetch tables from database").click({ force: true })
|
|
|
|
cy.wait(1000)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
Cypress.Commands.add("addRestDatasourceConfig", restUrl => {
|
|
|
|
// addExternalDatasource should be called prior to this
|
|
|
|
// Configures REST datasource
|
|
|
|
cy.get(".spectrum-Dialog-grid").within(() => {
|
|
|
|
cy.get(".spectrum-Textfield").within(() => {
|
|
|
|
cy.get("input").clear().type(restUrl)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
// Click Save and continue to query
|
|
|
|
cy.get(".spectrum-Dialog-grid").within(() => {
|
|
|
|
cy.get(".spectrum-Button").contains("Save and continue to query").click({ force: true })
|
|
|
|
cy.wait(500)
|
2021-10-15 18:36:10 +02:00
|
|
|
})
|
|
|
|
})
|