-
-
Notifications
You must be signed in to change notification settings - Fork 179
/
Copy pathframe_locator.go
130 lines (113 loc) · 3.53 KB
/
frame_locator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package playwright
import (
"errors"
"fmt"
"strconv"
)
type frameLocatorImpl struct {
frame *frameImpl
frameSelector string
}
func newFrameLocator(frame *frameImpl, frameSelector string) *frameLocatorImpl {
return &frameLocatorImpl{frame: frame, frameSelector: frameSelector}
}
func (fl *frameLocatorImpl) First() FrameLocator {
return newFrameLocator(fl.frame, fl.frameSelector+" >> nth=0")
}
func (fl *frameLocatorImpl) FrameLocator(selector string) FrameLocator {
return newFrameLocator(fl.frame, fl.frameSelector+" >> internal:control=enter-frame >> "+selector)
}
func (fl *frameLocatorImpl) GetByAltText(text interface{}, options ...FrameLocatorGetByAltTextOptions) Locator {
exact := false
if len(options) == 1 {
if *options[0].Exact {
exact = true
}
}
return fl.Locator(getByAltTextSelector(text, exact))
}
func (fl *frameLocatorImpl) GetByLabel(text interface{}, options ...FrameLocatorGetByLabelOptions) Locator {
exact := false
if len(options) == 1 {
if *options[0].Exact {
exact = true
}
}
return fl.Locator(getByLabelSelector(text, exact))
}
func (fl *frameLocatorImpl) GetByPlaceholder(text interface{}, options ...FrameLocatorGetByPlaceholderOptions) Locator {
exact := false
if len(options) == 1 {
if *options[0].Exact {
exact = true
}
}
return fl.Locator(getByPlaceholderSelector(text, exact))
}
func (fl *frameLocatorImpl) GetByRole(role AriaRole, options ...FrameLocatorGetByRoleOptions) Locator {
if len(options) == 1 {
return fl.Locator(getByRoleSelector(role, LocatorGetByRoleOptions(options[0])))
}
return fl.Locator(getByRoleSelector(role))
}
func (fl *frameLocatorImpl) GetByTestId(testId interface{}) Locator {
return fl.Locator(getByTestIdSelector(getTestIdAttributeName(), testId))
}
func (fl *frameLocatorImpl) GetByText(text interface{}, options ...FrameLocatorGetByTextOptions) Locator {
exact := false
if len(options) == 1 {
if *options[0].Exact {
exact = true
}
}
return fl.Locator(getByTextSelector(text, exact))
}
func (fl *frameLocatorImpl) GetByTitle(text interface{}, options ...FrameLocatorGetByTitleOptions) Locator {
exact := false
if len(options) == 1 {
if *options[0].Exact {
exact = true
}
}
return fl.Locator(getByTitleSelector(text, exact))
}
func (fl *frameLocatorImpl) Last() FrameLocator {
return newFrameLocator(fl.frame, fl.frameSelector+" >> nth=-1")
}
func (fl *frameLocatorImpl) Locator(selectorOrLocator interface{}, options ...FrameLocatorLocatorOptions) Locator {
var option LocatorOptions
if len(options) == 1 {
option = LocatorOptions{
Has: options[0].Has,
HasNot: options[0].HasNot,
HasText: options[0].HasText,
HasNotText: options[0].HasNotText,
}
}
selector, ok := selectorOrLocator.(string)
if ok {
return newLocator(fl.frame, fl.frameSelector+" >> internal:control=enter-frame >> "+selector, option)
}
locator, ok := selectorOrLocator.(*locatorImpl)
if ok {
if fl.frame != locator.frame {
locator.err = errors.Join(locator.err, ErrLocatorNotSameFrame)
return locator
}
return newLocator(locator.frame,
fmt.Sprintf("%s >> internal:control=enter-frame >> %s", fl.frameSelector, locator.selector),
option,
)
}
return &locatorImpl{
frame: fl.frame,
selector: fl.frameSelector,
err: fmt.Errorf("invalid locator parameter: %v", selectorOrLocator),
}
}
func (fl *frameLocatorImpl) Nth(index int) FrameLocator {
return newFrameLocator(fl.frame, fl.frameSelector+" >> nth="+strconv.Itoa(index))
}
func (fl *frameLocatorImpl) Owner() Locator {
return newLocator(fl.frame, fl.frameSelector)
}