ui_run_test.go 35.4 KB
Newer Older
雨爱无痕 已提交
1 2 3
package main

import (
雨爱无痕 已提交
4
	"strconv"
雨爱无痕 已提交
5 6 7
	"strings"
	"testing"

雨爱无痕 已提交
8 9
	"github.com/ozontech/allure-go/pkg/framework/provider"
	"github.com/ozontech/allure-go/pkg/framework/runner"
雨爱无痕 已提交
10 11 12 13 14
	playwright "github.com/playwright-community/playwright-go"
)

var runBrowser playwright.Browser

雨爱无痕 已提交
15
func RunScript(t provider.T) {
雨爱无痕 已提交
16 17
	t.ID("5479")
	t.AddParentSuite("执行脚本")
雨爱无痕 已提交
18 19 20 21 22
	pw, err := playwright.Run()
	if err != nil {
		t.Error(err)
		t.FailNow()
	}
雨爱无痕 已提交
23
	headless := true
雨爱无痕 已提交
24
	var slowMo float64 = 100
雨爱无痕 已提交
25
	runBrowser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{Headless: &headless, SlowMo: &slowMo})
雨爱无痕 已提交
26
	if err != nil {
雨爱无痕 已提交
27
		t.Errorf("Fail to launch the web runBrowser: %v", err)
雨爱无痕 已提交
28 29
		t.FailNow()
	}
雨爱无痕 已提交
30
	page, err := runBrowser.NewPage()
雨爱无痕 已提交
31 32 33 34 35
	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{
雨爱无痕 已提交
36
		WaitUntil: playwright.WaitUntilStateDomcontentloaded}); err != nil {
雨爱无痕 已提交
37 38 39 40 41 42 43 44
		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()
	}
雨爱无痕 已提交
45 46
	locator, err := page.Locator(".tree-node", playwright.PageLocatorOptions{HasText: "单元测试工作目录"})
	c, err := locator.Count()
雨爱无痕 已提交
47 48 49 50
	if err != nil || c == 0 {
		t.Errorf("Find workspace fail: %v", err)
		t.FailNow()
	}
雨爱无痕 已提交
51
	err = locator.Click()
雨爱无痕 已提交
52 53 54 55
	if err != nil {
		t.Errorf("Click node fail: %v", err)
		t.FailNow()
	}
雨爱无痕 已提交
56
	scriptLocator, err := locator.Locator("text=1_string_match.php")
雨爱无痕 已提交
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
	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()
	}
	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()
	}
	element, err := page.QuerySelector("#log-list>>.msg-span>>:has-text('执行1个用例,耗时')")
	innerText, err := element.InnerText()
	if err != nil {
		t.Errorf("Find result fail: %v", err)
		t.FailNow()
	}
	if !strings.Contains(innerText, "1(100.0%) 失败") {
		t.Errorf("Exec 1_string_match.php fail: %v", err)
		t.FailNow()
	}
雨爱无痕 已提交
86 87 88
	resultTitleElement, err := page.QuerySelector("#rightPane .result-list-item .list-item-title")
	if err != nil {
		t.Errorf("Find log title in logPane fail: %v", err)
雨爱无痕 已提交
89
		t.FailNow()
雨爱无痕 已提交
90 91 92 93
	}
	resultTitle, err := resultTitleElement.InnerText()
	if err != nil || resultTitle != "1_string_match.php" {
		t.Errorf("Find result in rightPane fail: %v", err)
雨爱无痕 已提交
94
		t.FailNow()
雨爱无痕 已提交
95 96 97 98
	}
	timeElement, err := page.QuerySelector("#log-list .item .time")
	if err != nil {
		t.Errorf("Find log time in logPane fail: %v", err)
雨爱无痕 已提交
99
		t.FailNow()
雨爱无痕 已提交
100 101 102 103
	}
	logTime, err := timeElement.InnerText()
	if err != nil {
		t.Errorf("Find log time in logPane fail: %v", err)
雨爱无痕 已提交
104
		t.FailNow()
雨爱无痕 已提交
105 106 107 108
	}
	resultTimeElement, err := page.QuerySelector("#rightPane .result-list-item .list-item-trailing-text")
	if err != nil {
		t.Errorf("Find log time in logPane fail: %v", err)
雨爱无痕 已提交
109
		t.FailNow()
雨爱无痕 已提交
110 111 112 113
	}
	resultTime, err := resultTimeElement.InnerText()
	if err != nil || logTime[:5] != resultTime {
		t.Errorf("Find result in rightPane fail: %v", err)
雨爱无痕 已提交
114
		t.FailNow()
雨爱无痕 已提交
115
	}
雨爱无痕 已提交
116

雨爱无痕 已提交
117 118
	if err = runBrowser.Close(); err != nil {
		t.Errorf("The runBrowser cannot be closed: %v", err)
雨爱无痕 已提交
119 120 121 122 123 124 125 126
		t.FailNow()
	}
	if err = pw.Stop(); err != nil {
		t.Errorf("The playwright cannot be stopped: %v", err)
		t.FailNow()
	}
}

雨爱无痕 已提交
127
func RunSelectedScripts(t provider.T) {
雨爱无痕 已提交
128 129
	t.ID("5481")
	t.AddParentSuite("执行脚本")
雨爱无痕 已提交
130 131 132 133 134
	pw, err := playwright.Run()
	if err != nil {
		t.Error(err)
		t.FailNow()
	}
雨爱无痕 已提交
135
	headless := true
雨爱无痕 已提交
136
	var slowMo float64 = 100
雨爱无痕 已提交
137
	runBrowser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{Headless: &headless, SlowMo: &slowMo})
雨爱无痕 已提交
138
	if err != nil {
雨爱无痕 已提交
139
		t.Errorf("Fail to launch the web runBrowser: %v", err)
雨爱无痕 已提交
140 141
		t.FailNow()
	}
雨爱无痕 已提交
142
	page, err := runBrowser.NewPage()
雨爱无痕 已提交
143 144 145 146 147
	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{
雨爱无痕 已提交
148
		WaitUntil: playwright.WaitUntilStateDomcontentloaded}); err != nil {
雨爱无痕 已提交
149 150 151 152 153 154 155 156
		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()
	}
雨爱无痕 已提交
157 158
	locator, err := page.Locator(".tree-node", playwright.PageLocatorOptions{HasText: "单元测试工作目录"})
	c, err := locator.Count()
雨爱无痕 已提交
159 160 161 162
	if err != nil || c == 0 {
		t.Errorf("Find workspace fail: %v", err)
		t.FailNow()
	}
雨爱无痕 已提交
163
	err = locator.Click()
雨爱无痕 已提交
164 165 166 167 168 169 170 171 172
	if err != nil {
		t.Errorf("Click node fail: %v", err)
		t.FailNow()
	}
	err = page.Click(`[title="批量选择"]`)
	if err != nil {
		t.Errorf("The Click select btn fail: %v", err)
		t.FailNow()
	}
雨爱无痕 已提交
173
	scriptLocator, err := locator.Locator(".tree-node-item:has-text('1_string_match.php')")
雨爱无痕 已提交
174 175 176 177 178 179 180 181 182 183 184 185 186 187
	if err != nil {
		t.Errorf("Find 1_string_match.php fail: %v", err)
		t.FailNow()
	}
	scriptLocator, err = scriptLocator.Locator(".tree-node-check")
	if err != nil {
		t.Errorf("Find 1_string_match.php checkbox fail: %v", err)
		t.FailNow()
	}
	err = scriptLocator.Click()
	if err != nil {
		t.Errorf("Click 1_string_match.php checkbox fail: %v", err)
		t.FailNow()
	}
雨爱无痕 已提交
188
	scriptLocator, err = locator.Locator(".tree-node-item:has-text('2_webpage_extract.php')")
雨爱无痕 已提交
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
	if err != nil {
		t.Errorf("Find 2_webpage_extract.php fail: %v", err)
		t.FailNow()
	}
	scriptLocator, err = scriptLocator.Locator(".tree-node-check")
	if err != nil {
		t.Errorf("Find 2_webpage_extract.php checkbox fail: %v", err)
		t.FailNow()
	}
	err = scriptLocator.Click()
	if err != nil {
		t.Errorf("Click 2_webpage_extract.php checkbox fail: %v", err)
		t.FailNow()
	}
	err = page.Click(".run-selected")
	if err != nil {
		t.Errorf("Click run fail: %v", err)
		t.FailNow()
	}
	_, err = page.WaitForSelector("#log-list>>.msg-span>>:has-text('执行2个用例,耗时')")
	if err != nil {
		t.Errorf("Wait exec result fail: %v", err)
		t.FailNow()
	}
	element, err := page.QuerySelector("#log-list>>.msg-span>>:has-text('执行2个用例,耗时')")
	innerText, err := element.InnerText()
	if err != nil {
		t.Errorf("Find result fail: %v", err)
		t.FailNow()
	}
	if !strings.Contains(innerText, "1(50.0%) 通过,1(50.0%) 失败") {
		t.Errorf("Exec 1_string_match.php,2_webpage_extract.php fail: %v", err)
		t.FailNow()
	}
雨爱无痕 已提交
223 224 225
	resultTitleElement, err := page.QuerySelector("#rightPane .result-list-item .list-item-title")
	if err != nil {
		t.Errorf("Find log title in logPane fail: %v", err)
雨爱无痕 已提交
226
		t.FailNow()
雨爱无痕 已提交
227 228 229 230
	}
	resultTitle, err := resultTitleElement.InnerText()
	if err != nil || resultTitle != "单元测试工作目录(2)" {
		t.Errorf("Find result in rightPane fail: %v", err)
雨爱无痕 已提交
231
		t.FailNow()
雨爱无痕 已提交
232 233 234 235
	}
	timeElement, err := page.QuerySelector("#log-list .item .time")
	if err != nil {
		t.Errorf("Find log time in logPane fail: %v", err)
雨爱无痕 已提交
236
		t.FailNow()
雨爱无痕 已提交
237 238 239 240
	}
	logTime, err := timeElement.InnerText()
	if err != nil {
		t.Errorf("Find log time in logPane fail: %v", err)
雨爱无痕 已提交
241
		t.FailNow()
雨爱无痕 已提交
242 243 244 245
	}
	resultTimeElement, err := page.QuerySelector("#rightPane .result-list-item .list-item-trailing-text")
	if err != nil {
		t.Errorf("Find log time in logPane fail: %v", err)
雨爱无痕 已提交
246
		t.FailNow()
雨爱无痕 已提交
247 248 249 250
	}
	resultTime, err := resultTimeElement.InnerText()
	if err != nil || logTime[:5] != resultTime {
		t.Errorf("Find result in rightPane fail: %v", err)
雨爱无痕 已提交
251
		t.FailNow()
雨爱无痕 已提交
252
	}
雨爱无痕 已提交
253 254
	if err = runBrowser.Close(); err != nil {
		t.Errorf("The runBrowser cannot be closed: %v", err)
雨爱无痕 已提交
255 256 257 258 259 260 261 262
		t.FailNow()
	}
	if err = pw.Stop(); err != nil {
		t.Errorf("The playwright cannot be stopped: %v", err)
		t.FailNow()
	}
}

雨爱无痕 已提交
263
func RunOpenedAndLast(t provider.T) {
雨爱无痕 已提交
264 265
	t.ID("5484")
	t.AddParentSuite("执行脚本")
雨爱无痕 已提交
266 267 268 269 270
	pw, err := playwright.Run()
	if err != nil {
		t.Error(err)
		t.FailNow()
	}
雨爱无痕 已提交
271
	headless := true
雨爱无痕 已提交
272
	var slowMo float64 = 100
雨爱无痕 已提交
273
	runBrowser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{Headless: &headless, SlowMo: &slowMo})
雨爱无痕 已提交
274
	if err != nil {
雨爱无痕 已提交
275
		t.Errorf("Fail to launch the web runBrowser: %v", err)
雨爱无痕 已提交
276 277
		t.FailNow()
	}
雨爱无痕 已提交
278
	page, err := runBrowser.NewPage()
雨爱无痕 已提交
279 280 281 282 283
	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{
雨爱无痕 已提交
284
		WaitUntil: playwright.WaitUntilStateDomcontentloaded}); err != nil {
雨爱无痕 已提交
285 286 287 288 289 290 291 292
		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()
	}
雨爱无痕 已提交
293
	locator, err := page.Locator("#siteMenuToggle")
雨爱无痕 已提交
294 295 296 297
	if err != nil {
		t.Errorf("The siteMenuToggle is missing: %v", err)
		t.FailNow()
	}
雨爱无痕 已提交
298
	err = locator.Click()
雨爱无痕 已提交
299 300 301 302 303 304 305 306 307 308 309 310 311 312
	if err != nil {
		t.Errorf("The Click is fail: %v", err)
		t.FailNow()
	}
	_, err = page.WaitForSelector("#navbar .list-item")
	if err != nil {
		t.Errorf("Wait for site list nav fail: %v", err)
		t.FailNow()
	}
	err = page.Click(".list-item-title>>text=单元测试站点")
	if err != nil {
		t.Errorf("The Click site nav fail: %v", err)
		t.FailNow()
	}
雨爱无痕 已提交
313 314 315 316 317
	_, err = page.WaitForSelector(".tree-node")
	if err != nil {
		t.Errorf("Wait tree-node fail: %v", err)
		t.FailNow()
	}
雨爱无痕 已提交
318 319
	locator, err = page.Locator(".tree-node", playwright.PageLocatorOptions{HasText: "单元测试工作目录"})
	c, err := locator.Count()
雨爱无痕 已提交
320 321 322 323
	if err != nil || c == 0 {
		t.Errorf("Find workspace fail: %v", err)
		t.FailNow()
	}
雨爱无痕 已提交
324
	err = locator.Click()
雨爱无痕 已提交
325 326 327 328
	if err != nil || c == 0 {
		t.Errorf("Click workspace fail: %v", err)
		t.FailNow()
	}
雨爱无痕 已提交
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
	err = page.Click(".tree-node-item:has-text('1_string_match.php')")
	if err != nil {
		t.Errorf("Click 1_string_match.php fail: %v", err)
		t.FailNow()
	}
	err = page.Click(".tree-node-item:has-text('2_webpage_extract.php')")
	if err != nil {
		t.Errorf("Click 2_webpage_extract.php fail: %v", err)
		t.FailNow()
	}
	err = page.Click("#batchRunMenuToggle")
	if err != nil {
		t.Errorf("Click batchRunMenuToggle fail: %v", err)
		t.FailNow()
	}
雨爱无痕 已提交
344
	err = page.Click(".list-item-content:has-text('执行打开文件')")
雨爱无痕 已提交
345
	if err != nil {
雨爱无痕 已提交
346
		t.Errorf("The Click Run opened scripts fail: %v", err)
雨爱无痕 已提交
347 348 349 350
		t.FailNow()
	}
	_, err = page.WaitForSelector("#log-list>>.msg-span>>:has-text('执行2个用例,耗时')")
	if err != nil {
雨爱无痕 已提交
351
		t.Errorf("Wait exec opened scripts result fail: %v", err)
雨爱无痕 已提交
352 353
		t.FailNow()
	}
雨爱无痕 已提交
354
	locator, err = page.Locator("#log-list>>code:has-text('执行2个用例,耗时')")
雨爱无痕 已提交
355 356 357 358
	if err != nil {
		t.Errorf("Find exec opened scripts result fail: %v", err)
		t.FailNow()
	}
雨爱无痕 已提交
359
	innerText, err := locator.InnerText()
雨爱无痕 已提交
360
	if err != nil {
雨爱无痕 已提交
361
		t.Errorf("Find exec opened scripts result fail: %v", err)
雨爱无痕 已提交
362 363 364
		t.FailNow()
	}
	if !strings.Contains(innerText, "1(50.0%) 通过,1(50.0%) 失败") {
雨爱无痕 已提交
365 366 367 368 369 370 371 372 373
		t.Errorf("Exec opened scripts fail: %v", err)
		t.FailNow()
	}

	resultTitleElement, err := page.QuerySelector("#rightPane .result-list-item .list-item-title")
	if err != nil {
		t.Errorf("Find log title in logPane fail: %v", err)
	}
	resultTitle, err := resultTitleElement.InnerText()
雨爱无痕 已提交
374
	if err != nil || resultTitle != "单元测试工作目录(3)" {
雨爱无痕 已提交
375 376
		t.Errorf("Find result in rightPane fail: %v", err)
	}
雨爱无痕 已提交
377
	timeElement, err := locator.Locator(".time>>span")
雨爱无痕 已提交
378
	if err != nil {
雨爱无痕 已提交
379 380
		t.Errorf("Find log time element in logPane fail: %v", err)
		t.FailNow()
雨爱无痕 已提交
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
	}
	logTime, err := timeElement.InnerText()
	if err != nil {
		t.Errorf("Find log time in logPane fail: %v", err)
	}
	resultTimeElement, err := page.QuerySelector("#rightPane .result-list-item .list-item-trailing-text")
	if err != nil {
		t.Errorf("Find log time in logPane fail: %v", err)
	}
	resultTime, err := resultTimeElement.InnerText()
	if err != nil || logTime[:5] != resultTime {
		t.Errorf("Find result in rightPane fail: %v", err)
	}

	err = page.Click("#batchRunMenuToggle")
	if err != nil {
		t.Errorf("Click batchRunMenuToggle fail: %v", err)
		t.FailNow()
	}
	err = page.Click(".list-item-content:has-text('执行上次')")
	if err != nil {
		t.Errorf("The Click Run last time fail: %v", err)
		t.FailNow()
	}
	_, err = page.WaitForSelector("#log-list>>.msg-span>>:has-text('执行2个用例,耗时')")
	if err != nil {
		t.Errorf("Wait exec last time result fail: %v", err)
		t.FailNow()
	}
雨爱无痕 已提交
410 411
	locator, err = page.Locator("#log-list>>code:has-text('执行2个用例,耗时')")
	innerText, err = locator.InnerText()
雨爱无痕 已提交
412 413 414 415 416 417 418 419 420 421 422
	if err != nil {
		t.Errorf("Find exec last time result fail: %v", err)
		t.FailNow()
	}
	if !strings.Contains(innerText, "1(50.0%) 通过,1(50.0%) 失败") {
		t.Errorf("Exec last time fail: %v", err)
		t.FailNow()
	}
	resultTitleElement, err = page.QuerySelector("#rightPane .result-list-item .list-item-title")
	if err != nil {
		t.Errorf("Find log title in logPane fail: %v", err)
雨爱无痕 已提交
423
		t.FailNow()
雨爱无痕 已提交
424 425 426 427
	}
	resultTitle, err = resultTitleElement.InnerText()
	if err != nil || resultTitle != "单元测试工作目录(2)" {
		t.Errorf("Find result in rightPane fail: %v", err)
雨爱无痕 已提交
428
		t.FailNow()
雨爱无痕 已提交
429
	}
雨爱无痕 已提交
430
	timeElement, err = locator.Locator(".time>>span")
雨爱无痕 已提交
431
	if err != nil {
雨爱无痕 已提交
432 433
		t.Errorf("Find log time element in logPane fail: %v", err)
		t.FailNow()
雨爱无痕 已提交
434 435 436 437
	}
	logTime, err = timeElement.InnerText()
	if err != nil {
		t.Errorf("Find log time in logPane fail: %v", err)
雨爱无痕 已提交
438
		t.FailNow()
雨爱无痕 已提交
439 440 441 442
	}
	resultTimeElement, err = page.QuerySelector("#rightPane .result-list-item .list-item-trailing-text")
	if err != nil {
		t.Errorf("Find log time in logPane fail: %v", err)
雨爱无痕 已提交
443
		t.FailNow()
雨爱无痕 已提交
444 445 446 447
	}
	resultTime, err = resultTimeElement.InnerText()
	if err != nil || logTime[:5] != resultTime {
		t.Errorf("Find result in rightPane fail: %v", err)
雨爱无痕 已提交
448
		t.FailNow()
雨爱无痕 已提交
449
	}
雨爱无痕 已提交
450 451
	if err = runBrowser.Close(); err != nil {
		t.Errorf("The runBrowser cannot be closed: %v", err)
雨爱无痕 已提交
452 453 454 455 456 457 458 459
		t.FailNow()
	}
	if err = pw.Stop(); err != nil {
		t.Errorf("The playwright cannot be stopped: %v", err)
		t.FailNow()
	}
}

雨爱无痕 已提交
460
func RunAll(t provider.T) {
雨爱无痕 已提交
461 462
	t.ID("5485")
	t.AddParentSuite("执行脚本")
雨爱无痕 已提交
463 464 465 466 467
	pw, err := playwright.Run()
	if err != nil {
		t.Error(err)
		t.FailNow()
	}
雨爱无痕 已提交
468
	headless := true
雨爱无痕 已提交
469
	var slowMo float64 = 100
雨爱无痕 已提交
470
	runBrowser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{Headless: &headless, SlowMo: &slowMo})
雨爱无痕 已提交
471
	if err != nil {
雨爱无痕 已提交
472
		t.Errorf("Fail to launch the web runBrowser: %v", err)
雨爱无痕 已提交
473 474
		t.FailNow()
	}
雨爱无痕 已提交
475
	page, err := runBrowser.NewPage()
雨爱无痕 已提交
476 477 478 479 480
	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{
雨爱无痕 已提交
481
		WaitUntil: playwright.WaitUntilStateDomcontentloaded}); err != nil {
雨爱无痕 已提交
482 483 484 485 486 487 488 489
		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()
	}
雨爱无痕 已提交
490
	locator, err := page.Locator("#siteMenuToggle")
雨爱无痕 已提交
491 492 493 494
	if err != nil {
		t.Errorf("The siteMenuToggle is missing: %v", err)
		t.FailNow()
	}
雨爱无痕 已提交
495
	err = locator.Click()
雨爱无痕 已提交
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
	if err != nil {
		t.Errorf("The Click is fail: %v", err)
		t.FailNow()
	}
	_, err = page.WaitForSelector("#navbar .list-item")
	if err != nil {
		t.Errorf("Wait for site list nav fail: %v", err)
		t.FailNow()
	}
	err = page.Click(".list-item-title>>text=单元测试站点")
	if err != nil {
		t.Errorf("The Click site nav fail: %v", err)
		t.FailNow()
	}
	_, err = page.WaitForSelector(".tree-node")
	if err != nil {
		t.Errorf("Wait tree-node fail: %v", err)
		t.FailNow()
	}
雨爱无痕 已提交
515 516
	locator, err = page.Locator(".tree-node", playwright.PageLocatorOptions{HasText: "单元测试工作目录"})
	c, err := locator.Count()
雨爱无痕 已提交
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536
	if err != nil || c == 0 {
		t.Errorf("Find workspace fail: %v", err)
		t.FailNow()
	}

	err = page.Click("#batchRunMenuToggle")
	if err != nil {
		t.Errorf("Click batchRunMenuToggle fail: %v", err)
		t.FailNow()
	}
	err = page.Click(".list-item-content:has-text('执行所有文件')")
	if err != nil {
		t.Errorf("The Click Run all scripts fail: %v", err)
		t.FailNow()
	}
	_, err = page.WaitForSelector("#log-list>>.msg-span>>:has-text('执行3个用例,耗时')")
	if err != nil {
		t.Errorf("Wait exec all scripts result fail: %v", err)
		t.FailNow()
	}
雨爱无痕 已提交
537
	locator, err = page.Locator("#log-list>>code:has-text('执行3个用例,耗时')")
雨爱无痕 已提交
538 539 540 541
	if err != nil {
		t.Errorf("Find exec all scripts result fail: %v", err)
		t.FailNow()
	}
雨爱无痕 已提交
542
	innerText, err := locator.InnerText()
雨爱无痕 已提交
543 544 545 546 547 548 549 550 551 552 553
	if err != nil {
		t.Errorf("Find exec all scripts result fail: %v", err)
		t.FailNow()
	}
	if !strings.Contains(innerText, "2(66.0%) 通过,1(33.0%) 失败") {
		t.Errorf("Exec all fail: %v", err)
		t.FailNow()
	}
	resultTitleElement, err := page.QuerySelector("#rightPane .result-list-item .list-item-title")
	if err != nil {
		t.Errorf("Find log title in logPane fail: %v", err)
雨爱无痕 已提交
554
		t.FailNow()
雨爱无痕 已提交
555 556 557 558
	}
	resultTitle, err := resultTitleElement.InnerText()
	if err != nil || resultTitle != "单元测试工作目录(3)" {
		t.Errorf("Find result in rightPane fail: %v", err)
雨爱无痕 已提交
559
		t.FailNow()
雨爱无痕 已提交
560
	}
雨爱无痕 已提交
561
	timeElement, err := locator.Locator(".time>>span")
雨爱无痕 已提交
562
	if err != nil {
雨爱无痕 已提交
563 564
		t.Errorf("Find log time element in logPane fail: %v", err)
		t.FailNow()
雨爱无痕 已提交
565 566 567 568
	}
	logTime, err := timeElement.InnerText()
	if err != nil {
		t.Errorf("Find log time in logPane fail: %v", err)
雨爱无痕 已提交
569
		t.FailNow()
雨爱无痕 已提交
570 571 572 573
	}
	resultTimeElement, err := page.QuerySelector("#rightPane .result-list-item .list-item-trailing-text")
	if err != nil {
		t.Errorf("Find log time in logPane fail: %v", err)
雨爱无痕 已提交
574
		t.FailNow()
雨爱无痕 已提交
575 576 577 578 579
	}
	resultTime, err := resultTimeElement.InnerText()
	if err != nil || logTime[:5] != resultTime {
		t.Errorf("Find result in rightPane fail: %v", err)
	}
雨爱无痕 已提交
580 581
	if err = runBrowser.Close(); err != nil {
		t.Errorf("The runBrowser cannot be closed: %v", err)
雨爱无痕 已提交
582 583 584 585 586 587 588 589
		t.FailNow()
	}
	if err = pw.Stop(); err != nil {
		t.Errorf("The playwright cannot be stopped: %v", err)
		t.FailNow()
	}
}

雨爱无痕 已提交
590
func RunReExecFailCase(t provider.T) {
雨爱无痕 已提交
591 592
	t.ID("5491")
	t.AddParentSuite("执行脚本")
雨爱无痕 已提交
593 594 595 596 597
	pw, err := playwright.Run()
	if err != nil {
		t.Error(err)
		t.FailNow()
	}
雨爱无痕 已提交
598
	headless := true
雨爱无痕 已提交
599
	var slowMo float64 = 100
雨爱无痕 已提交
600
	runBrowser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{Headless: &headless, SlowMo: &slowMo})
雨爱无痕 已提交
601
	if err != nil {
雨爱无痕 已提交
602
		t.Errorf("Fail to launch the web runBrowser: %v", err)
雨爱无痕 已提交
603 604
		t.FailNow()
	}
雨爱无痕 已提交
605
	page, err := runBrowser.NewPage()
雨爱无痕 已提交
606 607 608 609 610
	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{
雨爱无痕 已提交
611
		WaitUntil: playwright.WaitUntilStateDomcontentloaded}); err != nil {
雨爱无痕 已提交
612 613 614 615 616 617 618 619 620
		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()
	}

雨爱无痕 已提交
621
	locator, err := page.Locator("#siteMenuToggle")
雨爱无痕 已提交
622 623 624 625
	if err != nil {
		t.Errorf("The siteMenuToggle is missing: %v", err)
		t.FailNow()
	}
雨爱无痕 已提交
626
	err = locator.Click()
雨爱无痕 已提交
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658
	if err != nil {
		t.Errorf("The Click is fail: %v", err)
		t.FailNow()
	}
	_, err = page.WaitForSelector("#navbar .list-item")
	if err != nil {
		t.Errorf("Wait for site list nav fail: %v", err)
		t.FailNow()
	}
	err = page.Click(".list-item-title>>text=单元测试站点")
	if err != nil {
		t.Errorf("The Click site nav fail: %v", err)
		t.FailNow()
	}
	_, err = page.WaitForSelector(".tree-node")
	if err != nil {
		t.Errorf("Wait tree-node fail: %v", err)
		t.FailNow()
	}
	err = page.Click("#rightPane .result-list-item .list-item-title>>nth=0")
	if err != nil {
		t.Errorf("Click first result fail: %v", err)
	}
	err = page.Click(".result-action .btn:has-text('重新执行失败用例')")
	if err != nil {
		t.Errorf("Click re-exec failed case btn fail: %v", err)
	}
	_, err = page.WaitForSelector("#log-list>>.msg-span>>:has-text('执行1个用例,耗时')")
	if err != nil {
		t.Errorf("Wait exec script result fail: %v", err)
		t.FailNow()
	}
雨爱无痕 已提交
659
	locator, err = page.Locator("#log-list>>code:has-text('执行1个用例,耗时')")
雨爱无痕 已提交
660 661 662 663
	if err != nil {
		t.Errorf("Find exec script log fail: %v", err)
		t.FailNow()
	}
雨爱无痕 已提交
664
	innerText, err := locator.InnerText()
雨爱无痕 已提交
665 666 667 668 669 670 671 672 673 674 675
	if err != nil {
		t.Errorf("Find exec script result fail: %v", err)
		t.FailNow()
	}
	if !strings.Contains(innerText, "0(0.0%) 通过,1(100.0%) 失败") {
		t.Errorf("Exec failed case fail: %v", err)
		t.FailNow()
	}
	resultTitleElement, err := page.QuerySelector("#rightPane .result-list-item .list-item-title")
	if err != nil {
		t.Errorf("Find log title in logPane fail: %v", err)
雨爱无痕 已提交
676
		t.FailNow()
雨爱无痕 已提交
677 678
	}
	resultTitle, err := resultTitleElement.InnerText()
雨爱无痕 已提交
679
	if err != nil || resultTitle != "1_string_match.php" {
雨爱无痕 已提交
680
		t.Errorf("Find result in rightPane fail: %v", err)
雨爱无痕 已提交
681
		t.FailNow()
雨爱无痕 已提交
682
	}
雨爱无痕 已提交
683
	timeElement, err := locator.Locator(".time>>span")
雨爱无痕 已提交
684 685 686 687 688 689 690 691 692 693
	if err != nil || resultTitle != "1_string_match.php" {
		t.Errorf("Find log time element in logPane fail: %v", err)
		t.FailNow()
	}
	logTime, err := timeElement.InnerText()
	if err != nil {
		t.Errorf("Find log time in logPane fail: %v", err)
		t.FailNow()
	}
	resultTimeElement, err := page.QuerySelector("#rightPane .result-list-item .list-item-trailing-text")
雨爱无痕 已提交
694 695
	if err != nil {
		t.Errorf("Find log time in logPane fail: %v", err)
雨爱无痕 已提交
696 697 698 699 700 701 702
		t.FailNow()
	}
	resultTime, err := resultTimeElement.InnerText()
	if err != nil || logTime[:5] != resultTime {
		t.Errorf("Find result in rightPane fail: %v", err)
		t.FailNow()
	}
雨爱无痕 已提交
703 704
	if err = runBrowser.Close(); err != nil {
		t.Errorf("The runBrowser cannot be closed: %v", err)
雨爱无痕 已提交
705 706 707 708 709 710 711 712
		t.FailNow()
	}
	if err = pw.Stop(); err != nil {
		t.Errorf("The playwright cannot be stopped: %v", err)
		t.FailNow()
	}
}

雨爱无痕 已提交
713
func RunReExecAllCase(t provider.T) {
雨爱无痕 已提交
714 715
	t.ID("5491")
	t.AddParentSuite("执行脚本")
雨爱无痕 已提交
716 717 718 719 720 721 722
	pw, err := playwright.Run()
	if err != nil {
		t.Error(err)
		t.FailNow()
	}
	headless := true
	var slowMo float64 = 100
雨爱无痕 已提交
723
	runBrowser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{Headless: &headless, SlowMo: &slowMo})
雨爱无痕 已提交
724
	if err != nil {
雨爱无痕 已提交
725
		t.Errorf("Fail to launch the web runBrowser: %v", err)
雨爱无痕 已提交
726 727
		t.FailNow()
	}
雨爱无痕 已提交
728
	page, err := runBrowser.NewPage()
雨爱无痕 已提交
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743
	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()
	}

雨爱无痕 已提交
744
	locator, err := page.Locator("#siteMenuToggle")
雨爱无痕 已提交
745 746 747 748
	if err != nil {
		t.Errorf("The siteMenuToggle is missing: %v", err)
		t.FailNow()
	}
雨爱无痕 已提交
749
	err = locator.Click()
雨爱无痕 已提交
750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781
	if err != nil {
		t.Errorf("The Click is fail: %v", err)
		t.FailNow()
	}
	_, err = page.WaitForSelector("#navbar .list-item")
	if err != nil {
		t.Errorf("Wait for site list nav fail: %v", err)
		t.FailNow()
	}
	err = page.Click(".list-item-title>>text=单元测试站点")
	if err != nil {
		t.Errorf("The Click site nav fail: %v", err)
		t.FailNow()
	}
	_, err = page.WaitForSelector(".tree-node")
	if err != nil {
		t.Errorf("Wait tree-node fail: %v", err)
		t.FailNow()
	}
	err = page.Click("#rightPane .result-list-item .list-item-title>>nth=0")
	if err != nil {
		t.Errorf("Click first result fail: %v", err)
	}
	err = page.Click(".result-action .btn:has-text('重新执行所有用例')")
	if err != nil {
		t.Errorf("Click re-exec failed case btn fail: %v", err)
	}
	_, err = page.WaitForSelector("#log-list>>.msg-span>>:has-text('执行3个用例,耗时')")
	if err != nil {
		t.Errorf("Wait exec script result fail: %v", err)
		t.FailNow()
	}
雨爱无痕 已提交
782
	locator, err = page.Locator("#log-list>>code:has-text('执行3个用例,耗时')")
雨爱无痕 已提交
783 784 785 786
	if err != nil {
		t.Errorf("Find exec script log fail: %v", err)
		t.FailNow()
	}
雨爱无痕 已提交
787
	innerText, err := locator.InnerText()
雨爱无痕 已提交
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805
	if err != nil {
		t.Errorf("Find exec script result fail: %v", err)
		t.FailNow()
	}
	if !strings.Contains(innerText, "2(66.0%) 通过,1(33.0%) 失败") {
		t.Errorf("Exec failed case fail: %v", err)
		t.FailNow()
	}
	resultTitleElement, err := page.QuerySelector("#rightPane .result-list-item .list-item-title")
	if err != nil {
		t.Errorf("Find log title in logPane fail: %v", err)
		t.FailNow()
	}
	resultTitle, err := resultTitleElement.InnerText()
	if err != nil || resultTitle != "单元测试工作目录(3)" {
		t.Errorf("Find result in rightPane fail: %v", err)
		t.FailNow()
	}
雨爱无痕 已提交
806
	timeElement, err := locator.Locator(".time>>span")
雨爱无痕 已提交
807 808 809
	if err != nil {
		t.Errorf("Find log time element in logPane fail: %v", err)
		t.FailNow()
雨爱无痕 已提交
810 811 812 813
	}
	logTime, err := timeElement.InnerText()
	if err != nil {
		t.Errorf("Find log time in logPane fail: %v", err)
雨爱无痕 已提交
814
		t.FailNow()
雨爱无痕 已提交
815 816 817 818
	}
	resultTimeElement, err := page.QuerySelector("#rightPane .result-list-item .list-item-trailing-text")
	if err != nil {
		t.Errorf("Find log time in logPane fail: %v", err)
雨爱无痕 已提交
819
		t.FailNow()
雨爱无痕 已提交
820 821 822 823
	}
	resultTime, err := resultTimeElement.InnerText()
	if err != nil || logTime[:5] != resultTime {
		t.Errorf("Find result in rightPane fail: %v", err)
雨爱无痕 已提交
824
		t.FailNow()
雨爱无痕 已提交
825
	}
雨爱无痕 已提交
826 827
	if err = runBrowser.Close(); err != nil {
		t.Errorf("The runBrowser cannot be closed: %v", err)
雨爱无痕 已提交
828 829 830 831 832 833 834 835
		t.FailNow()
	}
	if err = pw.Stop(); err != nil {
		t.Errorf("The playwright cannot be stopped: %v", err)
		t.FailNow()
	}
}

雨爱无痕 已提交
836
func RunFailStatistic(t provider.T) {
雨爱无痕 已提交
837 838
	t.ID("5487")
	t.AddParentSuite("执行脚本")
雨爱无痕 已提交
839 840 841 842 843 844 845
	pw, err := playwright.Run()
	if err != nil {
		t.Error(err)
		t.FailNow()
	}
	headless := true
	var slowMo float64 = 100
雨爱无痕 已提交
846
	runBrowser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{Headless: &headless, SlowMo: &slowMo})
雨爱无痕 已提交
847
	if err != nil {
雨爱无痕 已提交
848
		t.Errorf("Fail to launch the web runBrowser: %v", err)
雨爱无痕 已提交
849 850
		t.FailNow()
	}
雨爱无痕 已提交
851
	page, err := runBrowser.NewPage()
雨爱无痕 已提交
852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911
	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()
	}
雨爱无痕 已提交
912 913
	if err = runBrowser.Close(); err != nil {
		t.Errorf("The runBrowser cannot be closed: %v", err)
雨爱无痕 已提交
914 915 916 917 918 919 920 921
		t.FailNow()
	}
	if err = pw.Stop(); err != nil {
		t.Errorf("The playwright cannot be stopped: %v", err)
		t.FailNow()
	}
}

雨爱无痕 已提交
922
func RunSuccessStatistic(t provider.T) {
雨爱无痕 已提交
923 924
	t.ID("5487")
	t.AddParentSuite("执行脚本")
雨爱无痕 已提交
925 926 927 928 929 930 931
	pw, err := playwright.Run()
	if err != nil {
		t.Error(err)
		t.FailNow()
	}
	headless := true
	var slowMo float64 = 100
雨爱无痕 已提交
932
	runBrowser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{Headless: &headless, SlowMo: &slowMo})
雨爱无痕 已提交
933
	if err != nil {
雨爱无痕 已提交
934
		t.Errorf("Fail to launch the web runBrowser: %v", err)
雨爱无痕 已提交
935 936
		t.FailNow()
	}
雨爱无痕 已提交
937
	page, err := runBrowser.NewPage()
雨爱无痕 已提交
938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997
	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()
	}
雨爱无痕 已提交
998 999
	if err = runBrowser.Close(); err != nil {
		t.Errorf("The runBrowser cannot be closed: %v", err)
雨爱无痕 已提交
1000 1001 1002 1003 1004 1005 1006 1007
		t.FailNow()
	}
	if err = pw.Stop(); err != nil {
		t.Errorf("The playwright cannot be stopped: %v", err)
		t.FailNow()
	}
}

雨爱无痕 已提交
1008
func RunBugStatistic(t provider.T) {
雨爱无痕 已提交
1009 1010
	t.ID("5487")
	t.AddParentSuite("执行脚本")
雨爱无痕 已提交
1011 1012 1013 1014 1015 1016 1017
	pw, err := playwright.Run()
	if err != nil {
		t.Error(err)
		t.FailNow()
	}
	headless := true
	var slowMo float64 = 100
雨爱无痕 已提交
1018
	runBrowser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{Headless: &headless, SlowMo: &slowMo})
雨爱无痕 已提交
1019
	if err != nil {
雨爱无痕 已提交
1020
		t.Errorf("Fail to launch the web runBrowser: %v", err)
雨爱无痕 已提交
1021 1022
		t.FailNow()
	}
雨爱无痕 已提交
1023
	page, err := runBrowser.NewPage()
雨爱无痕 已提交
1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074
	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()
	}
雨爱无痕 已提交
1075 1076
	if err = runBrowser.Close(); err != nil {
		t.Errorf("The runBrowser cannot be closed: %v", err)
雨爱无痕 已提交
1077 1078 1079 1080 1081 1082 1083 1084
		t.FailNow()
	}
	if err = pw.Stop(); err != nil {
		t.Errorf("The playwright cannot be stopped: %v", err)
		t.FailNow()
	}
}

雨爱无痕 已提交
1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190
func RunWorkspace(t provider.T) {
	t.ID("5482")
	t.AddParentSuite("右键执行脚本")
	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(playwright.PageClickOptions{Button: playwright.MouseButtonRight})
	if err != nil {
		t.Errorf("Right click workspace fail: %v", err)
		t.FailNow()
	}
	err = page.Click(".tree-context-menu>>text=执行")
	if err != nil {
		t.Errorf("Click copy fail: %v", err)
		t.FailNow()
	}
	_, err = page.WaitForSelector("#log-list>>.msg-span>>:has-text('执行3个用例,耗时')")
	if err != nil {
		t.Errorf("Wait exec workspace result fail: %v", err)
		t.FailNow()
	}
	locator, err = page.Locator("#log-list>>code:has-text('执行3个用例,耗时')")
	if err != nil {
		t.Errorf("Find exec workspace log fail: %v", err)
		t.FailNow()
	}
	innerText, err := locator.InnerText()
	if err != nil {
		t.Errorf("Find exec workspace result fail: %v", err)
		t.FailNow()
	}
	if !strings.Contains(innerText, "2(66.0%) 通过,1(33.0%) 失败") {
		t.Errorf("Exec workspace fail: %v", err)
		t.FailNow()
	}
	resultTitleElement, err := page.QuerySelector("#rightPane .result-list-item .list-item-title")
	if err != nil {
		t.Errorf("Find log title in logPane fail: %v", err)
		t.FailNow()
	}
	resultTitle, err := resultTitleElement.InnerText()
	if err != nil || resultTitle != "单元测试工作目录(3)" {
		t.Errorf("Find result in rightPane fail: %v", err)
		t.FailNow()
	}
	timeElement, err := page.Locator("#log-list>>.case-item:has-text('3_http_interface_call')>>.time>>span")
	if err != nil {
		t.Errorf("Find log time element in logPane fail: %v", err)
		t.FailNow()
	}
	logTime, err := timeElement.InnerText()
	if err != nil {
		t.Errorf("Find log time in logPane fail: %v", err)
		t.FailNow()
	}
	resultTimeElement, err := page.QuerySelector("#rightPane .result-list-item .list-item-trailing-text")
	if err != nil {
		t.Errorf("Find log time in rightPane fail: %v", err)
		t.FailNow()
	}
	resultTime, err := resultTimeElement.InnerText()
	if err != nil || logTime[:5] != resultTime {
		t.Errorf("Find result in rightPane fail: %v", err)
		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()
	}
}

雨爱无痕 已提交
1191
func TestUiRun(t *testing.T) {
雨爱无痕 已提交
1192 1193 1194 1195 1196 1197 1198 1199 1200
	runner.Run(t, "客户端-执行单个脚本", RunScript)
	runner.Run(t, "客户端-执行选中的脚本文件和文件夹", RunSelectedScripts)
	runner.Run(t, "客户端-执行打开的脚本文件", RunOpenedAndLast)
	runner.Run(t, "客户端-执行所有的脚本文件", RunAll)
	runner.Run(t, "客户端-结果中重新执行所有脚本", RunReExecAllCase)
	runner.Run(t, "客户端-结果中重新执行失败脚本", RunReExecFailCase)
	runner.Run(t, "客户端-确认执行统计成功数据", RunSuccessStatistic)
	runner.Run(t, "客户端-确认执行统计失败数据", RunFailStatistic)
	runner.Run(t, "客户端-确认执行统计bug数据", RunBugStatistic)
雨爱无痕 已提交
1201
	runner.Run(t, "客户端-右键执行工作目录", RunWorkspace)
雨爱无痕 已提交
1202
}