diff --git a/sysom_web/cypress/e2e/diagnosis/diagnose_query.cy.js b/sysom_web/cypress/e2e/diagnosis/diagnose_query.cy.js new file mode 100644 index 0000000000000000000000000000000000000000..8dc2b3f3832cbc53ab816cdcb782e4ad3145675c --- /dev/null +++ b/sysom_web/cypress/e2e/diagnosis/diagnose_query.cy.js @@ -0,0 +1,93 @@ +/* + * @Author: wb-msm241621 + * @Date: 2024-03-11 17:40:55 + * @LastEditTime: 2024-03-13 14:39:13 + * @Description: + */ +/// + +describe("SysOM Diagnosis Test -- Query", () => { + beforeEach(() => { + // 自动登录 + cy.login() + }) + it("Invoke diagnose query, and check result", () => { + cy.intercept("GET", "/api/v1/tasks/?*").as("getDiagnoseTaskList") + + // 1. 访问诊断查询页面 + cy.visit("diagnose/query") + + cy.wait("@getDiagnoseTaskList").then((interception) => { + expect(interception).to.have.property('response') + expect(interception.response?.body.code, 'code').to.equal(200) + expect(interception.response.statusCode).to.equal(200) + + // cy.get('.ant-table-tbody').find('tr').should("have.length.gte", 0) + cy.wait(1000) + cy.get('.ant-table-content').find('table').then(($el) => { + if ($el.text().includes("No data")) { + cy.wrap($el).contains("No data") + } else { + // 断言告警列表数据内容大于等于1 + cy.wrap($el).find('.ant-table-tbody').find('tr').should('have.length.gte', 1) + // 断言表头字段数量是否等于5 + cy.wrap($el).find('.ant-table-tbody').find('tr').eq(0).find('td').should('have.length.gte', 5) + + // 断言诊断ID是否为UUID + cy.wrap($el).find(".ant-table-tbody").find('tr').eq(0).find('td').eq(1).invoke("text").then((text) => { + expect(text).to.match(/[a-zA-Z0-9]{8}/); + }) + + // 断言诊断时间格式 + cy.wrap($el).find(".ant-table-tbody").find('tr').eq(0).find('td').eq(2).invoke("text").then((text) => { + const data = new Date(text); + expect(data.toString()).not.to.equal('Invalid Date!') + }) + + // 断言诊断状态是否在枚举类型中 + cy.wrap($el).find('.ant-table-tbody').find('tr').eq(0).find('td').eq(3).invoke("text").then((text) => { + expect(text.trim()).to.be.oneOf(["诊断完毕", "异常", "准备中", "运行中"]) + }) + + // 断言诊断参数是否大于1 + cy.wrap($el).find('.ant-table-tbody').find('tr').eq(0).find('td').eq(4).find("span").should('have.length.gt', 1) + } + }) + }) + + cy.wait(2000) + + // 2. 诊断查询参数悬着ssh通道 + cy.get('#channel').click({force: true}) + cy.get(".rc-virtual-list-holder-inner").contains("SSH通道").click() + + cy.get(':nth-child(2) > .ant-btn').click() + cy.wait(2000) + + // 3. + cy.get(".ant-table-content").find("table").then(($el) => { + if ($el.text().includes("No data")) { + cy.wrap($el).contains("No data") + } else { + cy.wrap($el).find(".ant-table-tbody").find('tr').eq(0).find('td').eq(5).find('.ant-space-item').eq(0).then(($el) => { + if ($el.text().includes("查看出错信息")) { + // 诊断失败后查看错误信息 + cy.wrap($el).get("a").contains("查看出错信息").click() + cy.wait(1000) + } else { + // 诊断成功后查看诊断结果 + cy.wrap($el).get("a").contains("查看诊断结果").click() + cy.wait(1000) + + cy.get(".ant-pro-card-header").eq(0).scrollIntoView() + cy.get(".ant-pro-card-header").should("contain.text", "诊断结果") + } + }) + } + }) + cy.wait(1500) + cy.scrollTo("top") + + cy.get('.ant-pro-card-body > .ant-form > .ant-space-align-center > :nth-child(1) > .ant-btn').click() + }) +}) diff --git a/sysom_web/cypress/e2e/diagnosis/filecache.cy.js b/sysom_web/cypress/e2e/diagnosis/filecache.cy.js index 6a51781e36c9c16f968e46c61766cc5e5d3c510c..d657439e9759bc2adc67476ee19ff9ac6439b8ce 100644 --- a/sysom_web/cypress/e2e/diagnosis/filecache.cy.js +++ b/sysom_web/cypress/e2e/diagnosis/filecache.cy.js @@ -12,7 +12,7 @@ describe("SysOM Diagnosis Test -- filecache", () => { // 诊断参数 { - "instance": "127.0.0.1", + "instance": Cypress.env("HOSTS")[0], //"value": "", "type": "all" }, @@ -85,39 +85,25 @@ describe("SysOM Diagnosis Test -- filecache", () => { // cy.get('.ant-statistic-content-value').click() //cy.get('.ant-table-thead').should("contain.text", "请求时间") /* ==== End Cypress Studio ==== */ + cy.get('.ant-pro-card-title > div').scrollIntoView() + cy.get('.ant-pro-card-title > div').should('contain.text', '诊断结果') + cy.get('.ant-table-content').last().find('table').then(($el) => { + if ($el.text().includes("No data")) { + cy.wrap($el).contains("No data") + } else { + cy.get('table').last().find('thead').find('tr').find('th').should('have.length.gte', 6) + // const thNames = [ + // 'POD', 'Container', 'Filename', 'Filesize', 'Cached', 'ActiveCached', 'InActiveCached', 'ext' + // ] + // thNames.forEach((name, index) => { + // cy.get('table').last().find('thead').find('tr').find('th').eq(index).invoke('text').should("contain.text", name) + // }) + } + }) }) /* ==== Generated with Cypress Studio ==== */ - cy.get('.ant-table-content').last().find('table').then(($el) => { - if ($el.text().includes("No data")) { - cy.wrap($el).contains("No data") - } else { - cy.get('[style="padding: 0px;"] > .ant-pro-table > \ - .ant-pro-card > .ant-pro-card-body > .ant-table-wrapper > \ - .ant-spin-nested-loading > .ant-spin-container > .ant-table > \ - .ant-table-container > .ant-table-content > table > .ant-table-thead > \ - tr > :nth-child(1)').should("contain.text", "POD"); - - cy.get('[style="padding: 0px;"] > .ant-pro-table > .ant-pro-card > \ - .ant-pro-card-body > .ant-table-wrapper > .ant-spin-nested-loading > \ - .ant-spin-container > .ant-table > .ant-table-container > \ - .ant-table-content > table > .ant-table-thead > tr > :nth-child(2)') - .should("contain.text", "Container"); - - cy.get('[style="padding: 0px;"] > .ant-pro-table > .ant-pro-card > \ - .ant-pro-card-body > .ant-table-wrapper > .ant-spin-nested-loading > \ - .ant-spin-container > .ant-table > .ant-table-container > \ - .ant-table-content > table > .ant-table-thead > tr > :nth-child(3)') - .should("contain.text", "Filename"); - - cy.get('[style="padding: 0px;"] > .ant-pro-table > .ant-pro-card > \ - .ant-pro-card-body > .ant-table-wrapper > .ant-spin-nested-loading > \ - .ant-spin-container > .ant-table > .ant-table-container > \ - .ant-table-content > table > .ant-table-thead > tr > :nth-child(5)') - .should("contain.text", "Cached"); - } - }) /* ==== End Cypress Studio ==== */ }) @@ -128,7 +114,7 @@ describe("SysOM Diagnosis Test -- filecache", () => { // 诊断参数 { - "instance": "127.0.0.1", + "instance": Cypress.env("HOSTS")[0], //"value": "", "type": "host" }, @@ -193,19 +179,22 @@ describe("SysOM Diagnosis Test -- filecache", () => { // cy.get('.ant-statistic-content-value').click() //cy.get('.ant-table-thead').should("contain.text", "请求时间") /* ==== End Cypress Studio ==== */ + cy.get('.ant-pro-card-title > div').scrollIntoView() + cy.get('.ant-pro-card-title > div').should('contain.text', '诊断结果') + cy.get('.ant-table-content').last().find('table').then(($el) => { + if ($el.text().includes("No data")) { + cy.wrap($el).contains("No data") + } else { + cy.get('table').last().find('thead').find('tr').find('th').should('have.length.gte', 6) + const thNames = [ + 'Filename', 'Filesize', 'Cached', 'ActiveCached', 'InActiveCached', 'ext' + ] + thNames.forEach((name, index) => { + cy.get('table').last().find('thead').find('tr').find('th').eq(index).should('contain.text', name) + }) + } + }) }) - /* ==== Generated with Cypress Studio ==== */ - cy.get('[style="padding: 0px;"] > .ant-pro-table > .ant-pro-card > \ - .ant-pro-card-body > .ant-table-wrapper > .ant-spin-nested-loading > \ - .ant-spin-container > .ant-table > .ant-table-container > \ - .ant-table-content > table > .ant-table-thead > tr > :nth-child(1)') - .should("contain.text", "Filename"); - cy.get('[style="padding: 0px;"] > .ant-pro-table > .ant-pro-card > \ - .ant-pro-card-body > .ant-table-wrapper > .ant-spin-nested-loading > \ - .ant-spin-container > .ant-table > .ant-table-container > \ - .ant-table-content > table > .ant-table-thead > tr > :nth-child(3)') - .should("contain.text", "Cached"); - /* ==== End Cypress Studio ==== */ }) }) diff --git a/sysom_web/cypress/e2e/diagnosis/iofsstat_test.cy.js b/sysom_web/cypress/e2e/diagnosis/iofsstat_test.cy.js index c0462370553d64d74eae8fe9d22d9a93ced13ef2..cc3fbee5aabdfb784b7d6c3e852a804b629691ca 100644 --- a/sysom_web/cypress/e2e/diagnosis/iofsstat_test.cy.js +++ b/sysom_web/cypress/e2e/diagnosis/iofsstat_test.cy.js @@ -13,7 +13,7 @@ describe("SysOM Diagnosis Test -- iofsstat", () => { // 诊断参数 { - "instance": "127.0.0.1", + "instance": Cypress.env("HOSTS")[0], "timeout": "5", }, (result) => { diff --git a/sysom_web/cypress/e2e/diagnosis/iohang_test.cy.js b/sysom_web/cypress/e2e/diagnosis/iohang_test.cy.js index f3d9eef960e11ba8e433df5900d19c4c9a1311a1..f004950a47e059ef32770038ea6606a132e6986a 100644 --- a/sysom_web/cypress/e2e/diagnosis/iohang_test.cy.js +++ b/sysom_web/cypress/e2e/diagnosis/iohang_test.cy.js @@ -13,7 +13,7 @@ describe("SysOM Diagnosis Test -- iohang", () => { // 诊断参数 { - "instance": "127.0.0.1", + "instance": Cypress.env("HOSTS")[0], "threshold": "1", "timeout": "10", }, diff --git a/sysom_web/cypress/e2e/diagnosis/iolatency_test.cy.js b/sysom_web/cypress/e2e/diagnosis/iolatency_test.cy.js index 0f8499bfe2783bed8ae5fde5ef1e8d65e9548db3..f398d8c6a74e393684841ac42fc3a0820fe4f4d9 100644 --- a/sysom_web/cypress/e2e/diagnosis/iolatency_test.cy.js +++ b/sysom_web/cypress/e2e/diagnosis/iolatency_test.cy.js @@ -13,7 +13,7 @@ describe("SysOM Diagnosis Test -- iolatency", () => { // 诊断参数 { - "instance": "127.0.0.1", + "instance": Cypress.env("HOSTS")[0], "timeout": "5", "threshold": "1" }, @@ -27,11 +27,16 @@ describe("SysOM Diagnosis Test -- iolatency", () => { //////////////////////////////////////////////////////////// /* ==== Generated with Cypress Studio ==== */ // cy.get('.ant-statistic-content-value').click() - cy.get('.ant-pro-card-border.ant-pro-card-contain-card > .ant-pro-card-header > .ant-pro-card-title').should("contain.text", "Iolatency overview"); - cy.get(':nth-child(1) > .ant-pro-card > .ant-pro-card-body > .ant-statistic > .ant-statistic-content > .ant-statistic-content-value').invoke('text').should("match", /normal|abnormal/); - cy.get(':nth-child(2) > .ant-pro-card-header').should("contain.text", "Overall delay distribution"); - cy.get(':nth-child(3) > .ant-pro-card-header').should("contain.text", "Single IO delay metrics display"); - cy.get(':nth-child(4) > .ant-pro-card-header > .ant-pro-card-title').should("contain.text", "More details of TOP 10 IO"); + if (result.status == "Fail") { + cy.get('.ant-modal-confirm-title').should("contain.text", "诊断失败") + cy.get('.ant-modal-confirm-btns > .ant-btn > span').click() + } else { + cy.get('.ant-pro-card-border.ant-pro-card-contain-card > .ant-pro-card-header > .ant-pro-card-title').should("contain.text", "Iolatency overview"); + cy.get(':nth-child(1) > .ant-pro-card > .ant-pro-card-body > .ant-statistic > .ant-statistic-content > .ant-statistic-content-value').invoke('text').should("match", /normal|abnormal/); + cy.get(':nth-child(2) > .ant-pro-card-header').should("contain.text", "Overall delay distribution"); + cy.get(':nth-child(3) > .ant-pro-card-header').should("contain.text", "Single IO delay metrics display"); + cy.get(':nth-child(4) > .ant-pro-card-header > .ant-pro-card-title').should("contain.text", "More details of TOP 10 IO"); + } //cy.get('.ant-statistic-content-value').should("contain.text", "total") /* ==== End Cypress Studio ==== */ }) diff --git a/sysom_web/cypress/e2e/diagnosis/jitter.cy.js b/sysom_web/cypress/e2e/diagnosis/jitter.cy.js index e37c9020bf81ffa8011393f3aaf984c85107b476..e18cd06cf17e1464a7acd6580916823ca797b948 100644 --- a/sysom_web/cypress/e2e/diagnosis/jitter.cy.js +++ b/sysom_web/cypress/e2e/diagnosis/jitter.cy.js @@ -12,7 +12,7 @@ describe("SysOM Diagnosis Test -- jitter", () => { // 诊断参数 { - "instance": "127.0.0.1", + "instance": Cypress.env("HOSTS")[0], }, // "result": { diff --git a/sysom_web/cypress/e2e/diagnosis/load_diagnosis_test.cy.js b/sysom_web/cypress/e2e/diagnosis/load_diagnosis_test.cy.js index c59110f3d6dee1c7580f1e2eedcd103555fce46f..b850b70620c7834eb1b03ed99810e6850f960c2e 100644 --- a/sysom_web/cypress/e2e/diagnosis/load_diagnosis_test.cy.js +++ b/sysom_web/cypress/e2e/diagnosis/load_diagnosis_test.cy.js @@ -13,7 +13,7 @@ describe("SysOM Diagnosis Test -- loadtask", () => { // 诊断参数 { - "instance": "127.0.0.1" + "instance": Cypress.env("HOSTS")[0] }, // 诊断结果处理(在此处判断诊断的结果数据是否符合预期) diff --git a/sysom_web/cypress/e2e/diagnosis/memgraph.cy.js b/sysom_web/cypress/e2e/diagnosis/memgraph.cy.js index fc86819737d5c5ad72c5db83cee824d14abf0496..ae849e167c4285892081178b28c360a98077cc7e 100644 --- a/sysom_web/cypress/e2e/diagnosis/memgraph.cy.js +++ b/sysom_web/cypress/e2e/diagnosis/memgraph.cy.js @@ -12,7 +12,7 @@ describe("SysOM Diagnosis Test -- memgraph", () => { // 诊断参数 { - "instance": "127.0.0.1" + "instance": Cypress.env("HOSTS")[0] }, // 诊断结果处理(在此处判断诊断的结果数据是否符合预期) diff --git a/sysom_web/cypress/e2e/diagnosis/oomcheck.cy.js b/sysom_web/cypress/e2e/diagnosis/oomcheck.cy.js index 116d0fd13a4dbc383d8036c1e32eb096532a9534..c38a62a946d95281466ebeead7feba86c67ff46b 100644 --- a/sysom_web/cypress/e2e/diagnosis/oomcheck.cy.js +++ b/sysom_web/cypress/e2e/diagnosis/oomcheck.cy.js @@ -13,7 +13,7 @@ describe("SysOM Diagnosis Test -- oomcheck", () => { // 诊断参数 { - "instance": "127.0.0.1" + "instance": Cypress.env("HOSTS")[0] }, // 诊断结果处理(在此处判断诊断的结果数据是否符合预期) diff --git a/sysom_web/cypress/e2e/diagnosis/packetdrop.cy.js b/sysom_web/cypress/e2e/diagnosis/packetdrop.cy.js index 90251777935f7f2747c700212d7b46a9299b17c6..710bac0b9669d544d0a08e298ec3b63eef503f82 100644 --- a/sysom_web/cypress/e2e/diagnosis/packetdrop.cy.js +++ b/sysom_web/cypress/e2e/diagnosis/packetdrop.cy.js @@ -12,7 +12,7 @@ describe("SysOM Diagnosis Test -- packetdrop", () => { // 诊断参数 { - "instance": "127.0.0.1", + "instance": Cypress.env("HOSTS")[0], }, // result { diff --git a/sysom_web/cypress/e2e/diagnosis/retran.cy.js b/sysom_web/cypress/e2e/diagnosis/retran.cy.js index 1b19cad83448be32758c8c8edfa9b1ebdbef702e..c5a3ef36b981c11805703bf4dfee785087c644c0 100644 --- a/sysom_web/cypress/e2e/diagnosis/retran.cy.js +++ b/sysom_web/cypress/e2e/diagnosis/retran.cy.js @@ -12,7 +12,7 @@ describe("SysOM Diagnosis Test -- retran", () => { // 诊断参数 { - "instance": "127.0.0.1", + "instance": Cypress.env("HOSTS")[0], }, diff --git a/sysom_web/cypress/e2e/diagnosis/rtdelay.cy.js b/sysom_web/cypress/e2e/diagnosis/rtdelay.cy.js index 1320e0d154ef4d2f45a034e1fd8bc113c962423a..b7a1b5ea2af76d93fd14c845b28f1bb525395c6d 100644 --- a/sysom_web/cypress/e2e/diagnosis/rtdelay.cy.js +++ b/sysom_web/cypress/e2e/diagnosis/rtdelay.cy.js @@ -12,7 +12,7 @@ describe("SysOM Diagnosis Test -- rtdelay", () => { // 诊断参数 { - "instance": "127.0.0.1", + "instance": Cypress.env("HOSTS")[0], "pid": "-1", "time": "2" }, diff --git a/sysom_web/cypress/e2e/diagnosis/schedmoni.cy.js b/sysom_web/cypress/e2e/diagnosis/schedmoni.cy.js index c56b1abf0a22aad497b4131fc5d9d3bf61ad9024..a93c53eb7ea785f6b1a7b6ee2f290a90c2d4f01a 100644 --- a/sysom_web/cypress/e2e/diagnosis/schedmoni.cy.js +++ b/sysom_web/cypress/e2e/diagnosis/schedmoni.cy.js @@ -12,18 +12,27 @@ describe("SysOM Cluster Manager Test", () => { // 诊断参数 { - "instance": "127.0.0.1", + "instance": Cypress.env("HOSTS")[0], "timeout": "1", - "threshold": "1" + "threshold": "1" }, // 诊断结果处理(在此处判断诊断的结果数据是否符合预期) (result) => { + cy.get('.ant-pro-card-title > div').scrollIntoView() + cy.get('.ant-pro-card-title > div').should('contain.text', '诊断结果') cy.diagnosisTaskResultHandler(result, () => { - cy.get('.ant-pro-card-border.ant-pro-card-contain-card > .ant-pro-card-header > .ant-pro-card-title').should("contain.text", "Event overview"); - cy.get(':nth-child(1) > .ant-pro-card > .ant-pro-card-body > .ant-statistic > .ant-statistic-content > .ant-statistic-content-value').invoke('text').should("match", /emergency|warning|normal/); - cy.get(':nth-child(2) > .ant-pro-card > .ant-pro-card-body > .ant-statistic > .ant-statistic-content > .ant-statistic-content-value').invoke('text').should("match", /emergency|warning|normal/); - cy.get(':nth-child(3) > .ant-pro-card > .ant-pro-card-body > .ant-statistic > .ant-statistic-content > .ant-statistic-content-value').invoke('text').should("match", /emergency|warning|normal/); + cy.get(':nth-child(1) > .ant-pro-card-header > .ant-pro-card-title').should("contain.text", "Event overview"); + cy.get(':nth-child(1) > .ant-pro-card > .ant-pro-card-body').then(($el) => { + if ($el.text().includes("no data")){ + cy.wrap($el).contains("no data") + } else { + cy.get(':nth-child(1) > .ant-pro-card > .ant-pro-card-body > .ant-statistic > .ant-statistic-content > .ant-statistic-content-value').invoke('text').should("match", /emergency|warning|normal/); + cy.get(':nth-child(2) > .ant-pro-card > .ant-pro-card-body > .ant-statistic > .ant-statistic-content > .ant-statistic-content-value').invoke('text').should("match", /emergency|warning|normal/); + cy.get(':nth-child(3) > .ant-pro-card > .ant-pro-card-body > .ant-statistic > .ant-statistic-content > .ant-statistic-content-value').invoke('text').should("match", /emergency|warning|normal/); + } + }) + cy.get(':nth-child(2) > .ant-pro-card-header').should("contain.text", "Timeline Diagram"); cy.get(':nth-child(3) > .ant-pro-card-header > .ant-pro-card-title').should("contain.text", "Scheduling Jitter Details"); }) 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) {