提交 d239da51 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

run test script/suite and show results

上级 5bf1b718
......@@ -80,8 +80,10 @@ func DealwithTestCase(tc model.TestCase, langType string, singleFile bool, caseP
srcCode := make([]string, 0)
steps = append(steps, "@开头的为含验证点的步骤")
temp := fmt.Sprintf("\n%sCODE: 此处编写操作步骤代码\n", LangMap[langType]["commentsTag"])
srcCode = append(srcCode, temp)
readme := utils.ReadFile("xdoc/template/readme.tpl") + "\n"
stepDisplayMaxWidth := 0
......
......@@ -13,7 +13,7 @@ func Run(scriptDir string, fileNames []string, langType string) {
scriptDir = utils.Prefer.WorkDir + scriptDir
}
LangMap := script.GetLangMap()
LangMap := script.LangMap
var files []string
if fileNames != nil && len(fileNames) > 0 {
files, _ = utils.GetSpecifiedFiles(scriptDir, fileNames)
......
......@@ -10,6 +10,7 @@ import (
)
func main() {
utils.RunFromCui = false
flagSets := make([]flag.FlagSet, 0)
var language string
......
......@@ -11,7 +11,7 @@ import (
func CheckResults(files []string, dir string, langType string, report *model.TestReport) {
fmt.Println("\n")
utils.PrintWholeLine(utils.I118Prt.Sprintf("begin_analyse"), "=", color.FgBlue)
PrintWholeLine(utils.I118Prt.Sprintf("begin_analyse"), "=", color.FgBlue)
for _, scriptFile := range files {
logFile := utils.ScriptToLogName(dir, scriptFile)
......@@ -99,13 +99,3 @@ func ValidateStep(langType string, expectLines []string, actualLines []string) (
return stepResult, checkpointLogs
}
func PrintAndLog(logs *[]string, str string) {
*logs = append(*logs, str)
fmt.Println(str)
}
func PrintAndLogColorLn(logs *[]string, str string, attr color.Attribute) {
*logs = append(*logs, str)
color.New(attr).Printf(str + "\n")
}
......@@ -11,7 +11,7 @@ import (
)
func ExeScripts(files []string, dir string, langType string, report *model.TestReport) {
utils.PrintWholeLine(utils.I118Prt.Sprintf("start_execution", ""), "=", color.FgBlue)
PrintWholeLine(utils.I118Prt.Sprintf("start_execution", ""), "=", color.FgBlue)
startTime := time.Now().Unix()
report.StartTime = startTime
......@@ -20,7 +20,7 @@ func ExeScripts(files []string, dir string, langType string, report *model.TestR
ExeScript(file, langType, dir)
}
utils.PrintWholeLine(utils.I118Prt.Sprintf("end_execution", ""), "=", color.FgBlue)
PrintWholeLine(utils.I118Prt.Sprintf("end_execution", ""), "=", color.FgBlue)
endTime := time.Now().Unix()
secs := endTime - startTime
......@@ -47,18 +47,19 @@ func ExeScript(file string, langType string, dir string) {
fmt.Println("")
msg := utils.I118Prt.Sprintf("start_case", file, startTime.Format("2006-01-02 15:04:05"))
utils.PrintWholeLine(msg, "-", color.FgCyan)
PrintWholeLine(msg, "-", color.FgCyan)
fmt.Println("")
//fmt.Println("")
output := utils.ExecCommand(command)
utils.WriteFile(logFile, strings.Join(output, ""))
Printt(strings.Join(output, ""))
entTime := time.Now()
secs := int64(entTime.Sub(startTime) / time.Second)
msg = utils.I118Prt.Sprintf("end_case", file, entTime.Format("2006-01-02 15:04:05"), secs)
utils.PrintWholeLine(msg, "-", color.FgCyan)
PrintWholeLine(msg, "-", color.FgCyan)
fmt.Println("")
//fmt.Println("")
}
package biz
import (
"fmt"
"github.com/easysoft/zentaoatf/src/utils"
"github.com/fatih/color"
"io"
"strings"
"unicode/utf8"
)
func PrintWholeLine(msg string, char string, attr color.Attribute) {
prefixLen := 6
var postfixLen int
if utils.RunFromCui {
maxX, _ := utils.Cui.Size()
postfixLen = maxX - utils.LeftWidth - utf8.RuneCountInString(msg) - 8
} else {
postfixLen = utils.Prefer.Width - utf8.RuneCountInString(msg) - 6
if postfixLen < 0 { // no width in debug mode
postfixLen = 6
}
}
preFixStr := strings.Repeat(char, prefixLen)
postFixStr := strings.Repeat(char, postfixLen)
var output io.Writer
if utils.RunFromCui {
output, _ = utils.Cui.View("main")
} else {
output = color.Output
}
clr := color.New(attr)
clr.Fprintf(output, fmt.Sprintf("%s%s%s\n", preFixStr, msg, postFixStr))
}
func PrintAndLog(logs *[]string, str string) {
*logs = append(*logs, str)
var output io.Writer
if utils.RunFromCui {
output, _ = utils.Cui.View("main")
} else {
output = color.Output
}
fmt.Fprintf(output, str+"\n")
}
func PrintAndLogColorLn(logs *[]string, str string, attr color.Attribute) {
*logs = append(*logs, str)
var output io.Writer
if utils.RunFromCui {
output, _ = utils.Cui.View("main")
} else {
output = color.Output
}
clr := color.New(attr)
clr.Fprintf(output, str+"\n")
}
func Printt(str string) {
var output io.Writer
if utils.RunFromCui {
output, _ = utils.Cui.View("main")
} else {
output = color.Output
}
fmt.Fprintf(output, str+"\n")
}
func coloredStatus(status string) string {
temp := strings.ToLower(status)
switch temp {
case "pass":
return color.GreenString(utils.I118Prt.Sprintf(temp))
case "fail":
return color.RedString(utils.I118Prt.Sprintf(temp))
case "skip":
return color.YellowString(utils.I118Prt.Sprintf(temp))
}
return status
}
......@@ -26,12 +26,12 @@ func Print(report model.TestReport, workDir string) {
PrintAndLogColorLn(&logs, fmt.Sprintf(" %s: %d", utils.I118Prt.Sprintf("skip"), report.Skip), color.FgYellow)
for _, cs := range report.Cases {
str := "\n%s %s \n"
str := "\n %s %s "
status := cs.Status.String()
statusColor := colorStatus(status)
statusColor := coloredStatus(status)
logs = append(logs, fmt.Sprintf(str, status, cs.Path))
fmt.Printf(str, statusColor, cs.Path)
Printt(fmt.Sprintf(str, statusColor, cs.Path))
if len(cs.Steps) > 0 {
count := 0
......@@ -42,10 +42,10 @@ func Print(report model.TestReport, workDir string) {
str := " %s%d: %s %s"
status := utils.BoolToPass(step.Status)
statusColor := colorStatus(status)
statusColor := coloredStatus(status)
logs = append(logs, fmt.Sprintf(str, utils.I118Prt.Sprintf("step"), step.Numb, status, step.Name))
fmt.Printf(str, utils.I118Prt.Sprintf("step"), step.Numb, statusColor, step.Name+"\n")
Printt(fmt.Sprintf(str, utils.I118Prt.Sprintf("step"), step.Numb, statusColor, step.Name+"\n"))
count1 := 0
for _, cp := range step.CheckPoints {
......@@ -54,10 +54,10 @@ func Print(report model.TestReport, workDir string) {
}
cpStatus := utils.BoolToPass(step.Status)
cpStatusColor := colorStatus(cpStatus)
cpStatusColored := coloredStatus(cpStatus)
logs = append(logs, fmt.Sprintf(" %s%d: %s", utils.I118Prt.Sprintf("checkpoint"), cp.Numb,
utils.BoolToPass(cp.Status)))
fmt.Printf(" %s%d: %s", utils.I118Prt.Sprintf("checkpoint"), cp.Numb, cpStatusColor)
Printt(fmt.Sprintf(" %s%d: %s", utils.I118Prt.Sprintf("checkpoint"), cp.Numb, cpStatusColored))
PrintAndLog(&logs, fmt.Sprintf(" %s %s", utils.I118Prt.Sprintf("expect_result"), cp.Expect))
PrintAndLog(&logs, fmt.Sprintf(" %s %s", utils.I118Prt.Sprintf("actual_result"), cp.Actual))
......@@ -74,18 +74,3 @@ func Print(report model.TestReport, workDir string) {
utils.WriteFile(workDir+"/logs/result-"+utils.DateTimeStrLong(time.Now())+".txt", strings.Join(logs, "\n"))
}
func colorStatus(status string) string {
temp := strings.ToLower(status)
switch temp {
case "pass":
return color.GreenString(utils.I118Prt.Sprintf(temp))
case "fail":
return color.RedString(utils.I118Prt.Sprintf(temp))
case "skip":
return color.YellowString(utils.I118Prt.Sprintf(temp))
}
return status
}
......@@ -9,6 +9,8 @@ import (
)
func main() {
utils.RunFromCui = true
mock.Server = mock.CreateServer("case-from-prodoct.json")
defer mock.Server.Close()
......@@ -20,6 +22,8 @@ func main() {
g.Cursor = true
g.Mouse = true
utils.Cui = g
ui.InitMainPage(g)
if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
......
......@@ -53,3 +53,7 @@ func GetLangMap() map[string]map[string]string {
return LangMap
}
func init() {
GetLangMap()
}
......@@ -72,7 +72,7 @@ func InitImportPage(g *gocui.Gui) error {
singleFileInput := NewRadioWidget(g, "singleFileInput", left, 7, true)
ViewMap["import"] = append(ViewMap["import"], singleFileInput.Name())
buttonX := (maxX-LeftWidth)/2 + LeftWidth - ButtonWidth
buttonX := (maxX-utils.LeftWidth)/2 + utils.LeftWidth - ButtonWidth
submitInput := NewButtonWidgetAutoWidth(g, "submitInput", buttonX, 10, "Submit", ImportRequest)
ViewMap["import"] = append(ViewMap["import"], submitInput.Name())
......
......@@ -8,17 +8,17 @@ import (
func InitMainPage(g *gocui.Gui) error {
maxX, maxY := g.Size()
if maxX < MinWidth {
maxX = MinWidth
if maxX < utils.MinWidth {
maxX = utils.MinWidth
}
if maxY < MinHeight {
maxY = MinHeight
if maxY < utils.MinHeight {
maxY = utils.MinHeight
}
quickBarView := NewPanelWidget(g, "quickBarView", 0, 0, LeftWidth, 2, "")
quickBarView := NewPanelWidget(g, "quickBarView", 0, 0, utils.LeftWidth, 2, "")
ViewMap["root"] = append(ViewMap["root"], quickBarView.Name())
sideView := NewPanelWidget(g, "side", 0, 2, LeftWidth, maxY-3, "")
sideView := NewPanelWidget(g, "side", 0, 2, utils.LeftWidth, maxY-3, "")
ViewMap["root"] = append(ViewMap["root"], sideView.Name())
x := 2
......@@ -28,12 +28,12 @@ func InitMainPage(g *gocui.Gui) error {
x += 10
}
mainView := NewPanelWidget(g, "main", LeftWidth, 0, maxX-1-LeftWidth, maxY-10, "")
mainView := NewPanelWidget(g, "main", utils.LeftWidth, 0, maxX-1-utils.LeftWidth, maxY-10, "")
ViewMap["root"] = append(ViewMap["root"], mainView.Name())
mainView.Editable = true
mainView.Wrap = true
cmdView := NewPanelWidget(g, "cmd", LeftWidth, maxY-10, maxX-1-LeftWidth, 9, "")
cmdView := NewPanelWidget(g, "cmd", utils.LeftWidth, maxY-10, maxX-1-utils.LeftWidth, 9, "")
ViewMap["root"] = append(ViewMap["root"], cmdView.Name())
cmdView.Autoscroll = true
......
......@@ -30,7 +30,7 @@ func InitSwitchPage(g *gocui.Gui) error {
return err
}
buttonX := (maxX-LeftWidth)/2 + LeftWidth - ButtonWidth
buttonX := (maxX-utils.LeftWidth)/2 + utils.LeftWidth - ButtonWidth
submitInput := NewButtonWidgetAutoWidth(g, "submitInput", buttonX, 4, "Submit", SwitchWorkDir)
ViewMap["switch"] = append(ViewMap["switch"], submitInput.Name())
......
package ui
import (
"fmt"
"github.com/easysoft/zentaoatf/src/action"
"github.com/easysoft/zentaoatf/src/script"
"github.com/easysoft/zentaoatf/src/utils"
"github.com/jroimartin/gocui"
......@@ -82,7 +84,14 @@ func showRunButton(g *gocui.Gui) error {
return nil
}
func run(g *gocui.Gui, view *gocui.View) error {
func run(g *gocui.Gui, v *gocui.View) error {
if _, err := g.SetCurrentView("main"); err != nil {
return err
}
utils.PrintToCmd(g, fmt.Sprintf("#atf run -d %s -f %s", utils.Prefer.WorkDir, CurrAsset))
utils.PrintToMain(g, "")
action.Run(utils.Prefer.WorkDir, []string{CurrAsset}, "")
return nil
}
......@@ -97,15 +106,6 @@ func loadTestAssets() ([]string, []string) {
return caseFiles, suitesFiles
}
func printSuiteInfo(g *gocui.Gui, file string) {
//str := "%s\n Work dir: %s\n Zentao project: %s\n Import type: %s\n Product code: %s\n Language: %s\n " +
// "Independent ExpectResult file: %t"
//str = fmt.Sprintf(str, name, his.ProjectPath, config.Url, config.EntityType, config.EntityVal,
// config.LangType, !config.SingleFile)
//
//utils.PrintToMain(g, str)
}
func init() {
}
......
......@@ -2,12 +2,6 @@ package ui
import "sync"
const (
LeftWidth = 36
MinWidth = 130
MinHeight = 36
)
var Tabs []string
var ViewMap map[string][]string
......
package utils
import "github.com/jroimartin/gocui"
const (
PreferenceFile = "preferences.yaml"
ConfigFile = "conf.yaml"
......@@ -14,4 +16,11 @@ const (
ZhRes = "res/messages_zh.json"
GenDir = "scripts/"
LeftWidth = 36
MinWidth = 130
MinHeight = 36
)
var RunFromCui bool
var Cui *gocui.Gui
package utils
import (
"github.com/fatih/color"
"os"
"os/exec"
"regexp"
"strconv"
"strings"
"unicode/utf8"
)
func InitScreenSize() {
......@@ -41,20 +39,6 @@ func InitScreenSize() {
Prefer.Height = height
}
func PrintWholeLine(msg string, char string, attr color.Attribute) {
prefixLen := 6
postfixLen := Prefer.Width - utf8.RuneCountInString(msg) - 6
if postfixLen < 0 { // no width in debug mode
postfixLen = 6
}
preFixStr := strings.Repeat(char, prefixLen)
postFixStr := strings.Repeat(char, postfixLen)
clr := color.New(attr)
clr.Printf("%s%s%s\n", preFixStr, msg, postFixStr)
}
func noWindowsSize() (int, int) {
cmd := exec.Command("stty", "size")
cmd.Stdin = os.Stdin
......
#-*- coding: UTF-8 -*-
#!/usr/bin/env python
'''
<<TC
caseId: 200
title: 登录失败账号锁定策略
steps: @开头的为含验证点的步骤
step2000 连续输入3次错误的密码
@step2010 第4次尝试登录
group2100 不连续输入3次错误的密码
step2101 输入2次错误的密码
step2102 输入1次正确的密码
step2103 再输入1次错误的密码
@step2104 再输入1次正确的密码
expects:
#
CODE: @step2010期望结果, 可以有多行
#
CODE: @step2104期望结果, 可以有多行
readme:
- 脚本输出日志,同expects章节中#号标注的验证点需保持一致对应
- 脚本中CODE打头的注释需用代码替换
- 参考样例https://github.com/easysoft/zentaoatf/tree/master/xdoc/sample
TC
'''
#CODE: 此处编写操作步骤代码
print("#") # @step2010: 系统提示账号被锁定
#CODE: 输出验证点实际结果
print("#") # @step2104: 登录成功,账号未被锁定
#CODE: 输出验证点实际结果
#-*- coding: UTF-8 -*-
#!/usr/bin/env python
#!/usr/bin/env python3
'''
<<TC
caseId: %d
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册