Skip to content

Commit 778715c

Browse files
committed
feat: add Goto Action to navigate to another url
1 parent 59e9454 commit 778715c

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

executors/playwright/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@ testcases:
4747
|Type |**querySelector** TEXT | Type "#element" |
4848
|WaitFor |**querySelector**| WaitFor "#element" |
4949
|WaitForSelector |**querySelector**| WaitForSelector "#element" |
50+
|Goto |**REGEX**| Goto "^some-page" |
5051
|WaitForURL |**REGEX**| WaitForURL "^some-page" |

executors/playwright/actions.go

+23
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package playwright
22

33
import (
44
"fmt"
5+
"net/url"
56
"strings"
67

78
playwrightgo "github.com/playwright-community/playwright-go"
@@ -28,6 +29,7 @@ var actionMap = map[string]ActionFunc{
2829
"WaitFor": WaitForSelectorAction,
2930
"WaitForSelector": WaitForSelectorAction,
3031
"WaitForURL": WaitForURLAction,
32+
"Goto": GotoAction,
3133
}
3234

3335
func removeQuotes(selector string) string {
@@ -130,3 +132,24 @@ func UncheckAction(page playwrightgo.Page, element string, target ...any) error
130132
// TODO: support passing Uncheck options
131133
return page.Locator(element).First().Uncheck()
132134
}
135+
136+
func GotoAction(page playwrightgo.Page, urlPattern string, target ...any) error {
137+
timeout := 10_000.00
138+
finalURL := urlPattern
139+
if strings.HasPrefix(urlPattern, "/") { // relative url
140+
parsedURL, err := url.Parse(page.URL())
141+
if err != nil {
142+
return err
143+
}
144+
u, err := parsedURL.Parse(urlPattern)
145+
if err != nil {
146+
return err
147+
}
148+
finalURL = u.String()
149+
}
150+
_, err := page.Goto(finalURL, playwrightgo.PageGotoOptions{
151+
Timeout: &timeout,
152+
WaitUntil: playwrightgo.WaitUntilStateCommit,
153+
})
154+
return err
155+
}

0 commit comments

Comments
 (0)