Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2e Test Fixes #25058

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,6 @@ playwright: $(PLAYWRIGHT_DIR)

.PHONY: test-e2e%
test-e2e%: TEST_TYPE ?= e2e
# Clear display env variable. Otherwise, chromium tests can fail.
DISPLAY=

.PHONY: test-e2e
test-e2e: test-e2e-sqlite
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ Start tests based on the database container
TEST_MSSQL_HOST=localhost:1433 TEST_MSSQL_DBNAME=gitea_test TEST_MSSQL_USERNAME=sa TEST_MSSQL_PASSWORD=MwantsaSecurePassword1 make test-e2e-mssql
```

## Debug

Set `PLAYWRIGHT_DEBUG=1` to enable [visual debugging](https://playwright.dev/docs/debug#run-in-debug-mode-1).
kdumontnu marked this conversation as resolved.
Show resolved Hide resolved

## Running individual tests

Example command to run `example.test.e2e.js` test file:
Expand Down
56 changes: 34 additions & 22 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ func TestMain(m *testing.M) {

// TestE2e should be the only test e2e necessary. It will collect all "*.test.e2e.js" files in this directory and build a test for each.
func TestE2e(t *testing.T) {
browsers := []string{"chromium", "webkit", "Mobile Chrome", "Mobile Safari"}

// Find the paths of all e2e test files in test test directory.
searchGlob := filepath.Join(filepath.Dir(setting.AppPath), "tests", "e2e", "*.test.e2e.js")
paths, err := filepath.Glob(searchGlob)
Expand All @@ -91,30 +93,40 @@ func TestE2e(t *testing.T) {
runArgs = append(runArgs, "--update-snapshots")
}

// If debug flag is set
if _, set := os.LookupEnv("PLAYWRIGHT_DEBUG"); set {
runArgs = append(runArgs, "--debug")
}

// Create new test for each input file
for _, path := range paths {
_, filename := filepath.Split(path)
testname := filename[:len(filename)-len(filepath.Ext(path))]

t.Run(testname, func(t *testing.T) {
// Default 2 minute timeout
onGiteaRun(t, func(*testing.T, *url.URL) {
cmd := exec.Command(runArgs[0], runArgs...)
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, fmt.Sprintf("GITEA_URL=%s", setting.AppURL))
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err := cmd.Run()
if err != nil {
// Currently colored output is conflicting. Using Printf until that is resolved.
fmt.Printf("%v", stdout.String())
fmt.Printf("%v", stderr.String())
log.Fatal("Playwright Failed: %s", err)
} else {
fmt.Printf("%v", stdout.String())
}
// Iterate each browser serially to reset the fixtures
// TODO: parallel tests with separate environments?
for _, browser := range browsers {
_, filename := filepath.Split(path)
testname := filename[:len(filename)-len(filepath.Ext(path))]

t.Run(testname+"/"+browser, func(t *testing.T) {
// Default 2 minute timeout
onGiteaRun(t, func(*testing.T, *url.URL) {
// Finally, append the testname to only run the current test
cmd := exec.Command(runArgs[0], append(runArgs[1:], "--project="+browser, testname)...)
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, fmt.Sprintf("GITEA_URL=%s", setting.AppURL))
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err := cmd.Run()
if err != nil {
// Currently colored output is conflicting. Using Printf until that is resolved.
fmt.Printf("%v", stdout.String())
fmt.Printf("%v", stderr.String())
log.Fatal("Playwright Failed: %s", err)
} else {
fmt.Printf("%v", stdout.String())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surposed ths fmt.Printf passes the linter.

}
})
})
})
}
}
}