Now easier to write tests for the app, and most pages are at least touched.
This commit is contained in:
parent
d095bc9ff4
commit
ecc264db8c
14 changed files with 124 additions and 89 deletions
|
|
@ -5,7 +5,7 @@ import (
|
|||
"log"
|
||||
"time"
|
||||
"runtime"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
browser "github.com/chromedp/chromedp"
|
||||
)
|
||||
|
||||
|
|
@ -22,16 +22,39 @@ func Setup(timeout time.Duration) (context.Context, context.CancelFunc) {
|
|||
return ctx, cancel
|
||||
}
|
||||
|
||||
func ClickOn(assert *assert.Assertions, ctx context.Context, id string) {
|
||||
err := browser.Run(ctx, browser.WaitVisible(`#streams`),)
|
||||
assert.NoError(err)
|
||||
func ClickOn(require *require.Assertions, ctx context.Context, id string) {
|
||||
err := browser.Run(ctx, browser.WaitVisible(id),)
|
||||
require.NoError(err)
|
||||
|
||||
resp, err := browser.RunResponse(ctx, browser.Click(id, browser.ByID))
|
||||
assert.Equal(resp.Status, int64(200))
|
||||
assert.NoError(err)
|
||||
resp, err := browser.RunResponse(ctx,
|
||||
browser.WaitVisible(id),
|
||||
browser.Click(id))
|
||||
|
||||
require.NoError(err)
|
||||
require.Equal(resp.Status, int64(200))
|
||||
}
|
||||
|
||||
func Run(assert *assert.Assertions, ctx context.Context, actions ...browser.Action) {
|
||||
func GoTo(require *require.Assertions, ctx context.Context, path string, expect string) {
|
||||
err := browser.Run(ctx,
|
||||
browser.Navigate(`http://127.0.0.1:5002`),
|
||||
browser.WaitVisible(`body > footer`),
|
||||
browser.WaitVisible(expect))
|
||||
require.NoError(err)
|
||||
}
|
||||
|
||||
func WaitFor(require *require.Assertions, ctx context.Context, expect string) {
|
||||
err := browser.Run(ctx, browser.WaitVisible(expect))
|
||||
require.NoError(err)
|
||||
}
|
||||
|
||||
func ExpectText(require *require.Assertions, ctx context.Context, target string, expect string) {
|
||||
var extracted string
|
||||
err := browser.Run(ctx, browser.Text(target, &extracted))
|
||||
require.NoError(err)
|
||||
require.Equal(expect, extracted)
|
||||
}
|
||||
|
||||
func Run(require *require.Assertions, ctx context.Context, actions ...browser.Action) {
|
||||
err := browser.Run(ctx, actions...)
|
||||
assert.NoError(err)
|
||||
require.NoError(err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue