提交 bd2454cd 编写于 作者: Z zhaoke

add unit test.

上级 bb157450
......@@ -38,20 +38,20 @@ logs/
/ui/report.json
#test
/test/conf
/test/log
/test/screenshot
/test/cli/product1
test/cli/docker
/test/ui/docker
/test/ui/log
/test/demo/ci_test*
test/demo/php/conf
test/demo/php/log
test/demo/php/product1
/test/ui/allure-results
/test/cli/allure-results
test/ui/demo/ci_test_testng/
/cmd/test/conf
/cmd/test/log
/cmd/test/screenshot
/cmd/test/cli/product1
/cmd/test/cli/docker
/cmd/test/ui/docker
/cmd/test/ui/log
/cmd/test/demo/ci_test*
/cmd/test/demo/php/conf
/cmd/test/demo/php/log
/cmd/test/demo/php/product1
/cmd/test/ui/allure-results
/cmd/test/cli/allure-results
/cmd/test/ui/demo/ci_test_testng/
/demo/unit/.pytest_cache/
/demo/unit/report/
/.pytest_cache/
......@@ -71,7 +71,8 @@ node_modules
/test/restapi/allure-results/
zentaoatf.exe~
/ztf
/cmd/test/log/
cmd/test/demo/php/log/
cmd/test/demo/php/conf/
cmd/test/ui/allure-results/
test/cli/docker/
cmd/test/restapi/allure-results/
cmd/test/restapi/result.json
cmd/test/restapi/result.zip
......@@ -8,8 +8,8 @@ import (
commonTestHelper "github.com/easysoft/zentaoatf/cmd/test/helper/common"
constTestHelper "github.com/easysoft/zentaoatf/cmd/test/helper/conf"
apiTest "github.com/easysoft/zentaoatf/cmd/test/helper/zentao/api"
expect "github.com/easysoft/zentaoatf/pkg/lib/expect"
apiTest "github.com/easysoft/zentaoatf/test/helper/zentao/api"
"github.com/ozontech/allure-go/pkg/framework/provider"
"github.com/ozontech/allure-go/pkg/framework/suite"
)
......@@ -34,7 +34,7 @@ func (s *CbSuite) TestCbSuite(t provider.T) {
func testCb() string {
lastId := apiTest.GetLastBugId()
cmd := commonTestHelper.GetZtfPath() + fmt.Sprintf(" cb %stest/demo/001 -p 1", constTestHelper.RootPath)
cmd := commonTestHelper.GetZtfPath() + fmt.Sprintf(" cb %scmd/test/demo/001 -p 1", constTestHelper.RootPath)
child, err := expect.Spawn(cmd, -1)
if err != nil {
......
......@@ -16,8 +16,8 @@ import (
commonTestHelper "github.com/easysoft/zentaoatf/cmd/test/helper/common"
constTestHelper "github.com/easysoft/zentaoatf/cmd/test/helper/conf"
apiTest "github.com/easysoft/zentaoatf/cmd/test/helper/zentao/api"
expect "github.com/easysoft/zentaoatf/pkg/lib/expect"
apiTest "github.com/easysoft/zentaoatf/test/helper/zentao/api"
"github.com/ozontech/allure-go/pkg/framework/provider"
"github.com/ozontech/allure-go/pkg/framework/suite"
)
......@@ -40,7 +40,7 @@ func (s *CiSuite) TestCiSuite(t provider.T) {
}
func testCi() string {
cmd := commonTestHelper.GetZtfPath() + fmt.Sprintf(" ci %stest/demo/1_string_match_pass.php", constTestHelper.RootPath)
cmd := commonTestHelper.GetZtfPath() + fmt.Sprintf(" ci %scmd/test/demo/1_string_match_pass.php", constTestHelper.RootPath)
child, err := expect.Spawn(cmd, -1)
if err != nil {
return err.Error()
......
......@@ -8,18 +8,18 @@ import (
"time"
commonTestHelper "github.com/easysoft/zentaoatf/cmd/test/helper/common"
constTestHelper "github.com/easysoft/zentaoatf/cmd/test/helper/conf"
apiTest "github.com/easysoft/zentaoatf/cmd/test/helper/zentao/api"
dateUtils "github.com/easysoft/zentaoatf/pkg/lib/date"
expect "github.com/easysoft/zentaoatf/pkg/lib/expect"
constTestHelper "github.com/easysoft/zentaoatf/test/helper/conf"
apiTest "github.com/easysoft/zentaoatf/test/helper/zentao/api"
"github.com/ozontech/allure-go/pkg/framework/provider"
"github.com/ozontech/allure-go/pkg/framework/suite"
)
var (
successCrRe = regexp.MustCompile("Submitted test results to ZenTao|提交测试结果到禅道成功")
productIdRe = regexp.MustCompile("Zentao account|请输入 产品Id")
taskIdRe = regexp.MustCompile("Zentao account|请输入 测试任务Id")
productIdRe = regexp.MustCompile("Please enter Product Id|请输入 产品Id")
taskIdRe = regexp.MustCompile("Please enter Test Request Id|请输入 测试任务Id")
)
type CrSuite struct {
......@@ -38,7 +38,7 @@ func (s *CrSuite) TestAutoCr(t provider.T) {
caseInfo := apiTest.GetCaseResult(1)
lastId := caseInfo["Id"].(int64)
cmd := commonTestHelper.GetZtfPath() + fmt.Sprintf(" cr %stest/demo/001 -p 1 -y -t testcr", constTestHelper.RootPath)
cmd := commonTestHelper.GetZtfPath() + fmt.Sprintf(" cr %scmd/test/demo/001 -p 1 -y -t testcr", constTestHelper.RootPath)
child, err := expect.Spawn(cmd, -1)
if err != nil {
......@@ -53,7 +53,7 @@ func (s *CrSuite) TestAutoCr(t provider.T) {
//check zentao
caseInfo = apiTest.GetCaseResult(1)
resultTime := dateUtils.TimeStrToTimestamp(caseInfo["Date"].(string))
t.Require().Equal(lastId+1, caseInfo["Id"].(int64))
t.Require().GreaterOrEqual(caseInfo["Id"].(int64), lastId+1)
t.Require().Equal("fail", caseInfo["CaseResult"])
t.Require().LessOrEqual(math.Abs(float64(resultTime-time.Now().Unix())), float64(10))
}
......@@ -65,7 +65,7 @@ func (s *CrSuite) TestCr(t provider.T) {
caseInfo := apiTest.GetCaseResult(1)
lastId := caseInfo["Id"].(int64)
cmd := commonTestHelper.GetZtfPath() + fmt.Sprintf(" cr %stest/demo/001", constTestHelper.RootPath)
cmd := commonTestHelper.GetZtfPath() + fmt.Sprintf(" cr %scmd/test/demo/001", constTestHelper.RootPath)
child, err := expect.Spawn(cmd, -1)
if err != nil {
t.Require().Equal("Success", err.Error())
......
......@@ -22,9 +22,9 @@ func (s *ListSuite) BeforeEach(t provider.T) {
t.AddSubSuite("命令行-查看脚本列表")
}
func (s *ListSuite) TestListSuite(t provider.T) {
t.Require().Equal("Success", testLs(commonTestHelper.GetZtfPath()+fmt.Sprintf(" list %stest/demo", constTestHelper.RootPath), regexp.MustCompile("Found 6 test cases|发现6个用例")))
t.Require().Equal("Success", testLs(commonTestHelper.GetZtfPath()+fmt.Sprintf(" ls %stest/demo -k 1", constTestHelper.RootPath), regexp.MustCompile("Found 3 test cases|发现3个用例")))
t.Require().Equal("Success", testLs(commonTestHelper.GetZtfPath()+fmt.Sprintf(" ls %stest/demo -k match", constTestHelper.RootPath), regexp.MustCompile("Found 4 test cases|发现4个用例")))
t.Require().Equal("Success", testLs(commonTestHelper.GetZtfPath()+fmt.Sprintf(" list %scmd/test/demo", constTestHelper.RootPath), regexp.MustCompile("Found 7 test cases|发现7个用例")))
t.Require().Equal("Success", testLs(commonTestHelper.GetZtfPath()+fmt.Sprintf(" ls %scmd/test/demo -k 1", constTestHelper.RootPath), regexp.MustCompile("Found 3 test cases|发现3个用例")))
t.Require().Equal("Success", testLs(commonTestHelper.GetZtfPath()+fmt.Sprintf(" ls %scmd/test/demo -k match", constTestHelper.RootPath), regexp.MustCompile("Found 4 test cases|发现4个用例")))
}
func testLs(cmd string, successRe *regexp.Regexp) string {
......
......@@ -17,6 +17,7 @@ import (
"bufio"
"fmt"
"os"
"path/filepath"
"regexp"
"runtime"
"strings"
......@@ -38,7 +39,7 @@ func (s *RunSuite) BeforeEach(t provider.T) {
if runtime.GOOS == "windows" {
os.RemoveAll(fmt.Sprintf("%s\\test\\demo\\php\\product1", constTestHelper.RootPath))
} else {
os.RemoveAll(fmt.Sprintf("%s/test/demo/php/product1", constTestHelper.RootPath))
os.RemoveAll(fmt.Sprintf("%s/cmd/test/demo/php/product1", constTestHelper.RootPath))
}
t.AddSubSuite("命令行-run")
}
......@@ -47,17 +48,17 @@ func (s *RunSuite) TestRunZtfFile(t provider.T) {
t.ID("1584")
t.Title("执行多个文件和目录中的脚本")
cmd := commonTestHelper.GetZtfPath() + fmt.Sprintf(" run %s/test/demo/1_string_match_pass.php", constTestHelper.RootPath)
cmd := commonTestHelper.GetZtfPath() + fmt.Sprintf(" run %s/cmd/test/demo/1_string_match_pass.php", constTestHelper.RootPath)
expectReg := regexp.MustCompile(`Pass:1\(100\.0%\), Fail:0\(0\.0%\), Skip:0\(0\.0%\)|通过数:1\(100\.0%\),失败数:0\(0\.0%\),忽略数:0\(0\.0%\)`)
t.Require().Equal("Success", testRun(cmd, expectReg))
cmd = commonTestHelper.GetZtfPath() + fmt.Sprintf(" run %stest/demo/1_string_match_pass.php %stest/demo/2_webpage_extract.php", constTestHelper.RootPath, constTestHelper.RootPath)
cmd = commonTestHelper.GetZtfPath() + fmt.Sprintf(" run %scmd/test/demo/1_string_match_pass.php %scmd/test/demo/2_webpage_extract.php", constTestHelper.RootPath, constTestHelper.RootPath)
expectReg = regexp.MustCompile(`Pass:2\(100\.0%\), Fail:0\(0\.0%\), Skip:0\(0\.0%\)|通过数:2\(100\.0%\),失败数:0\(0\.0%\),忽略数:0\(0\.0%\)`)
t.Require().Equal("Success", testRun(cmd, expectReg))
cmd = commonTestHelper.GetZtfPath() + fmt.Sprintf(" run %stest/demo", constTestHelper.RootPath)
cmd = commonTestHelper.GetZtfPath() + fmt.Sprintf(" run %scmd/test/demo", constTestHelper.RootPath)
if runtime.GOOS == "windows" {
cmd = strings.ReplaceAll(cmd, "/", "\\")
}
......@@ -70,7 +71,7 @@ func (s *RunSuite) TestRunExpectFile(t provider.T) {
t.ID("7561")
t.Title("执行期待结果独立文件的用例")
cmd := commonTestHelper.GetZtfPath() + fmt.Sprintf(" run %s/test/demo/expect.php", constTestHelper.RootPath)
cmd := commonTestHelper.GetZtfPath() + fmt.Sprintf(" run %s/cmd/test/demo/expect.php", constTestHelper.RootPath)
expectReg := regexp.MustCompile(`Pass:1\(100\.0%\), Fail:0\(0\.0%\), Skip:0\(0\.0%\)|通过数:1\(100\.0%\),失败数:0\(0\.0%\),忽略数:0\(0\.0%\)`)
t.Require().Equal("Success", testRun(cmd, expectReg))
......@@ -80,7 +81,7 @@ func (s *RunSuite) TestRunFileAndSubmit(t provider.T) {
t.ID("7552")
t.Title("执行后自动提交结果")
cmd := commonTestHelper.GetZtfPath() + fmt.Sprintf(" run %s/test/demo/1_string_match_pass.php -p 1 -cr", constTestHelper.RootPath)
cmd := commonTestHelper.GetZtfPath() + fmt.Sprintf(" run %s/cmd/test/demo/1_string_match_pass.php -p 1 -cr", constTestHelper.RootPath)
expectReg := regexp.MustCompile(`Submitted test results to ZenTao|提交测试结果到禅道成功`)
t.Require().Equal("Success", testRun(cmd, expectReg))
......@@ -90,8 +91,9 @@ func (s *RunSuite) TestRunFileAndSubmitBug(t provider.T) {
t.ID("7553")
t.Title("执行后自动提交缺陷")
cmd := commonTestHelper.GetZtfPath() + fmt.Sprintf(" run %s/test/demo/1_string_match_fail.php -p 1 -cb", constTestHelper.RootPath)
expectReg := regexp.MustCompile(`Success to report bug for case \\d+|成功为用例\d+提交缺陷`)
scriptPath := filepath.Join(constTestHelper.RootPath, "cmd", "test", "demo", "1_string_match_fail.php")
cmd := commonTestHelper.GetZtfPath() + fmt.Sprintf(" run %s -p 1 -cb", scriptPath)
expectReg := regexp.MustCompile(`Success to report bug for case \d+|成功为用例\d+提交缺陷`)
t.Require().Equal("Success", testRun(cmd, expectReg))
}
......@@ -100,7 +102,7 @@ func (s *RunSuite) TestRunZtfTask(t provider.T) {
t.ID("1589")
t.Title("执行禅道测试任务")
cmd := commonTestHelper.GetZtfPath() + fmt.Sprintf(" run %stest/demo -task 1", constTestHelper.RootPath)
cmd := commonTestHelper.GetZtfPath() + fmt.Sprintf(" run %scmd/test/demo -task 1", constTestHelper.RootPath)
expectReg := regexp.MustCompile(`Pass:0\(0\.0%\), Fail:3\(100\.0%\), Skip:0\(0\.0%\)|通过数:0\(0\.0%\),失败数:3\(100\.0%\),忽略数:0\(0\.0%\)`)
t.Require().Equal("Success", testRun(cmd, expectReg))
......@@ -110,7 +112,7 @@ func (s *RunSuite) TestRunZtfSuite(t provider.T) {
t.ID("1588")
t.Title("执行禅道测试套件")
cmd := commonTestHelper.GetZtfPath() + fmt.Sprintf(" run %stest%sdemo -suite 1", constTestHelper.RootPath, constTestHelper.FilePthSep)
cmd := commonTestHelper.GetZtfPath() + fmt.Sprintf(" run %scmd%stest%sdemo -suite 1", constTestHelper.RootPath, constTestHelper.FilePthSep, constTestHelper.FilePthSep)
expectReg := regexp.MustCompile(`Pass:0\(0\.0%\), Fail:1\(100\.0%\), Skip:0\(0\.0%\)|通过数:0\(0\.0%\),失败数:1\(100\.0%\),忽略数:0\(0\.0%\)`)
t.Require().Equal("Success", testRun(cmd, expectReg))
......@@ -120,7 +122,7 @@ func (s *RunSuite) TestRunZtfCsFile(t provider.T) {
t.ID("1586")
t.Title("执行本地套件文件中指定编号的脚本")
cmd := commonTestHelper.GetZtfPath() + fmt.Sprintf(" run %stest/demo %stest/demo/all.cs", constTestHelper.RootPath, constTestHelper.RootPath)
cmd := commonTestHelper.GetZtfPath() + fmt.Sprintf(" run %scmd/test/demo %scmd/test/demo/all.cs", constTestHelper.RootPath, constTestHelper.RootPath)
expectReg := regexp.MustCompile(`Pass:0\(0\.0%\), Fail:2\(100\.0%\), Skip:0\(0\.0%\)|通过数:0\(0\.0%\),失败数:2\(100\.0%\),忽略数:0\(0\.0%\)`)
t.Require().Equal("Success", testRun(cmd, expectReg))
......@@ -172,10 +174,7 @@ func (s *RunSuite) TestRunScenes(t provider.T) {
print("%s\n");`
path := "../../demo/test_scene.php"
if runtime.GOOS == "windows" {
path = `..\..\demo\test_scene.php`
}
path := filepath.Join(constTestHelper.RootPath, "cmd", "test", "demo", "test_scene.php")
cmd := commonTestHelper.GetZtfPath() + ` run ` + path
for expectVal, actualVal := range sceneMap {
......
......@@ -29,13 +29,13 @@ func (s *RunUnitSuit) BeforeEach(t provider.T) {
if runtime.GOOS == "windows" {
os.RemoveAll(fmt.Sprintf("%s\\test\\demo\\php\\product1", constTestHelper.RootPath))
} else {
os.RemoveAll(fmt.Sprintf("%s/test/demo/php/product1", constTestHelper.RootPath))
os.RemoveAll(fmt.Sprintf("%s/cmd/test/demo/php/product1", constTestHelper.RootPath))
}
t.AddSubSuite("命令行-run")
}
func (s *RunUnitSuit) TestRunTestng(t provider.T) {
testngDir := fmt.Sprintf("%stest/demo/ci_test_testng", constTestHelper.RootPath)
testngDir := fmt.Sprintf("%scmd/test/demo/ci_test_testng", constTestHelper.RootPath)
t.ID("5432")
t.Title("执行TestNG单元测试")
cloneGit("https://gitee.com/ngtesting/ci_test_testng.git", testngDir)
......@@ -43,7 +43,7 @@ func (s *RunUnitSuit) TestRunTestng(t provider.T) {
}
func (s *RunUnitSuit) TestRunPytest(t provider.T) {
pytestDir := fmt.Sprintf(".%stest/demo/ci_test_pytest", constTestHelper.RootPath)
pytestDir := fmt.Sprintf(".%scmd/test/demo/ci_test_pytest", constTestHelper.RootPath)
t.ID("5435")
t.Title("执行PyTest单元测试")
cloneGit("https://gitee.com/ngtesting/ci_test_pytest.git", pytestDir)
......
......@@ -7,6 +7,7 @@ import (
"fmt"
"regexp"
"runtime"
"strings"
"testing"
"time"
......@@ -36,7 +37,7 @@ var (
"tcl": "",
"go": "",
}
langArray = []string{"php", "javascript", "lua", "perl", "python", "ruby", "tcl", "go"}
langArray = []string{"go", "php", "ruby", "javascript", "lua", "perl", "python", "tcl"}
)
type SetSuite struct {
......@@ -107,11 +108,17 @@ func testSet(language string) (ret string) {
}
for _, lang := range langArray {
if _, err = child.Expect(regexp.MustCompile(lang), time.Second*5); err != nil {
out, err := child.Expect(regexp.MustCompile("Please set script|请设置"), time.Second*5)
if err != nil {
return fmt.Sprintf("expect %s, actual %s", lang, err.Error())
}
if err = child.Send(langMap[lang] + constTestHelper.NewLine); err != nil {
sendMsg := ""
if strings.Contains(out, "php") {
sendMsg = "D:\\Program Files\\phpstudy_pro\\Extensions\\php\\php7.4.3nts\\php.exe"
}
if err = child.Send(sendMsg + constTestHelper.NewLine); err != nil {
return err.Error()
}
}
......
......@@ -22,11 +22,11 @@ func (s *ViewSuite) BeforeEach(t provider.T) {
t.AddSubSuite("命令行-查看脚本详情")
}
func (s *ViewSuite) TestViewSuite(t provider.T) {
t.Require().Equal("Success", testView(commonTestHelper.GetZtfPath()+fmt.Sprintf(" view %stest/demo/1_string_match_fail.php", constTestHelper.RootPath), regexp.MustCompile("check string matches pattern")))
t.Require().Equal("Success", testView(commonTestHelper.GetZtfPath()+fmt.Sprintf(" view %scmd/test/demo/1_string_match_fail.php", constTestHelper.RootPath), regexp.MustCompile("check string matches pattern")))
t.Require().Equal("Success", testView(commonTestHelper.GetZtfPath()+fmt.Sprintf(" -v %stest/demo -k 1", constTestHelper.RootPath), regexp.MustCompile("check string matches pattern")))
t.Require().Equal("Success", testView(commonTestHelper.GetZtfPath()+fmt.Sprintf(" -v %scmd/test/demo -k 1", constTestHelper.RootPath), regexp.MustCompile("check string matches pattern")))
t.Require().Equal("Success", testView(commonTestHelper.GetZtfPath()+fmt.Sprintf(" view %stest/demo -k match", constTestHelper.RootPath), regexp.MustCompile("Found 5 test cases|发现5个用例")))
t.Require().Equal("Success", testView(commonTestHelper.GetZtfPath()+fmt.Sprintf(" view %scmd/test/demo -k match", constTestHelper.RootPath), regexp.MustCompile("Found 5 test cases|发现5个用例")))
}
func testView(cmd string, successRe *regexp.Regexp) string {
......
......@@ -46,6 +46,7 @@ func main() {
serverConfig.InitLog()
serverConfig.InitExecLog(constTestHelper.RootPath)
commConsts.ZtfDir = constTestHelper.RootPath
i118Utils.Init("zh-CN", commConsts.AppServer)
if runFrom == "jenkins" {
......
......@@ -19,9 +19,9 @@ import (
)
func TestCli() (err error) {
testPath := fmt.Sprintf(`%stest`, constTestHelper.RootPath)
testPath := fmt.Sprintf(`%scmd/test`, constTestHelper.RootPath)
if runtime.GOOS == "windows" {
testPath = fmt.Sprintf(`%stest`, constTestHelper.RootPath)
testPath = fmt.Sprintf(`%scmd\test`, constTestHelper.RootPath)
}
req := serverDomain.TestSet{
WorkspacePath: testPath,
......@@ -43,13 +43,11 @@ func TestCli() (err error) {
}
func TestUi() (err error) {
var screenshotPath = fmt.Sprintf("%stest/screenshot", constTestHelper.RootPath)
var screenshotPath = fmt.Sprintf("%scmd/test/screenshot", constTestHelper.RootPath)
os.RemoveAll(screenshotPath)
fileUtils.MkDirIfNeeded(screenshotPath)
testPath := fmt.Sprintf(`%stest`, constTestHelper.RootPath)
if runtime.GOOS == "windows" {
testPath = fmt.Sprintf(`%stest`, constTestHelper.RootPath)
}
testPath := filepath.Join(constTestHelper.RootPath, "cmd", "test")
req := serverDomain.TestSet{
WorkspacePath: testPath,
Cmd: "go test ./ui -v -timeout 10m",
......
......@@ -6,6 +6,7 @@ import (
"io"
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"
......@@ -102,11 +103,11 @@ func GetZtfPath() string {
}
func GetZtfProductPath() string {
return fmt.Sprintf("%s%s%s%s%s%s%s%s", constTestHelper.RootPath, "test", constTestHelper.FilePthSep, "demo", constTestHelper.FilePthSep, "php", constTestHelper.FilePthSep, "product1")
return filepath.Join(constTestHelper.RootPath, "cmd", "test", "demo", "php", "product1")
}
func GetPhpWorkspacePath() string {
return fmt.Sprintf("%s%s%s%s%s%s%s", constTestHelper.RootPath, "test", constTestHelper.FilePthSep, "demo", constTestHelper.FilePthSep, "php", constTestHelper.FilePthSep)
return filepath.Join(constTestHelper.RootPath, "cmd", "test", "demo", "php")
}
func WaitZtfAccessed() {
......
......@@ -35,7 +35,7 @@ func init() {
}
RootPath, _ = os.Getwd()
if strings.Index(RootPath, "test") != -1 {
RootPath = RootPath[:strings.Index(RootPath, "test")]
RootPath = RootPath[:strings.Index(RootPath, "test")-4]
}
if RootPath[len(RootPath)-1:] != FilePthSep {
RootPath += FilePthSep
......
......@@ -3,10 +3,10 @@ package apiTest
import (
"fmt"
constTestHelper "github.com/easysoft/zentaoatf/cmd/test/helper/conf"
httpHelper "github.com/easysoft/zentaoatf/cmd/test/helper/http"
"github.com/easysoft/zentaoatf/cmd/test/restapi/config"
zentaoHelper "github.com/easysoft/zentaoatf/internal/pkg/helper/zentao"
constTestHelper "github.com/easysoft/zentaoatf/test/helper/conf"
httpHelper "github.com/easysoft/zentaoatf/test/helper/http"
"github.com/easysoft/zentaoatf/test/restapi/config"
"github.com/tidwall/gjson"
)
......
......@@ -15,7 +15,7 @@ var AddSiteTimes = 0
func CreateTestWorkspace(webpage plwHelper.Webpage, name, workspacePath string) {
if workspacePath == "" {
workspacePath = fmt.Sprintf("%stest%sdemo%sphp", constTestHelper.RootPath, constTestHelper.FilePthSep, constTestHelper.FilePthSep)
workspacePath = fmt.Sprintf("%scmd%stest%sdemo%sphp", constTestHelper.RootPath, constTestHelper.FilePthSep, constTestHelper.FilePthSep, constTestHelper.FilePthSep)
}
webpage.Click(`[title="新建工作目录"]`)
......@@ -102,6 +102,9 @@ func CreateSite(webpage plwHelper.Webpage) {
}
func ExpandWorspace(webpage plwHelper.Webpage) (err error) {
plwConf.DisableErr()
defer plwConf.EnableErr()
if !webpage.ElementExist(fmt.Sprintf(".tree-node-title:has-text('%s')", constTestHelper.WorkspaceName)) {
CreateTestWorkspace(webpage, constTestHelper.WorkspaceName, "")
}
......@@ -113,8 +116,8 @@ func ExpandWorspace(webpage plwHelper.Webpage) (err error) {
}
webpage.Click(fmt.Sprintf(".tree-node-title:has-text(\"%s\")", constTestHelper.WorkspaceName))
err = webpage.WaitForSelectorTimeout(".tree-node-item>>div:has-text('1_string_match.php')", 3000)
if err != nil {
if webpage.ElementExist(".tree-node-item>>text=1_string_match.php") {
if expandTimes > 3 {
expandTimes = 0
return err
......@@ -129,9 +132,16 @@ func ExpandWorspace(webpage plwHelper.Webpage) (err error) {
func ExpandProduct(webpage plwHelper.Webpage) (err error) {
plwConf.DisableErr()
defer plwConf.EnableErr()
ExpandWorspace(webpage)
var waitTimeOut float64 = 5000
webpage.WaitForSelector(".tree-node-item:has-text('product1')", playwright.PageWaitForSelectorOptions{Timeout: &waitTimeOut})
if !webpage.ElementExist(".tree-node-root .tree-node:has-text('product1')") {
webpage.WaitForTimeout(100)
expandTimes++
ExpandProduct(webpage)
return
}
selector := webpage.QuerySelectorAll(".tree-node-root .tree-node:has-text('product1')")
className := selector.GetAttribute(0, "class")
if className != "" && !strings.Contains(className, "collapsed") {
......
......@@ -2,6 +2,8 @@ package main
import (
"fmt"
"testing"
constTestHelper "github.com/easysoft/zentaoatf/cmd/test/helper/conf"
httpHelper "github.com/easysoft/zentaoatf/cmd/test/helper/http"
"github.com/easysoft/zentaoatf/cmd/test/restapi/config"
......@@ -12,7 +14,6 @@ import (
"github.com/ozontech/allure-go/pkg/framework/provider"
"github.com/ozontech/allure-go/pkg/framework/suite"
"github.com/tidwall/gjson"
"testing"
)
func TestCaseApi(t *testing.T) {
......@@ -40,7 +41,7 @@ func (s *CaseApiSuite) TestCaseListApi(t provider.T) {
firstCaseId := gjson.Get(string(bodyBytes), "testcases.0.id").Int()
t.Require().Greater(firstCaseId, int64(0), "list testcases failed")
t.Require().Greater(firstCaseId, int64(0), "list testcases failed, url: "+url)
}
func (s *CaseApiSuite) TestCaseListByModuleApi(t provider.T) {
......@@ -56,7 +57,7 @@ func (s *CaseApiSuite) TestCaseListByModuleApi(t provider.T) {
firstCaseId := gjson.Get(string(bodyBytes), "testcases.0.id").Int()
t.Require().Greater(firstCaseId, int64(0), "list testcases failed")
t.Require().Greater(firstCaseId, int64(0), "list testcases failed, url: "+url)
}
func (s *CaseApiSuite) TestCaseListBySuiteApi(t provider.T) {
......@@ -69,7 +70,7 @@ func (s *CaseApiSuite) TestCaseListBySuiteApi(t provider.T) {
firstCaseId := gjson.Get(string(bodyBytes), "testcases.0.id").Int()
t.Require().Greater(firstCaseId, int64(0), "list testcases failed")
t.Require().Greater(firstCaseId, int64(0), "list testcases failed, url: "+url)
}
func (s *CaseApiSuite) TestCaseListByTaskApi(t provider.T) {
......@@ -82,7 +83,7 @@ func (s *CaseApiSuite) TestCaseListByTaskApi(t provider.T) {
firstCaseId := gjson.Get(string(bodyBytes), "testcases.0.id").Int()
t.Require().Greater(firstCaseId, int64(0), "list testcases failed")
t.Require().Greater(firstCaseId, int64(0), "list testcases failed, url: "+url)
}
func (s *CaseApiSuite) TestCaseDetailApi(t provider.T) {
......@@ -95,7 +96,7 @@ func (s *CaseApiSuite) TestCaseDetailApi(t provider.T) {
title := gjson.Get(string(bodyBytes), "title").String()
t.Require().Greater(len(title), 0, "get testcases failed")
t.Require().Greater(len(title), 0, "get testcases failed, url: "+url)
}
func (s *CaseApiSuite) TestCaseCheckinApi(t provider.T) {
......@@ -124,11 +125,11 @@ func (s *CaseApiSuite) TestCaseCheckinApi(t provider.T) {
bodyBytes, _ := httpHelper.Put(url, token, requestObj)
actualTitle := gjson.Get(string(bodyBytes), "title").String()
t.Require().Equal(actualTitle, title, "checkin testcases failed")
t.Require().Equal(actualTitle, title, "checkin testcases failed, url: "+url)
newCase := getCase(config.CaseId)
titleFromRemote := newCase["title"]
t.Require().Equal(titleFromRemote, title, "get testcases failed")
t.Require().Equal(titleFromRemote, title, "get testcases failed, url: "+url)
}
func getCase(id int) (cs map[string]interface{}) {
......
......@@ -240,7 +240,7 @@ func (p *Webpage) ScreenShot() {
if !conf.ShowErr && !conf.ExitAllOnError {
return
}
var screenshotPath = fmt.Sprintf("%stest/screenshot/%v.png", constTestHelper.RootPath, time.Now().Unix())
var screenshotPath = fmt.Sprintf("%scmd/test/screenshot/%v.png", constTestHelper.RootPath, time.Now().Unix())
p.Page.Screenshot(playwright.PageScreenshotOptions{Path: &screenshotPath})
}
......
......@@ -180,7 +180,7 @@ func (l *MyLocator) ScreenShot() {
if !conf.ShowErr && !conf.ExitAllOnError {
return
}
var screenshotPath = fmt.Sprintf("%stest/screenshot/%v.png", constTestHelper.RootPath, time.Now().Unix())
var screenshotPath = fmt.Sprintf("%scmd/test/screenshot/%v.png", constTestHelper.RootPath, time.Now().Unix())
l.Page.Screenshot(playwright.PageScreenshotOptions{Path: &screenshotPath})
}
......
......@@ -10,6 +10,7 @@ import (
commonTestHelper "github.com/easysoft/zentaoatf/cmd/test/helper/common"
constTestHelper "github.com/easysoft/zentaoatf/cmd/test/helper/conf"
uiTest "github.com/easysoft/zentaoatf/cmd/test/helper/zentao/ui"
commandConfig "github.com/easysoft/zentaoatf/internal/command/config"
commConsts "github.com/easysoft/zentaoatf/internal/pkg/consts"
execHelper "github.com/easysoft/zentaoatf/internal/pkg/helper/exec"
serverConfig "github.com/easysoft/zentaoatf/internal/server/config"
......@@ -45,7 +46,7 @@ func main() {
commConsts.ExecFrom = commConsts.FromCmd
commConsts.ZtfDir = constTestHelper.RootPath
serverConfig.InitLog()
commandConfig.InitLog()
serverConfig.InitExecLog(constTestHelper.RootPath)
i118Utils.Init("zh-CN", commConsts.AppServer)
......@@ -62,16 +63,19 @@ func main() {
fmt.Println("Init zentao data fail ", err)
}
fmt.Println("build cli")
err = commonTestHelper.BuildCli()
if err != nil {
fmt.Println("Build cli fail ", err)
}
fmt.Println("run server")
err = commonTestHelper.RunServer()
if err != nil {
fmt.Println("Build server fail ")
}
fmt.Println("run ui")
err = commonTestHelper.RunUi()
if err != nil {
fmt.Println("Build server fail ")
......
......@@ -7,11 +7,11 @@ import (
"time"
constTestHelper "github.com/easysoft/zentaoatf/cmd/test/helper/conf"
apiTest "github.com/easysoft/zentaoatf/cmd/test/helper/zentao/api"
ztfTest "github.com/easysoft/zentaoatf/cmd/test/helper/ztf"
ztfTestHelper "github.com/easysoft/zentaoatf/cmd/test/helper/ztf"
plwHelper "github.com/easysoft/zentaoatf/cmd/test/ui/helper"
dateUtils "github.com/easysoft/zentaoatf/pkg/lib/date"
apiTest "github.com/easysoft/zentaoatf/test/helper/zentao/api"
"github.com/ozontech/allure-go/pkg/framework/provider"
"github.com/ozontech/allure-go/pkg/framework/runner"
playwright "github.com/playwright-community/playwright-go"
......
package main
import (
"os"
"runtime"
"path/filepath"
"strings"
"testing"
......@@ -12,6 +11,7 @@ import (
ztfTestHelper "github.com/easysoft/zentaoatf/cmd/test/helper/ztf"
plwConf "github.com/easysoft/zentaoatf/cmd/test/ui/conf"
plwHelper "github.com/easysoft/zentaoatf/cmd/test/ui/helper"
commandConfig "github.com/easysoft/zentaoatf/internal/command/config"
shellUtils "github.com/easysoft/zentaoatf/pkg/lib/shell"
"github.com/ozontech/allure-go/pkg/framework/provider"
"github.com/ozontech/allure-go/pkg/framework/runner"
......@@ -37,11 +37,9 @@ func createUnitWorkspace(t provider.T, workspaceName, workspacePath, unitType st
}
func RunTestNG(t provider.T) {
var pwd, _ = os.Getwd()
testngDir := pwd + "/demo/ci_test_testng"
if runtime.GOOS == "windows" {
testngDir = pwd + "\\demo\\ci_test_testng"
}
commandConfig.InitLog()
testngDir := filepath.Join(constTestHelper.RootPath, "cmd", "test", "demo", "ci_test_testng")
workspaceName := "testng工作目录"
commonTestHelper.CloneGit("https://gitee.com/ngtesting/ci_test_testng.git", testngDir)
......
......@@ -22,8 +22,10 @@ func FilterDir(t provider.T) {
webpage.Click(`[title="筛选"]`)
webpage.WaitForSelector("#filterModal")
webpage.WaitForTimeout(1000)
webpage.Click(fmt.Sprintf("#filterModal>>.list-item-title:has-text(\"%s\")", constTestHelper.WorkspaceName))
webpage.WaitForSelector("#leftPane>>.tree>>.tree-node")
eleArr := webpage.QuerySelectorAll("#leftPane>>.tree>>.tree-node")
if len(eleArr.ElementHandles) < 1 {
t.Errorf("Filter valid fail")
......
......@@ -8,19 +8,23 @@ import (
"testing"
commonTestHelper "github.com/easysoft/zentaoatf/cmd/test/helper/common"
constTestHelper "github.com/easysoft/zentaoatf/cmd/test/helper/conf"
apiTest "github.com/easysoft/zentaoatf/cmd/test/helper/zentao/api"
ztfTestHelper "github.com/easysoft/zentaoatf/cmd/test/helper/ztf"
plwConf "github.com/easysoft/zentaoatf/cmd/test/ui/conf"
plwHelper "github.com/easysoft/zentaoatf/cmd/test/ui/helper"
fileUtils "github.com/easysoft/zentaoatf/pkg/lib/file"
constTestHelper "github.com/easysoft/zentaoatf/test/helper/conf"
apiTest "github.com/easysoft/zentaoatf/test/helper/zentao/api"
ztfTestHelper "github.com/easysoft/zentaoatf/test/helper/ztf"
plwHelper "github.com/easysoft/zentaoatf/test/ui/helper"
"github.com/ozontech/allure-go/pkg/framework/provider"
"github.com/ozontech/allure-go/pkg/framework/runner"
playwright "github.com/playwright-community/playwright-go"
)
var (
workspacePath = fmt.Sprintf("%stest%sdemo%sphp", constTestHelper.RootPath, constTestHelper.FilePthSep, constTestHelper.FilePthSep)
workspacePath = fileUtils.AddFilePathSepIfNeeded(commonTestHelper.GetPhpWorkspacePath())
syncDir = filepath.Join(workspacePath, "product1")
oldDirPath = workspacePath + "oldDir"
newDirPath = filepath.Join(workspacePath, "product1", "oldDir")
)
func CreateWorkspace(t provider.T) {
......@@ -55,7 +59,6 @@ func SyncFromZentao(t provider.T) {
syncAllCaseFromZentao(t)
}
func syncAllCaseFromZentao(t provider.T) {
syncDir := filepath.Join(workspacePath, "product1")
os.RemoveAll(syncDir)
webpage, _ := plwHelper.OpenUrl(constTestHelper.ZtfUrl, t)
......@@ -79,20 +82,19 @@ func syncAllCaseFromZentao(t provider.T) {
//check file info
scriptPath := filepath.Join(workspacePath, "product1", "2.php")
content := fileUtils.ReadFile(scriptPath)
t.Require().Contains(content, "extract content from webpage-synctozentao")
t.Require().Contains(content, "extract content from webpage")
}
func syncCaseFromZentaoTask(t provider.T) {
webpage, _ := plwHelper.OpenUrl(constTestHelper.ZtfUrl, t)
defer webpage.Close()
syncDir := filepath.Join(workspacePath, "product1")
os.RemoveAll(syncDir)
ztfTestHelper.SelectSite(webpage)
webpage.WaitForSelector(".tree-node", playwright.PageWaitForSelectorOptions{Timeout: &plwConf.Timeout})
locator := webpage.Locator(".tree-node", playwright.PageLocatorOptions{HasText: constTestHelper.WorkspaceName})
locator := webpage.Locator(".tree-node-title", playwright.PageLocatorOptions{HasText: constTestHelper.WorkspaceName})
locator.RightClick()
webpage.Click(".tree-context-menu>>text=从禅道同步")
......@@ -118,13 +120,12 @@ func syncCaseFromZentaoModule(t provider.T) {
webpage, _ := plwHelper.OpenUrl(constTestHelper.ZtfUrl, t)
defer webpage.Close()
syncDir := filepath.Join(workspacePath, "product1")
os.RemoveAll(syncDir)
ztfTestHelper.SelectSite(webpage)
webpage.WaitForSelector(".tree-node", playwright.PageWaitForSelectorOptions{Timeout: &plwConf.Timeout})
locator := webpage.Locator(".tree-node", playwright.PageLocatorOptions{HasText: constTestHelper.WorkspaceName})
locator := webpage.Locator(".tree-node-title", playwright.PageLocatorOptions{HasText: constTestHelper.WorkspaceName})
locator.RightClick()
webpage.Click(".tree-context-menu>>text=从禅道同步")
......@@ -150,13 +151,12 @@ func syncCaseFromZentaoSuite(t provider.T) {
webpage, _ := plwHelper.OpenUrl(constTestHelper.ZtfUrl, t)
defer webpage.Close()
syncDir := filepath.Join(workspacePath, "product1")
os.RemoveAll(syncDir)
ztfTestHelper.SelectSite(webpage)
webpage.WaitForSelector(".tree-node", playwright.PageWaitForSelectorOptions{Timeout: &plwConf.Timeout})
locator := webpage.Locator(".tree-node", playwright.PageLocatorOptions{HasText: constTestHelper.WorkspaceName})
locator := webpage.Locator(".tree-node-title", playwright.PageLocatorOptions{HasText: constTestHelper.WorkspaceName})
locator.RightClick()
webpage.Click(".tree-context-menu>>text=从禅道同步")
......@@ -184,13 +184,12 @@ func SyncTwoCaseFromZentao(t provider.T) {
webpage, _ := plwHelper.OpenUrl(constTestHelper.ZtfUrl, t)
defer webpage.Close()
syncDir := filepath.Join(workspacePath, "product1")
os.RemoveAll(syncDir)
ztfTestHelper.SelectSite(webpage)
webpage.WaitForSelector(".tree-node", playwright.PageWaitForSelectorOptions{Timeout: &plwConf.Timeout})
locator := webpage.Locator(".tree-node", playwright.PageLocatorOptions{HasText: constTestHelper.WorkspaceName})
locator := webpage.Locator(".tree-node-title", playwright.PageLocatorOptions{HasText: constTestHelper.WorkspaceName})
locator.RightClick()
webpage.Click(".tree-context-menu>>text=从禅道同步")
......@@ -225,9 +224,9 @@ func SyncToZentao(t provider.T) {
defer webpage.Close()
ztfTestHelper.SelectSite(webpage)
ztfTestHelper.ExpandWorspace(webpage)
webpage.WaitForSelector(".tree-node", playwright.PageWaitForSelectorOptions{Timeout: &plwConf.Timeout})
locator := webpage.Locator(".tree-node", playwright.PageLocatorOptions{HasText: constTestHelper.WorkspaceName})
locator := webpage.Locator(".tree-node-title", playwright.PageLocatorOptions{HasText: constTestHelper.WorkspaceName})
locator.RightClick()
webpage.Click(".tree-context-menu>>text=同步到禅道")
......@@ -244,6 +243,9 @@ func Copy(t provider.T) {
t.ID("5474")
t.AddParentSuite("管理禅道站点下工作目录")
fileUtils.MkDirIfNeeded(syncDir)
defer os.RemoveAll(syncDir)
webpage, _ := plwHelper.OpenUrl(constTestHelper.ZtfUrl, t)
defer webpage.Close()
......@@ -279,14 +281,26 @@ func CopyDir(t provider.T) {
t.ID("7593")
t.AddParentSuite("管理禅道站点下工作目录")
fileUtils.MkDirIfNeeded(syncDir)
defer os.RemoveAll(syncDir)
if !fileUtils.FileExist(oldDirPath) {
fileUtils.MkDirIfNeeded(oldDirPath)
}
if fileUtils.FileExist(newDirPath) {
os.RemoveAll(newDirPath)
}
defer os.Remove(oldDirPath)
defer os.Remove(newDirPath)
webpage, _ := plwHelper.OpenUrl(constTestHelper.ZtfUrl, t)
defer webpage.Close()
ztfTestHelper.SelectSite(webpage)
ztfTestHelper.ExpandWorspace(webpage)
ztfTestHelper.ExpandProduct(webpage)
CreateDir(t)
scriptLocator := webpage.Locator(fmt.Sprintf(".tree-node:has-text('%s')>>.tree-node-title>>text=oldDir", constTestHelper.WorkspaceName))
scriptLocator := webpage.Locator(".tree-node-title>>text=oldDir")
scriptLocator.RightClick()
webpage.Click(".tree-context-menu>>text=复制")
......@@ -299,21 +313,27 @@ func CopyDir(t provider.T) {
t.FailNow()
return
}
os.Remove(commonTestHelper.GetPhpWorkspacePath() + "oldDir")
os.Remove(filepath.Join(commonTestHelper.GetPhpWorkspacePath(), "product1", "oldDir"))
}
func ClipDir(t provider.T) {
t.ID("7593")
t.AddParentSuite("管理禅道站点下工作目录")
fileUtils.MkDirIfNeeded(syncDir)
defer os.RemoveAll(syncDir)
if !fileUtils.FileExist(oldDirPath) {
fileUtils.MkDirIfNeeded(oldDirPath)
}
if fileUtils.FileExist(newDirPath) {
os.RemoveAll(newDirPath)
}
webpage, _ := plwHelper.OpenUrl(constTestHelper.ZtfUrl, t)
defer webpage.Close()
ztfTestHelper.SelectSite(webpage)
ztfTestHelper.ExpandWorspace(webpage)
ztfTestHelper.ExpandProduct(webpage)
CreateDir(t)
scriptLocator := webpage.Locator(fmt.Sprintf(".tree-node:has-text('%s')>>.tree-node-title>>text=oldDir", constTestHelper.WorkspaceName))
scriptLocator.RightClick()
......@@ -329,8 +349,8 @@ func ClipDir(t provider.T) {
return
}
os.Remove(commonTestHelper.GetPhpWorkspacePath() + "oldDir")
os.Remove(filepath.Join(commonTestHelper.GetPhpWorkspacePath(), "product1", "oldDir"))
os.Remove(oldDirPath)
os.Remove(newDirPath)
}
func CreateScript(t provider.T) {
......@@ -360,10 +380,19 @@ func RenameScript(t provider.T) {
t.ID("7596")
t.AddParentSuite("管理禅道站点下工作目录")
fileUtils.MkDirIfNeeded(syncDir)
webpage, _ := plwHelper.OpenUrl(constTestHelper.ZtfUrl, t)
defer webpage.Close()
defer func() {
webpage.Close()
os.RemoveAll(syncDir)
os.Remove(workspacePath + "old.php")
os.Remove(workspacePath + "new.php")
}()
ztfTestHelper.SelectSite(webpage)
ztfTestHelper.ExpandWorspace(webpage)
ztfTestHelper.ExpandProduct(webpage)
CreateScript(t)
......@@ -376,9 +405,6 @@ func RenameScript(t provider.T) {
webpage.Click("#scriptFormModal>>.modal-action>>span:has-text(\"确定\")")
scriptLocator = webpage.Locator(fmt.Sprintf(".tree-node:has-text('%s')>>.tree-node-title>>text=new.php", constTestHelper.WorkspaceName))
os.Remove(commonTestHelper.GetPhpWorkspacePath() + "old.php")
os.Remove(commonTestHelper.GetPhpWorkspacePath() + "new.php")
}
func CreateDir(t provider.T) {
......@@ -390,7 +416,7 @@ func CreateDir(t provider.T) {
ztfTestHelper.SelectSite(webpage)
ztfTestHelper.ExpandProduct(webpage)
if webpage.ElementExist(fmt.Sprintf(".tree-node:has-text('%s')>>.tree-node-title>>text=oldDir", constTestHelper.WorkspaceName)) {
if webpage.ElementExist(".tree-node-title>>text=oldDir") {
return
}
......@@ -408,10 +434,16 @@ func RenameDir(t provider.T) {
t.ID("7595")
t.AddParentSuite("管理禅道站点下工作目录")
fileUtils.MkDirIfNeeded(syncDir)
defer os.RemoveAll(syncDir)
webpage, _ := plwHelper.OpenUrl(constTestHelper.ZtfUrl, t)
defer webpage.Close()
defer os.RemoveAll(oldDirPath)
defer os.RemoveAll(workspacePath + "newDir")
ztfTestHelper.SelectSite(webpage)
ztfTestHelper.ExpandWorspace(webpage)
ztfTestHelper.ExpandProduct(webpage)
CreateDir(t)
......@@ -423,15 +455,18 @@ func RenameDir(t provider.T) {
webpage.Click("#scriptFormModal>>.modal-action>>span:has-text(\"确定\")")
webpage.Locator(fmt.Sprintf(".tree-node:has-text('%s')>>.tree-node-title>>text=newDir", constTestHelper.WorkspaceName))
os.Remove(commonTestHelper.GetPhpWorkspacePath() + "oldDir")
os.Remove(commonTestHelper.GetPhpWorkspacePath() + "newDir")
}
func DeleteScript(t provider.T) {
t.ID("5478")
t.AddParentSuite("管理禅道站点下工作目录")
fileUtils.MkDirIfNeeded(syncDir)
scriptPath := filepath.Join(workspacePath, "product1", "1.php")
fileUtils.WriteFile(scriptPath, "")
defer os.RemoveAll(syncDir)
defer os.RemoveAll(scriptPath)
webpage, _ := plwHelper.OpenUrl(constTestHelper.ZtfUrl, t)
defer webpage.Close()
......@@ -459,6 +494,9 @@ func DeleteDir(t provider.T) {
t.ID("5477")
t.AddParentSuite("管理禅道站点下工作目录")
fileUtils.MkDirIfNeeded(syncDir)
defer os.RemoveAll(syncDir)
webpage, _ := plwHelper.OpenUrl(constTestHelper.ZtfUrl, t)
defer webpage.Close()
......@@ -490,18 +528,19 @@ func DeleteWorkspace(t provider.T) {
defer webpage.Close()
ztfTestHelper.SelectSite(webpage)
ztfTestHelper.ExpandWorspace(webpage)
webpage.WaitForSelector(".tree-node")
locator := webpage.Locator(".tree-node-item", playwright.PageLocatorOptions{HasText: constTestHelper.WorkspaceName})
locator.Hover()
webpage.Click(`[title="删除"]`)
webpage.Click(".modal-action>>span:has-text(\"确定\")")
webpage.Click(".modal-action>>span>>text=确定")
webpage.WaitForTimeout(1000)
plwConf.DisableErr()
defer plwConf.EnableErr()
scriptLocator := webpage.Locator(fmt.Sprintf(".tree-node-title:has-text('%s')", constTestHelper.WorkspaceName))
scriptLocator := webpage.Locator(fmt.Sprintf(".tree-node-title>>text=%s", constTestHelper.WorkspaceName))
c := scriptLocator.Count()
if c > 0 {
t.Errorf("Delete workspace fail")
......@@ -513,17 +552,25 @@ func Clip(t provider.T) {
t.ID("5476")
t.AddParentSuite("管理禅道站点下工作目录")
fileUtils.MkDirIfNeeded(syncDir)
scriptPath := filepath.Join(workspacePath, "product1", "1.php")
scriptNewPath := filepath.Join(workspacePath, "1.php")
fileUtils.WriteFile(scriptPath, "")
defer func() {
os.RemoveAll(syncDir)
os.RemoveAll(scriptPath)
os.RemoveAll(scriptNewPath)
}()
webpage, _ := plwHelper.OpenUrl(constTestHelper.ZtfUrl, t)
defer webpage.Close()
ztfTestHelper.SelectSite(webpage)
webpage.WaitForSelector(".tree-node")
locator := webpage.Locator(".tree-node", playwright.PageLocatorOptions{HasText: constTestHelper.WorkspaceName})
locator.Click()
ztfTestHelper.ExpandWorspace(webpage)
ztfTestHelper.ExpandProduct(webpage)
scriptLocator := locator.Locator(".tree-node-title>>text=1.php")
scriptLocator := webpage.Locator(".tree-node-title>>text=1.php")
scriptLocator.RightClick()
webpage.Click(".tree-context-menu>>text=剪切")
workspaceLocator := webpage.Locator(".tree-node-title", playwright.PageLocatorOptions{HasText: constTestHelper.WorkspaceName})
......@@ -531,7 +578,7 @@ func Clip(t provider.T) {
webpage.Click(".tree-context-menu>>text=粘贴")
webpage.WaitForTimeout(1000)
locator.Locator(".tree-node-item>>div:has-text('1.php')")
webpage.Locator(".tree-node-item>>div:has-text('1.php')")
}
func Collapse(t provider.T) {
......@@ -573,8 +620,8 @@ func Collapse(t provider.T) {
}
func TestUiWorkspace(t *testing.T) {
runner.Run(t, "客户端-同步到禅道", SyncToZentao)
runner.Run(t, "客户端-从禅道同步选中用例", SyncTwoCaseFromZentao)
runner.Run(t, "客户端-从禅道同步", SyncFromZentao)
runner.Run(t, "客户端-从禅道同步选中用例", SyncTwoCaseFromZentao)
runner.Run(t, "客户端-复制粘贴树状脚本文件", Copy)
runner.Run(t, "客户端-复制粘贴目录", ClipAndCopyDir)
runner.Run(t, "客户端-剪切粘贴树状脚本文件", Clip)
......
......@@ -29,7 +29,6 @@ func KillProcessByUUID(uuid string) {
pid = cols[2]
}
if pid != "" {
fmt.Println(fmt.Sprintf(`taskkill /F /pid %s`, pid))
cmd2 := exec.Command("cmd")
cmd2.SysProcAttr = &syscall.SysProcAttr{CmdLine: fmt.Sprintf(`/c taskkill /F /pid %s`, pid), HideWindow: true}
cmd2.Start()
......
......@@ -187,7 +187,9 @@ func LoadSuite(productId uint, config commDomain.WorkspaceConf) (suites []domain
}
uri := fmt.Sprintf("products/%d/testsuites", productId)
url := GenApiUrl(uri, nil, config.Url)
url := GenApiUrl(uri, map[string]interface{}{
"limit": 10000,
}, config.Url)
bytes, err := httpUtils.Get(url)
if err != nil {
......
......@@ -3,6 +3,8 @@ package zentaoHelper
import (
"encoding/json"
"fmt"
"os"
commConsts "github.com/easysoft/zentaoatf/internal/pkg/consts"
commDomain "github.com/easysoft/zentaoatf/internal/pkg/domain"
websocketHelper "github.com/easysoft/zentaoatf/internal/pkg/helper/websocket"
......@@ -11,7 +13,6 @@ import (
logUtils "github.com/easysoft/zentaoatf/pkg/lib/log"
"github.com/fatih/color"
"github.com/kataras/iris/v12/websocket"
"os"
)
func CommitResult(report commDomain.ZtfReport, productId, taskId int, config commDomain.WorkspaceConf,
......@@ -19,7 +20,8 @@ func CommitResult(report commDomain.ZtfReport, productId, taskId int, config com
if productId != 0 {
report.ProductId = productId
}
RemoveAutoCreateId(&report)
FilterCases(&report, config)
report.TaskId = taskId
// for ci tool debug
......@@ -78,12 +80,37 @@ func JobCommitResult(report interface{}, config commDomain.WorkspaceConf) (err e
return
}
func RemoveAutoCreateId(report *commDomain.ZtfReport) {
if report.TestType == commConsts.TestFunc {
return
func FilterCases(report *commDomain.ZtfReport, config commDomain.WorkspaceConf) {
//get case list
casesResp, _ := LoadTestCaseSimple(report.ProductId, 0, 0, 0, config)
casesMap := map[int]bool{}
for _, caseInfo := range casesResp.Cases {
casesMap[caseInfo.Id] = true
}
funcResult := make([]commDomain.FuncResult, 0)
for _, cs := range report.FuncResult {
if _, ok := casesMap[cs.Id]; !ok || cs.Id == 0 {
continue
}
funcResult = append(funcResult, cs)
}
for idx, cs := range report.UnitResult {
report.UnitResult[idx].Id = cs.Cid
report.FuncResult = funcResult
unitResult := make([]commDomain.UnitResult, 0)
for _, cs := range report.UnitResult {
cs.Id = cs.Cid
if _, ok := casesMap[cs.Id]; !ok || cs.Id == 0 {
continue
}
unitResult = append(unitResult, cs)
}
report.UnitResult = unitResult
return
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册