-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgithub.go
More file actions
77 lines (67 loc) · 1.89 KB
/
github.go
File metadata and controls
77 lines (67 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// nolint
package main
/*
Example on how to use locatr with playwright to interact with github.
*/
import (
"context"
"fmt"
"log"
"os"
"time"
"github.com/playwright-community/playwright-go"
locatr "github.com/vertexcover-io/locatr/golang"
"github.com/vertexcover-io/locatr/golang/llm"
"github.com/vertexcover-io/locatr/golang/playwrightLocatr"
)
func main() {
pw, err := playwright.Run()
if err != nil {
log.Fatalf("could not start playwright: %v", err)
}
defer pw.Stop()
browser, err := pw.Chromium.Launch(
playwright.BrowserTypeLaunchOptions{
Headless: playwright.Bool(false),
},
)
if err != nil {
log.Fatalf("could not launch browser: %v", err)
}
defer browser.Close()
page, err := browser.NewPage()
if err != nil {
log.Fatalf("could not create page: %v", err)
}
if _, err := page.Goto("https://github.com/vertexcover-io/locatr"); err != nil {
log.Fatalf("could not navigate to docker hub: %v", err)
}
time.Sleep(5 * time.Second) // wait for page to load
llmClient, err := llm.NewLlmClient(
llm.OpenAI, // (openai | anthropic),
os.Getenv("LLM_MODEL_NAME"),
os.Getenv("LLM_API_KEY"),
)
if err != nil {
log.Fatalf("could not create llm client: %v", err)
}
options := locatr.BaseLocatrOptions{UseCache: true, LlmClient: llmClient}
ctx := context.Background()
locatr := playwrightLocatr.NewPlaywrightLocatr(ctx, page, options)
cDropDownLoc, err := locatr.GetLocatr(ctx, "<> Code dropdown")
if err != nil {
log.Fatalf("could not get locator: %v", err)
return
}
if err := page.Locator(cDropDownLoc.Selectors[0]).Click(); err != nil {
log.Fatalf("could not click on code dropdown: %v", err)
return
}
dZipLoc, err := locatr.GetLocatr(ctx, "Download ZIP button on the opened dropdown")
if err != nil {
log.Fatalf("could not get download ZIP locator: %v", err)
return
}
fmt.Println(page.Locator(dZipLoc.Selectors[0]).InnerHTML())
time.Sleep(5 * time.Second)
}