This repository has been 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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We now support creating a locator using one of page.locator and frame.locator. This commit adds a simple unit test to verify whether we can create locators using the mentioned methods. However, the test is not that useful, we can remove it later when we add integration tests.
- Loading branch information
1 parent
0708178
commit 8f880f7
Showing
7 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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,4 @@ | ||
package api | ||
|
||
// Locator represents a way to find element(s) on a page at any moment. | ||
type Locator interface{} |
This file contains 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 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 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,25 @@ | ||
package common | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
// Locator represent a way to find element(s) on the page at any moment. | ||
type Locator struct { | ||
selector string | ||
|
||
frame *Frame | ||
|
||
ctx context.Context | ||
log *Logger | ||
} | ||
|
||
// NewLocator creates and returns a new locator. | ||
func NewLocator(ctx context.Context, selector string, f *Frame, l *Logger) *Locator { | ||
return &Locator{ | ||
selector: selector, | ||
frame: f, | ||
ctx: ctx, | ||
log: l, | ||
} | ||
} |
This file contains 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 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,31 @@ | ||
package common | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// TestPageLocator can be removed later on when we add integration | ||
// tests. Since we don't yet have any of them, it makes sense to keep | ||
// this test. | ||
func TestPageLocator(t *testing.T) { | ||
const ( | ||
wantMainFrameID = "1" | ||
wantSelector = "span" | ||
) | ||
ctx := context.TODO() | ||
p := &Page{ | ||
ctx: ctx, | ||
frameManager: &FrameManager{ | ||
ctx: ctx, | ||
mainFrame: &Frame{id: wantMainFrameID, ctx: ctx}, | ||
}, | ||
} | ||
l := p.Locator(wantSelector, nil).(*Locator) //nolint:forcetypeassert | ||
assert.Equal(t, wantSelector, l.selector) | ||
assert.Equal(t, wantMainFrameID, string(l.frame.id)) | ||
|
||
// other behavior will be tested via integration tests | ||
} |