You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.5 KiB
60 lines
1.5 KiB
3 months ago
|
package tests
|
||
|
|
||
|
import (
|
||
3 months ago
|
"testing"
|
||
|
"context"
|
||
|
"log"
|
||
|
"time"
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
browser "github.com/chromedp/chromedp"
|
||
3 months ago
|
)
|
||
|
|
||
|
func Run(assert *assert.Assertions, ctx context.Context, actions ...browser.Action) {
|
||
3 months ago
|
err := browser.Run(ctx, actions...)
|
||
|
assert.NoError(err)
|
||
3 months ago
|
}
|
||
|
|
||
|
func Setup(timeout time.Duration) (context.Context, context.CancelFunc) {
|
||
|
|
||
3 months ago
|
opts := append(browser.DefaultExecAllocatorOptions[:],
|
||
|
browser.Flag("headless", false),)
|
||
|
|
||
|
allocCtx, _ := browser.NewExecAllocator(context.Background(), opts...)
|
||
|
|
||
|
ctx, _ := browser.NewContext(allocCtx, browser.WithLogf(log.Printf))
|
||
|
|
||
|
return context.WithTimeout(ctx, timeout * time.Second)
|
||
|
}
|
||
|
|
||
|
func TestLogin(t *testing.T) {
|
||
|
assert := assert.New(t)
|
||
|
|
||
|
ctx, cancel := Setup(5); defer cancel()
|
||
|
|
||
|
Run(assert, ctx,
|
||
|
browser.Navigate(`http://127.0.0.1:5002/login/`),
|
||
|
browser.WaitVisible(`body > footer`),
|
||
|
browser.WaitVisible(`[data-testid="login-page"]`),
|
||
|
browser.SendKeys(`#username`, `zedshaw`),
|
||
|
browser.SendKeys(`#password`, `1234`),
|
||
|
browser.Click(`#login-submit`, browser.NodeVisible),
|
||
|
browser.WaitVisible(`body > footer`),
|
||
|
browser.WaitVisible(`[data-testid="home-page"]`))
|
||
3 months ago
|
}
|
||
|
|
||
|
func TestStreamPage(t *testing.T) {
|
||
3 months ago
|
assert := assert.New(t)
|
||
3 months ago
|
|
||
3 months ago
|
ctx, cancel := Setup(20); defer cancel()
|
||
3 months ago
|
|
||
3 months ago
|
var example string
|
||
3 months ago
|
|
||
3 months ago
|
Run(assert, ctx,
|
||
3 months ago
|
browser.Navigate(`http://127.0.0.1:5001`),
|
||
3 months ago
|
browser.WaitVisible(`body > footer`),
|
||
|
browser.Click(`#streams`, browser.NodeVisible),
|
||
|
browser.Text(`#streams-title`, &example))
|
||
3 months ago
|
|
||
3 months ago
|
assert.Equal(example, "Past Streams")
|
||
3 months ago
|
}
|