Test can now attempt a login and the browser is shown rather than headless.
This commit is contained in:
parent
e29c36fb5c
commit
831b5ea762
6 changed files with 156 additions and 19 deletions
|
@ -1,36 +1,59 @@
|
|||
package tests
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"context"
|
||||
"time"
|
||||
"github.com/stretchr/testify/assert"
|
||||
browser "github.com/chromedp/chromedp"
|
||||
"testing"
|
||||
"context"
|
||||
"log"
|
||||
"time"
|
||||
"github.com/stretchr/testify/assert"
|
||||
browser "github.com/chromedp/chromedp"
|
||||
)
|
||||
|
||||
func Run(assert *assert.Assertions, ctx context.Context, actions ...browser.Action) {
|
||||
err := browser.Run(ctx, actions...)
|
||||
assert.NoError(err)
|
||||
err := browser.Run(ctx, actions...)
|
||||
assert.NoError(err)
|
||||
}
|
||||
|
||||
func Setup(timeout time.Duration) (context.Context, context.CancelFunc) {
|
||||
ctx, _ := browser.NewContext(context.Background())
|
||||
|
||||
return context.WithTimeout(ctx, timeout * time.Second)
|
||||
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"]`))
|
||||
}
|
||||
|
||||
func TestStreamPage(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
assert := assert.New(t)
|
||||
|
||||
ctx, cancel := Setup(20); defer cancel()
|
||||
ctx, cancel := Setup(20); defer cancel()
|
||||
|
||||
var example string
|
||||
var example string
|
||||
|
||||
Run(assert, ctx,
|
||||
browser.Navigate(`http://127.0.0.1:5002`),
|
||||
browser.WaitVisible(`body > footer`),
|
||||
browser.Click(`#streams`, browser.NodeVisible),
|
||||
browser.Text(`#streams-title`, &example))
|
||||
Run(assert, ctx,
|
||||
browser.Navigate(`http://127.0.0.1:5002`),
|
||||
browser.WaitVisible(`body > footer`),
|
||||
browser.Click(`#streams`, browser.NodeVisible),
|
||||
browser.Text(`#streams-title`, &example))
|
||||
|
||||
assert.Equal(example, "Past Streams")
|
||||
assert.Equal(example, "Past Streams")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue