This repository was archived by the owner on Jan 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Add lifecycle event validation to WaitForLoadState
#300
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1d32ee4
Add lifecycle event validation to WaitForLoadState
cbac709
Validate FrameWaitForNavigation WaitUntil using UnmarshalText
707c3b9
Validate FrameGoto WaitUntil using UnmarshalText
62fa217
Validate FrameSetContent WaitUntil using UnmarshalText
a526dd9
Fix defaulting to load in WaitForLoadState
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package common | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestFrameGotoOptionsParse(t *testing.T) { | ||
t.Parallel() | ||
|
||
t.Run("ok", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
mockVU := newMockVU(t) | ||
opts := mockVU.RuntimeField.ToValue(map[string]interface{}{ | ||
"timeout": "1000", | ||
"waitUntil": "networkidle", | ||
}) | ||
gotoOpts := NewFrameGotoOptions("https://example.com/", 0) | ||
err := gotoOpts.Parse(mockVU.CtxField, opts) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, "https://example.com/", gotoOpts.Referer) | ||
assert.Equal(t, time.Second, gotoOpts.Timeout) | ||
assert.Equal(t, LifecycleEventNetworkIdle, gotoOpts.WaitUntil) | ||
}) | ||
|
||
t.Run("err/invalid_waitUntil", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
mockVU := newMockVU(t) | ||
opts := mockVU.RuntimeField.ToValue(map[string]interface{}{ | ||
"waitUntil": "none", | ||
}) | ||
navOpts := NewFrameGotoOptions("", 0) | ||
err := navOpts.Parse(mockVU.CtxField, opts) | ||
|
||
assert.EqualError(t, err, | ||
`error parsing goto options: `+ | ||
`invalid lifecycle event: "none"; must be one of: `+ | ||
`load, domcontentloaded, networkidle`) | ||
}) | ||
} | ||
|
||
func TestFrameSetContentOptionsParse(t *testing.T) { | ||
t.Parallel() | ||
|
||
t.Run("ok", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
mockVU := newMockVU(t) | ||
opts := mockVU.RuntimeField.ToValue(map[string]interface{}{ | ||
"waitUntil": "networkidle", | ||
}) | ||
scOpts := NewFrameSetContentOptions(30 * time.Second) | ||
err := scOpts.Parse(mockVU.CtxField, opts) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, 30*time.Second, scOpts.Timeout) | ||
assert.Equal(t, LifecycleEventNetworkIdle, scOpts.WaitUntil) | ||
}) | ||
|
||
t.Run("err/invalid_waitUntil", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
mockVU := newMockVU(t) | ||
opts := mockVU.RuntimeField.ToValue(map[string]interface{}{ | ||
"waitUntil": "none", | ||
}) | ||
navOpts := NewFrameSetContentOptions(0) | ||
err := navOpts.Parse(mockVU.CtxField, opts) | ||
|
||
assert.EqualError(t, err, | ||
`error parsing setContent options: `+ | ||
`invalid lifecycle event: "none"; must be one of: `+ | ||
`load, domcontentloaded, networkidle`) | ||
}) | ||
} | ||
|
||
func TestFrameWaitForNavigationOptionsParse(t *testing.T) { | ||
t.Parallel() | ||
|
||
t.Run("ok", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
mockVU := newMockVU(t) | ||
opts := mockVU.RuntimeField.ToValue(map[string]interface{}{ | ||
"url": "https://example.com/", | ||
"timeout": "1000", | ||
"waitUntil": "networkidle", | ||
}) | ||
navOpts := NewFrameWaitForNavigationOptions(0) | ||
err := navOpts.Parse(mockVU.CtxField, opts) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, "https://example.com/", navOpts.URL) | ||
assert.Equal(t, time.Second, navOpts.Timeout) | ||
assert.Equal(t, LifecycleEventNetworkIdle, navOpts.WaitUntil) | ||
}) | ||
|
||
t.Run("err/invalid_waitUntil", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
mockVU := newMockVU(t) | ||
opts := mockVU.RuntimeField.ToValue(map[string]interface{}{ | ||
"waitUntil": "none", | ||
}) | ||
navOpts := NewFrameWaitForNavigationOptions(0) | ||
err := navOpts.Parse(mockVU.CtxField, opts) | ||
|
||
assert.EqualError(t, err, | ||
`error parsing waitForNavigation options: `+ | ||
`invalid lifecycle event: "none"; must be one of: `+ | ||
`load, domcontentloaded, networkidle`) | ||
}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.