diff --git a/sysom_web/cypress/e2e/diagnosis/diagnose_query.cy.js b/sysom_web/cypress/e2e/diagnosis/diagnose_query.cy.js index 8dc2b3f3832cbc53ab816cdcb782e4ad3145675c..2721094e70f96fadb9fdf61be341bc7c5e24d101 100644 --- a/sysom_web/cypress/e2e/diagnosis/diagnose_query.cy.js +++ b/sysom_web/cypress/e2e/diagnosis/diagnose_query.cy.js @@ -1,7 +1,7 @@ /* * @Author: wb-msm241621 * @Date: 2024-03-11 17:40:55 - * @LastEditTime: 2024-03-13 14:39:13 + * @LastEditTime: 2024-03-14 10:39:48 * @Description: */ /// @@ -17,7 +17,7 @@ describe("SysOM Diagnosis Test -- Query", () => { // 1. 访问诊断查询页面 cy.visit("diagnose/query") - cy.wait("@getDiagnoseTaskList").then((interception) => { + cy.wait("@getDiagnoseTaskList", { timeout: 10000 }).then((interception) => { expect(interception).to.have.property('response') expect(interception.response?.body.code, 'code').to.equal(200) expect(interception.response.statusCode).to.equal(200) diff --git a/sysom_web/cypress/e2e/diagnosis/filecache.cy.js b/sysom_web/cypress/e2e/diagnosis/filecache.cy.js index d657439e9759bc2adc67476ee19ff9ac6439b8ce..659b6f5b1e7b985b3e06bba2a13bbb4e71ab67a0 100644 --- a/sysom_web/cypress/e2e/diagnosis/filecache.cy.js +++ b/sysom_web/cypress/e2e/diagnosis/filecache.cy.js @@ -85,19 +85,24 @@ describe("SysOM Diagnosis Test -- filecache", () => { // cy.get('.ant-statistic-content-value').click() //cy.get('.ant-table-thead').should("contain.text", "请求时间") /* ==== End Cypress Studio ==== */ + cy.wait(1000) 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) - // }) + const dataList = result.result?.podmem?.data + if (dataList && dataList.length > 0) { + const rowItem = dataList[0] + const rowNames = Object.keys(rowItem) + const thNames = rowNames.filter(item => item != "key") + + cy.get('table').last().find('thead').find('tr').find('th').should('have.length.gte', 6) + thNames.forEach((name, index) => { + cy.get('table').last().find('thead').find('tr').find('th').eq(index).should('contain.text', name) + }) + } } }) @@ -185,14 +190,17 @@ describe("SysOM Diagnosis Test -- filecache", () => { 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) - }) + const dataList = result.result?.podmem?.data + if (dataList && dataList.length > 0) { + const rowItem = dataList[0] + const rowNames = Object.keys(rowItem) + const thNames = rowNames.filter(item => item != "key") + + cy.get('table').last().find('thead').find('tr').find('th').should('have.length.gte', 6) + thNames.forEach((name, index) => { + cy.get('table').last().find('thead').find('tr').find('th').eq(index).should('contain.text', name) + }) + } } }) }) diff --git a/sysom_web/cypress/e2e/host/host.cy.js b/sysom_web/cypress/e2e/host/host.cy.js index dcff1c85dc76242e047a31efde86d15d3066c3c7..73b50e2b87665ec7005d0b492c638227d68b6c82 100644 --- a/sysom_web/cypress/e2e/host/host.cy.js +++ b/sysom_web/cypress/e2e/host/host.cy.js @@ -5,6 +5,8 @@ describe("SysOM Host Manager Test", () => { cy.login() }) it("Crate and delete host", () => { + cy.intercept("GET", "/api/v1/host/") + .as("getHostList") cy.intercept("POST", "/api/v1/host/") .as("createHost") @@ -14,11 +16,45 @@ describe("SysOM Host Manager Test", () => { // 1. 访问主机列表也米娜 cy.visit("/host/list") + cy.wait('@getHostList', { timeout: 10000 }) + .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] + + // 判断主机列表是否已存在默认测试主机 + if (ipList.includes(defaultHostIpOne)) { + + // 找到默认的主机,并点击删除按钮 + cy.get("td") + .contains(defaultHostIpOne) + .parent() + .within(() => { + cy.get("td").contains("删除").click() + }) + + // 点击删除按钮之后需要在弹出的浮窗中点击OK确认 + cy.get(".ant-popover-buttons").find("button").contains("OK").click() + // 确认删除接口调用结果为 200 + cy.wait('@deleteHost') + .then((interception) => { + cy.wrap({ + statusCode: interception.response?.statusCode + }).its("statusCode").should("eq", 200) + }) + } + }) + // 2. 点击新建主机并开始添加 cy.addDefaultHost() // 创建完主机后等待一秒钟,一秒钟后执行删除操作 cy.wait(1000) + // 找到最新创建的主机,并点击删除按钮 cy.get("td") @@ -27,10 +63,9 @@ describe("SysOM Host Manager Test", () => { .within(() => { cy.get("td").contains("删除").click() }) - + // 点击删除按钮之后需要在弹出的浮窗中点击OK确认 cy.get(".ant-popover-buttons").find("button").contains("OK").click() - // 确认删除接口调用结果为 200 cy.wait('@deleteHost') .then((interception) => { @@ -38,5 +73,6 @@ describe("SysOM Host Manager Test", () => { statusCode: interception.response?.statusCode }).its("statusCode").should("eq", 200) }) + }) }) \ No newline at end of file diff --git a/sysom_web/cypress/e2e/monitor/nginx_monitor.cy.js b/sysom_web/cypress/e2e/monitor/nginx_monitor.cy.js index 9161db5baded78dd4eac23ad62b1a698a468ffd0..3c824c352aad266c00ba3206e6c8048f2525ab0c 100644 --- a/sysom_web/cypress/e2e/monitor/nginx_monitor.cy.js +++ b/sysom_web/cypress/e2e/monitor/nginx_monitor.cy.js @@ -13,70 +13,124 @@ describe("SysOM Nginx Observer Dashboard Test", () => { cy.wait(2000); // 3. 检查异常告警pannel - cy.getPannelContentByTitle("异常告警分布(次数)").contains("请求抖动"); - cy.getPannelContentByTitle("异常告警分布(次数)").contains("请求4xx"); - cy.getPannelContentByTitle("异常告警分布(次数)").contains("请求5xx"); - cy.getPannelContentByTitle("异常告警分布(次数)").contains("错误日志"); + cy.getPannelContentByTitle("异常告警分布(次数)").then($el => { + if ($el.text().includes("No data")) { + cy.wrap($el).contains("No data") + } else { + cy.wrap($el).contains("请求抖动") + cy.wrap($el).contains("请求4xx") + cy.wrap($el).contains("请求5xx") + cy.wrap($el).contains("错误日志") + } + }); // 4. 检查请求数pannel - cy.getPannelContentByTitle("请求数").find("ul li").should("have.length.gte", 1); - cy.getPannelContentByTitle("请求数").find("ul li").eq(0).contains("requests"); + cy.getPannelContentByTitle("请求数").then($el => { + if ($el.text().includes("No data")) { + cy.wrap($el).contains("No data") + } else { + cy.wrap($el).find("ul li").should("have.length.gte", 1); + cy.wrap($el).find("ul li").eq(0).contains("requests"); + } + }); // 5. 检查http status分布pannel - cy.getPannelContentByTitle("http status分布").find("ul li").should("have.length.gte", 1); - cy.getPannelContentByTitle("http status分布").find("ul li").eq(0).contains("status_1xx"); - cy.getPannelContentByTitle("http status分布").find("ul li").eq(1).contains("status_2xx"); - cy.getPannelContentByTitle("http status分布").find("ul li").eq(2).contains("status_3xx"); - cy.getPannelContentByTitle("http status分布").find("ul li").eq(3).contains("status_4xx"); - cy.getPannelContentByTitle("http status分布").find("ul li").eq(4).contains("status_5xx"); + cy.getPannelContentByTitle("http status分布").then($el => { + if ($el.text().includes("No data")) { + cy.wrap($el).contains("No data") + } else { + cy.wrap($el).find("ul li").should("have.length.gte", 1); + cy.wrap($el).find("ul li").eq(0).contains("status_1xx"); + cy.wrap($el).find("ul li").eq(1).contains("status_2xx"); + cy.wrap($el).find("ul li").eq(2).contains("status_3xx"); + cy.wrap($el).find("ul li").eq(3).contains("status_4xx"); + cy.wrap($el).find("ul li").eq(4).contains("status_5xx"); + } + }); + // 6. 检查响应时延pannel - cy.getPannelContentByTitle("响应时延").find("ul li").should("have.length.gte", 1); - cy.getPannelContentByTitle("响应时延").find("ul li").eq(0).contains("requestTime"); - cy.getPannelContentByTitle("响应时延").find("ul li").eq(1).contains("upstreamTime"); - cy.getPannelContentByTitle("响应时延").find("ul li").eq(2).contains("maxRequestTime"); - cy.getPannelContentByTitle("响应时延").find("ul li").eq(3).contains("maxUpstreamTime"); + cy.getPannelContentByTitle("响应时延").then($el => { + if ($el.text().includes("No data")) { + cy.wrap($el).contains("No data") + } else { + cy.wrap($el).find("ul li").should("have.length.gte", 1); + cy.wrap($el).find("ul li").eq(0).contains("requestTime"); + cy.wrap($el).find("ul li").eq(1).contains("upstreamTime"); + cy.wrap($el).find("ul li").eq(2).contains("maxRequestTime"); + cy.wrap($el).find("ul li").eq(3).contains("maxUpstreamTime"); + } + }); // 7. 检查workers数量pannel - cy.getPannelContentByTitle("workers数量").find("ul li").should("have.length.gte", 1); - cy.getPannelContentByTitle("workers数量").find("ul li").eq(0).contains("workersCount"); + cy.getPannelContentByTitle("workers数量").then($el => { + if ($el.text().includes("No data")) { + cy.wrap($el).contains("No data") + } else { + cy.wrap($el).find("ul li").find("ul li").should("have.length.gte", 1); + cy.wrap($el).find("ul li").find("ul li").eq(0).contains("workersCount"); + } + }); // 8. 检查活跃的连接数pannel - cy.getPannelContentByTitle("活跃的连接数").find("ul li").should("have.length.gte", 1); - cy.getPannelContentByTitle("活跃的连接数").find("ul li").eq(0).contains("activeConnections"); + cy.getPannelContentByTitle("活跃的连接数").then($el => { + if ($el.text().includes("No data")) { + cy.wrap($el).contains("No data") + } else { + cy.wrap($el).find("ul li").should("have.length.gte", 1); + cy.wrap($el).find("ul li").eq(0).contains("activeConnections"); + } + }); // 9. 检查nginx进程cpu利用率pannel - cy.getPannelContentByTitle("nginx进程cpu利用率").find("ul li").should("have.length.gte", 1); - cy.getPannelContentByTitle("nginx进程cpu利用率").find("ul li").eq(0).contains(/\d+/).then(($el) => { - const num = parseFloat($el.text()); - expect(num).to.be.gte(0); - }); - cy.getPannelContentByTitle("nginx进程cpu利用率").find("ul li").eq(1).contains(/\d+/).then(($el) => { - const num = parseFloat($el.text()); - expect(num).to.be.gte(0); + cy.getPannelContentByTitle("nginx进程cpu利用率").then($el => { + if ($el.text().includes("No data")) { + cy.wrap($el).contains("No data") + } else { + cy.wrap($el).find("ul li").should("have.length.gte", 1); + cy.wrap($el).find("ul li").eq(0).contains(/\d+/).then(($el) => { + const num = parseFloat($el.text()); + expect(num).to.be.gte(0); + }); + cy.wrap($el).find("ul li").eq(1).contains(/\d+/).then(($el) => { + const num = parseFloat($el.text()); + expect(num).to.be.gte(0); + }); + } }); // 10. 检查nginx进程内存利用率pannel - cy.getPannelContentByTitle("nginx进程内存利用率").find("ul li").should("have.length.gte", 1); - cy.getPannelContentByTitle("nginx进程内存利用率").find("ul li").eq(0).contains(/\d+/).then(($el) => { - const num = parseFloat($el.text()); - expect(num).to.be.gte(0); - }); - cy.getPannelContentByTitle("nginx进程内存利用率").find("ul li").eq(1).contains(/\d+/).then(($el) => { - const num = parseFloat($el.text()); - expect(num).to.be.gte(0); + cy.getPannelContentByTitle("nginx进程内存利用率").then($el => { + if ($el.text().includes("No data")) { + cy.wrap($el).contains("No data") + } else { + cy.wrap($el).find("ul li").should("have.length.gte", 1); + cy.wrap($el).find("ul li").eq(0).contains(/\d+/).then(($el) => { + const num = parseFloat($el.text()); + expect(num).to.be.gte(0); + }); + cy.wrap($el).find("ul li").eq(1).contains(/\d+/).then(($el) => { + const num = parseFloat($el.text()); + expect(num).to.be.gte(0); + }); + } }); // 11. 检查nginx进程网络流量pannel - cy.getPannelContentByTitle("nginx进程网络流量").find("ul li").should("have.length.gte", 1); - cy.getPannelContentByTitle("nginx进程网络流量").find("ul li").eq(0).contains(/\d+/).then(($el) => { - const num = parseFloat($el.text()); - expect(num).to.be.gte(0); + cy.getPannelContentByTitle("nginx进程网络流量").then($el => { + if ($el.text().includes("No data")) { + cy.wrap($el).contains("No data") + } else { + cy.wrap($el).find("ul li").should("have.length.gte", 1); + cy.wrap($el).find("ul li").eq(0).contains(/\d+/).then(($el) => { + const num = parseFloat($el.text()); + expect(num).to.be.gte(0); + }); + cy.wrap($el).find("ul li").eq(1).contains(/\d+/).then(($el) => { + const num = parseFloat($el.text()); + expect(num).to.be.gte(0); + }); + } }); - cy.getPannelContentByTitle("nginx进程网络流量").find("ul li").eq(1).contains(/\d+/).then(($el) => { - const num = parseFloat($el.text()); - expect(num).to.be.gte(0); - }); - }) }) \ No newline at end of file