Forgot the tools file
This commit is contained in:
parent
db9697130e
commit
0bccddc62c
1 changed files with 37 additions and 0 deletions
37
tests/tools.go
Normal file
37
tests/tools.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
package tests
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"time"
|
||||
"runtime"
|
||||
"github.com/stretchr/testify/assert"
|
||||
browser "github.com/chromedp/chromedp"
|
||||
)
|
||||
|
||||
func Setup(timeout time.Duration) (context.Context, context.CancelFunc) {
|
||||
opts := append(browser.DefaultExecAllocatorOptions[:],
|
||||
browser.Flag("headless", runtime.GOOS == "windows"),)
|
||||
|
||||
ctx, cancel := browser.NewExecAllocator(context.Background(), opts...)
|
||||
|
||||
ctx, _ = browser.NewContext(ctx, browser.WithLogf(log.Printf))
|
||||
|
||||
ctx, _ = context.WithTimeout(ctx, timeout * time.Second)
|
||||
|
||||
return ctx, cancel
|
||||
}
|
||||
|
||||
func ClickOn(assert *assert.Assertions, ctx context.Context, id string) {
|
||||
err := browser.Run(ctx, browser.WaitVisible(`#streams`),)
|
||||
assert.NoError(err)
|
||||
|
||||
resp, err := browser.RunResponse(ctx, browser.Click(id, browser.ByID))
|
||||
assert.Equal(resp.Status, int64(200))
|
||||
assert.NoError(err)
|
||||
}
|
||||
|
||||
func Run(assert *assert.Assertions, ctx context.Context, actions ...browser.Action) {
|
||||
err := browser.Run(ctx, actions...)
|
||||
assert.NoError(err)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue