.\tests\tools.go
This commit is contained in:
parent
74edb069d2
commit
db9697130e
1 changed files with 1 additions and 31 deletions
|
|
@ -2,40 +2,10 @@ package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
"context"
|
|
||||||
"log"
|
|
||||||
"time"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
browser "github.com/chromedp/chromedp"
|
browser "github.com/chromedp/chromedp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Run(assert *assert.Assertions, ctx context.Context, actions ...browser.Action) {
|
|
||||||
err := browser.Run(ctx, actions...)
|
|
||||||
assert.NoError(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Setup(timeout time.Duration) (context.Context, context.CancelFunc) {
|
|
||||||
opts := append(browser.DefaultExecAllocatorOptions[:],
|
|
||||||
browser.Flag("headless", false),)
|
|
||||||
|
|
||||||
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 TestLogin(t *testing.T) {
|
func TestLogin(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
|
@ -67,7 +37,7 @@ func TestStreamPage(t *testing.T) {
|
||||||
)
|
)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
ClickOn(assert, ctx, `#streams`)
|
ClickOn(assert, ctx, `#streams`)
|
||||||
|
|
||||||
err = browser.Run(ctx, browser.WaitVisible(`#streams-title`))
|
err = browser.Run(ctx, browser.WaitVisible(`#streams-title`))
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue