dt_automate/method/hw_dtcloud.go
2025-02-26 18:58:43 +08:00

153 lines
5.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package method
import (
"fmt"
"log"
"github.com/playwright-community/playwright-go"
)
func HW_DTCLOUD() {
// 启动 Playwright
pw, err := playwright.Run()
if err != nil {
log.Fatalf("could not start Playwright: %v", err)
}
defer pw.Stop()
// 启动浏览器Chromium
browser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{
Headless: playwright.Bool(false), // 设置为 false 以显示浏览器界面
Args: []string{
"--ignore-certificate-errors", // 忽略证书错误[^28^][^29^]
},
})
if err != nil {
log.Fatalf("could not launch browser: %v", err)
}
defer browser.Close()
// 创建一个新页面
page, err := browser.NewPage()
if err != nil {
log.Fatalf("could not create page: %v", err)
}
// 设置浏览器窗口大小
err = page.SetViewportSize(1920, 1080) // 宽度为 1200px高度为 800px
if err != nil {
log.Fatalf("无法设置浏览器窗口大小: %v", err)
}
// 导航到指定网址
_, err = page.Goto("https://ops.hlw.dtcloud.com/login", playwright.PageGotoOptions{WaitUntil: playwright.WaitUntilStateDomcontentloaded})
if err != nil {
log.Fatalf("could not go to the page: %v", err)
}
// page.WaitForTimeout(4000)
//输入用户名
page.Locator(`.el-input__inner`).Nth(0).Fill("opsadmin")
//输入密码
page.Locator(`.el-input__inner`).Nth(1).Fill(`DTXCY@2024#`)
var name string
fmt.Print("请输入验证码:")
fmt.Scanf("%s", &name)
//输入验证码
page.Locator(`.el-input__inner`).Nth(2).Fill(name)
log.Println("当前验证码为:", name)
page.WaitForTimeout(2000)
//登录
if err := page.Locator(".el-button.login-form-item.login-btn.el-button--primary").Click(); err != nil {
log.Fatalf("could not click button: %v", err)
}
page.WaitForTimeout(7000)
//运维中心主页
page.Screenshot(playwright.PageScreenshotOptions{
Path: playwright.String("img/hw_dtcloud_man.png"),
FullPage: playwright.Bool(false),
})
// tool.Jietu("img/hw_dtcloud_man.png")
page.Goto("https://ops.hlw.dtcloud.com/console/om/capacity/overview?regionId=-1") //跳转到运维中心概览
page.WaitForTimeout(4000)
page.Screenshot(playwright.PageScreenshotOptions{
Path: playwright.String("img/hw_dtcloud_01.png"),
FullPage: playwright.Bool(false),
})
// tool.Jietu("img/hw_dtcloud_01.png")
page.Goto("https://ops.hlw.dtcloud.com/console/om/capacity/resource?regionId=-1") //运维-资源容量
page.WaitForTimeout(4000)
page.Screenshot(playwright.PageScreenshotOptions{
Path: playwright.String("img/hw_dtcloud_02.png"),
FullPage: playwright.Bool(false),
})
// tool.Jietu("img/hw_dtcloud_02.png")
page.Goto("https://ops.hlw.dtcloud.com/region/dtcloud1/console/om/monitor/overview") //监控-概览
page.WaitForTimeout(4000)
page.Screenshot(playwright.PageScreenshotOptions{
Path: playwright.String("img/hw_dtcloud_03.png"),
FullPage: playwright.Bool(false),
})
// tool.Jietu("img/hw_dtcloud_03.png")
page.Goto("https://ops.hlw.dtcloud.com/region/dtcloud1/console/om/monitor/resource") //监控-资源监控
page.WaitForTimeout(4000)
page.Locator(`.arco-tree.arco-tree-show-line`).Locator(`div`).Nth(4).Locator(`span`).Nth(1).Locator(`span[role="button"]`).Click()
page.Locator(`div[data-test-id="PhysicalServer"]`).Click()
page.WaitForTimeout(1000)
page.Screenshot(playwright.PageScreenshotOptions{
Path: playwright.String("img/hw_dtcloud_04.png"),
FullPage: playwright.Bool(false),
})
// tool.Jietu("img/hw_dtcloud_04.png")
page.Goto("https://ops.hlw.dtcloud.com/region/dtcloud1/console/om/alert/view") //监控-告警-告警查看
page.WaitForTimeout(4000)
page.Locator(`.flex-between mb20`).Locator(`.arco-material-last-days`).Locator(`.arco-space.arco-space-horizontal.arco-space-align-center`).Locator(`div`).Nth(0).Locator(`button`).Click()
page.WaitForTimeout(2000)
page.Screenshot(playwright.PageScreenshotOptions{
Path: playwright.String("img/hw_dtcloud_05.png"),
FullPage: playwright.Bool(false),
})
// tool.Jietu("img/hw_dtcloud_05.png")
page.Goto("https://ops.hlw.dtcloud.com/region/dtcloud1/console/om/alert/history") //监控-告警历史
page.WaitForTimeout(4000)
page.Locator(`.arco-btn.arco-btn-outline.arco-btn-size-default.arco-btn-shape-square`).Nth(0).Click()
page.WaitForTimeout(500)
page.Locator(`.arco-input-tag-input.arco-input-tag-input-size-default.arco-input-tag-input-autowidth`).Click()
page.Locator(`.arco-select-option-wrapper`).Nth(1).Locator(`.arco-checkbox-mask`).Click()
page.Locator(`.arco-btn.arco-btn-primary.arco-btn-size-mini.arco-btn-shape-square`).Click()
page.WaitForTimeout(1000)
page.Screenshot(playwright.PageScreenshotOptions{
Path: playwright.String("img/hw_dtcloud_06.png"),
FullPage: playwright.Bool(false),
})
// tool.Jietu("img/hw_dtcloud_06.png")
page.Goto("https://ops.hlw.dtcloud.com/region/dtcloud1/console/om/health-inspection/outputs?page=1&size=10&order=createTime%3Adesc&searchResult=%7B%7D") //运维-监控巡检-巡检结果
page.WaitForTimeout(4000)
page.Screenshot(playwright.PageScreenshotOptions{
Path: playwright.String("img/hw_dtcloud_07.png"),
FullPage: playwright.Bool(false),
})
// tool.Jietu("img/hw_dtcloud_07.png")
page.Goto("https://ops.hlw.dtcloud.com/console/om/capacity/service?regionId=-1") //运维-容量-云服务容量
page.WaitForTimeout(4000)
page.Screenshot(playwright.PageScreenshotOptions{
Path: playwright.String("img/hw_dtcloud_08.png"),
FullPage: playwright.Bool(false),
})
// 获取页面标题
title, err := page.Title()
if err != nil {
log.Fatalf("could not get title: %v", err)
}
log.Printf("Page title is: %s\n", title)
page.WaitForTimeout(5000)
}