提交 ee075eb9 编写于 作者: 雨爱无痕

* Add run statistic case

上级 37b3705f
package main
import (
"strconv"
"strings"
"testing"
......@@ -818,6 +819,249 @@ func RunReExecAllCase(t *testing.T) {
}
}
func RunFailStatistic(t *testing.T) {
pw, err := playwright.Run()
if err != nil {
t.Error(err)
t.FailNow()
}
headless := true
var slowMo float64 = 100
workspaceBrowser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{Headless: &headless, SlowMo: &slowMo})
if err != nil {
t.Errorf("Fail to launch the web workspaceBrowser: %v", err)
t.FailNow()
}
page, err := workspaceBrowser.NewPage()
if err != nil {
t.Errorf("Create the new page fail: %v", err)
t.FailNow()
}
if _, err = page.Goto("http://127.0.0.1:8000/", playwright.PageGotoOptions{
WaitUntil: playwright.WaitUntilStateDomcontentloaded}); err != nil {
t.Errorf("The specific URL is missing: %v", err)
t.FailNow()
}
_, err = page.WaitForSelector(".tree-node")
if err != nil {
t.Errorf("Wait tree-node fail: %v", err)
t.FailNow()
}
locator, err := page.Locator(".tree-node", playwright.PageLocatorOptions{HasText: "单元测试工作目录"})
c, err := locator.Count()
if err != nil || c == 0 {
t.Errorf("Find workspace fail: %v", err)
t.FailNow()
}
err = locator.Click()
if err != nil {
t.Errorf("Click node fail: %v", err)
t.FailNow()
}
scriptLocator, err := locator.Locator("text=1_string_match.php")
if err != nil {
t.Errorf("Find 1_string_match.php fail: %v", err)
t.FailNow()
}
err = scriptLocator.Click()
if err != nil {
t.Errorf("Click script fail: %v", err)
t.FailNow()
}
elements, _ := page.QuerySelectorAll(".statistic>>span")
runTimes, _ := elements[0].InnerText()
failTimes, _ := elements[2].InnerText()
runTimesInt, _ := strconv.Atoi(runTimes)
failTimesInt, _ := strconv.Atoi(failTimes)
err = page.Click(".tabs-nav-toolbar>>[title=\"Run\"]")
if err != nil {
t.Errorf("Click run fail: %v", err)
t.FailNow()
}
_, err = page.WaitForSelector("#log-list>>.msg-span>>:has-text('执行1个用例,耗时')")
if err != nil {
t.Errorf("Wait exec result fail: %v", err)
t.FailNow()
}
page.WaitForTimeout(200)
elements, _ = page.QuerySelectorAll(".statistic>>span")
runTimes2, _ := elements[0].InnerText()
failTimes2, _ := elements[2].InnerText()
runTimes2Int, _ := strconv.Atoi(runTimes2)
failTimes2Int, _ := strconv.Atoi(failTimes2)
if runTimes2Int-runTimesInt != 1 || failTimes2Int-failTimesInt != 1 {
t.Error("statistic error")
t.FailNow()
}
if err = workspaceBrowser.Close(); err != nil {
t.Errorf("The workspaceBrowser cannot be closed: %v", err)
t.FailNow()
}
if err = pw.Stop(); err != nil {
t.Errorf("The playwright cannot be stopped: %v", err)
t.FailNow()
}
}
func RunSuccessStatistic(t *testing.T) {
pw, err := playwright.Run()
if err != nil {
t.Error(err)
t.FailNow()
}
headless := true
var slowMo float64 = 100
workspaceBrowser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{Headless: &headless, SlowMo: &slowMo})
if err != nil {
t.Errorf("Fail to launch the web workspaceBrowser: %v", err)
t.FailNow()
}
page, err := workspaceBrowser.NewPage()
if err != nil {
t.Errorf("Create the new page fail: %v", err)
t.FailNow()
}
if _, err = page.Goto("http://127.0.0.1:8000/", playwright.PageGotoOptions{
WaitUntil: playwright.WaitUntilStateDomcontentloaded}); err != nil {
t.Errorf("The specific URL is missing: %v", err)
t.FailNow()
}
_, err = page.WaitForSelector(".tree-node")
if err != nil {
t.Errorf("Wait tree-node fail: %v", err)
t.FailNow()
}
locator, err := page.Locator(".tree-node", playwright.PageLocatorOptions{HasText: "单元测试工作目录"})
c, err := locator.Count()
if err != nil || c == 0 {
t.Errorf("Find workspace fail: %v", err)
t.FailNow()
}
err = locator.Click()
if err != nil {
t.Errorf("Click node fail: %v", err)
t.FailNow()
}
scriptLocator, err := locator.Locator("text=2_webpage_extract.php")
if err != nil {
t.Errorf("Find 2_webpage_extract.php fail: %v", err)
t.FailNow()
}
err = scriptLocator.Click()
if err != nil {
t.Errorf("Click script fail: %v", err)
t.FailNow()
}
elements, _ := page.QuerySelectorAll(".statistic>>span")
runTimes, _ := elements[0].InnerText()
succTimes, _ := elements[1].InnerText()
runTimesInt, _ := strconv.Atoi(runTimes)
succTimesInt, _ := strconv.Atoi(succTimes)
err = page.Click(".tabs-nav-toolbar>>[title=\"Run\"]")
if err != nil {
t.Errorf("Click run fail: %v", err)
t.FailNow()
}
_, err = page.WaitForSelector("#log-list>>.msg-span>>:has-text('执行1个用例,耗时')")
if err != nil {
t.Errorf("Wait exec result fail: %v", err)
t.FailNow()
}
page.WaitForTimeout(200)
elements, _ = page.QuerySelectorAll(".statistic>>span")
runTimes2, _ := elements[0].InnerText()
succTimes2, _ := elements[1].InnerText()
runTimes2Int, _ := strconv.Atoi(runTimes2)
succTimes2Int, _ := strconv.Atoi(succTimes2)
if runTimes2Int-runTimesInt != 1 || succTimes2Int-succTimesInt != 1 {
t.Error("statistic error")
t.FailNow()
}
if err = workspaceBrowser.Close(); err != nil {
t.Errorf("The workspaceBrowser cannot be closed: %v", err)
t.FailNow()
}
if err = pw.Stop(); err != nil {
t.Errorf("The playwright cannot be stopped: %v", err)
t.FailNow()
}
}
func RunBugStatistic(t *testing.T) {
pw, err := playwright.Run()
if err != nil {
t.Error(err)
t.FailNow()
}
headless := true
var slowMo float64 = 100
workspaceBrowser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{Headless: &headless, SlowMo: &slowMo})
if err != nil {
t.Errorf("Fail to launch the web workspaceBrowser: %v", err)
t.FailNow()
}
page, err := workspaceBrowser.NewPage()
if err != nil {
t.Errorf("Create the new page fail: %v", err)
t.FailNow()
}
if _, err = page.Goto("http://127.0.0.1:8000/", playwright.PageGotoOptions{
WaitUntil: playwright.WaitUntilStateDomcontentloaded}); err != nil {
t.Errorf("The specific URL is missing: %v", err)
t.FailNow()
}
_, err = page.WaitForSelector(".tree-node")
if err != nil {
t.Errorf("Wait tree-node fail: %v", err)
t.FailNow()
}
locator, err := page.Locator(".tree-node", playwright.PageLocatorOptions{HasText: "单元测试工作目录"})
c, err := locator.Count()
if err != nil || c == 0 {
t.Errorf("Find workspace fail: %v", err)
t.FailNow()
}
err = locator.Click()
if err != nil {
t.Errorf("Click node fail: %v", err)
t.FailNow()
}
scriptLocator, err := locator.Locator("text=1_string_match.php")
if err != nil {
t.Errorf("Find 1_string_match.php fail: %v", err)
t.FailNow()
}
err = scriptLocator.Click()
if err != nil {
t.Errorf("Click script fail: %v", err)
t.FailNow()
}
page.WaitForTimeout(200)
elements, _ := page.QuerySelectorAll(".statistic>>span")
bugTimes, _ := elements[3].InnerText()
bugTimesInt, _ := strconv.Atoi(bugTimes)
err = page.Click(".statistic>>span>>nth=3")
if err != nil {
t.Errorf("Click bug btn fail: %v", err)
t.FailNow()
}
elements, _ = page.QuerySelectorAll("#bugsModal>>tr")
bugTimes2Int := len(elements)
if bugTimes2Int-1 != bugTimesInt {
t.Error("statistic error")
t.FailNow()
}
if err = workspaceBrowser.Close(); err != nil {
t.Errorf("The workspaceBrowser cannot be closed: %v", err)
t.FailNow()
}
if err = pw.Stop(); err != nil {
t.Errorf("The playwright cannot be stopped: %v", err)
t.FailNow()
}
}
func TestUiRun(t *testing.T) {
t.Run("RunScript", RunScript)
t.Run("RunSelectedScripts", RunSelectedScripts)
......@@ -825,4 +1069,7 @@ func TestUiRun(t *testing.T) {
t.Run("RunAll", RunAll)
t.Run("RunReExecAllCase", RunReExecAllCase)
t.Run("RunReExecFailCase", RunReExecFailCase)
t.Run("RunSuccessStatistic", RunSuccessStatistic)
t.Run("RunFailStatistic", RunFailStatistic)
t.Run("RunBugStatistic", RunBugStatistic)
}
<template>
<ZModal
id="bugsModal"
:showModal="props.show"
:title="t('zentao_bug')"
:contentStyle="{width: '90vw', height: '90vh'}"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册