diff --git a/sysom_web/cypress/e2e/host/host.cy.js b/sysom_web/cypress/e2e/host/host.cy.js index 665d8b11e08da7180c9459eb5a9999cee9dae7ff..dcff1c85dc76242e047a31efde86d15d3066c3c7 100644 --- a/sysom_web/cypress/e2e/host/host.cy.js +++ b/sysom_web/cypress/e2e/host/host.cy.js @@ -14,37 +14,8 @@ describe("SysOM Host Manager Test", () => { // 1. 访问主机列表也米娜 cy.visit("/host/list") - // 2. 点击新建主机打开模块框 - cy.get("button").contains("新建主机").click() - - // 3. 在模态框内部填充字段 - cy.get(".ant-modal-content").first().within(() => { - // 3.1 cluster - cy.get("#cluster").focus().type("default").type("{enter}") - - // 3.2 hostname - cy.get("#hostname").focus().clear().type("local") - - // 3.3 username - cy.get("#username").focus().clear().type("root") - - // 3.4 password - const default_host_password = Cypress.env("DEFAULT_HOST_PASSWORD") - cy.get("#host_password").focus().clear().type(default_host_password) - - // 3.5 ip - cy.get("#ip").focus().clear().type("127.0.0.1") - - // 3.6 port - cy.get("#port").focus().clear().type("22") - - // 3.7 确认 - cy.get("button").contains("确 认").click() - - // 3.8 等待新建主机请求结束,判断请求是否成功 - // 检查状态码返回是否是200(如果集群已经存在会返回400) - cy.wait('@createHost').its("response.statusCode").should("eq", 200) - }) + // 2. 点击新建主机并开始添加 + cy.addDefaultHost() // 创建完主机后等待一秒钟,一秒钟后执行删除操作 cy.wait(1000) diff --git a/sysom_web/cypress/support/commands.js b/sysom_web/cypress/support/commands.js index b0dc6b363441e17e6a01fa31e5b72e70a3210863..e141dfc21b4b1499b42dab0d10cfb1def65f4130 100644 --- a/sysom_web/cypress/support/commands.js +++ b/sysom_web/cypress/support/commands.js @@ -24,6 +24,17 @@ // -- This will overwrite an existing command -- // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) +Cypress.on('uncaught:exception', (err, runnable) => { + // return false to prevent the error from failing the test if it matches + // the specific error message + if (err.message.includes('ResizeObserver loop completed with undelivered notifications')) { + return false; + } + // else let Cypress handle the exception as it normally does + return true; +}); + + Cypress.Commands.add("login", () => { cy.visit("/user/login") cy.get("#username").focus().clear().type(Cypress.env("SYSOM_ACCOUNT_USERNAME")) @@ -37,6 +48,44 @@ Cypress.Commands.add("login", () => { } }) +Cypress.Commands.add('addDefaultHost', () => { + cy.intercept("POST", "/api/v1/host/") + .as("createHost") + + // 1. 点击新建主机打开模块框 + cy.get("button").contains("新建主机").click() + + // 2. 在模态框内部填充字段 + cy.get(".ant-modal-content").first().within(() => { + // 1.1 cluster + // cy.get("#cluster").focus().type("default") + cy.get('#cluster').type("default").type("{enter}", {force: true}) + + // 2.2 hostname + cy.get("#hostname").focus().clear().type("local") + + // 2.3 username + cy.get("#username").focus().clear().type("root") + + // 2.4 password + const default_host_password = Cypress.env("DEFAULT_HOST_PASSWORD") + cy.get("#host_password").focus().clear().type(default_host_password) + + // 2.5 ip + cy.get("#ip").focus().clear().type("127.0.0.1") + + // 2.6 port + cy.get("#port").focus().clear().type("22") + + // 2.7 确认 + cy.get("button").contains("确 认").click() + + // 2.8 等待新建主机请求结束,判断请求是否成功 + // 检查状态码返回是否是200(如果集群已经存在会返回400) + cy.wait('@createHost').its("response.statusCode").should("eq", 200) + }) +}) + /** * SysOM 诊断测试封装 * @param {*} pageUrl 诊断前端url @@ -44,6 +93,8 @@ Cypress.Commands.add("login", () => { * @param {*} resultCheckCallback 诊断结果处理(在此处判断诊断结果是否符合预期) */ Cypress.Commands.add("sysomDiagnosisCheck", (pageUrl, params, resultCheckCallback) => { + cy.intercept("GET", "/api/v1/host") + .as("getHostList") cy.intercept("POST", "/api/v1/tasks/") .as("createDiagnosisTask") @@ -57,6 +108,37 @@ Cypress.Commands.add("sysomDiagnosisCheck", (pageUrl, params, resultCheckCallbac cy.visit(pageUrl) cy.wait(1000) + cy.wait('@getHostList') + .then((interception) => { + expect(interception).to.have.property('response') + expect(interception.response?.body.code, 'code').to.equal(200) + expect(interception.response.statusCode).to.equal(200) + const { data } = interception.response.body + const ipList = data.map((item) => { + return item.ip + }) + + const defaultHostIpOne = Cypress.env("HOSTS")[0] + const defaultHostIpTwo = Cypress.env("HOSTS")[1] + + if (ipList.includes(defaultHostIpOne) && ipList.includes(defaultHostIpTwo)) { + expect(defaultHostIpOne).to.be.oneOf(ipList) + expect(defaultHostIpTwo).to.be.oneOf(ipList) + } else { + // 1. 跳转到主机列表页面 + cy.visit("/host/list") + cy.wait(1000) + + // 2. 添加默认主机 + cy.addDefaultHost() + cy.wait(1000) + + // 返回当前页面 + cy.visit(pageUrl) + cy.wait(30000) + } + }) + // 2 输入instance参数 for (let k in params) { if (k.indexOf("instance") != -1) {