@@ -103,7 +103,7 @@ func (Executor) Run(ctx context.Context, step venom.TestStep) (interface{}, erro
103
103
return nil , fmt .Errorf ("could not goto: %w" , err )
104
104
}
105
105
106
- err = performActions (page , e .Actions )
106
+ err = performActions (ctx , page , e .Actions )
107
107
if err != nil {
108
108
return nil , err
109
109
}
@@ -112,7 +112,6 @@ func (Executor) Run(ctx context.Context, step venom.TestStep) (interface{}, erro
112
112
if err != nil {
113
113
return nil , fmt .Errorf ("could not goto: %w" , err )
114
114
}
115
- // TODO: run the assertions in here ...
116
115
117
116
err = browser .Close ()
118
117
if err != nil {
@@ -135,25 +134,44 @@ func (Executor) Run(ctx context.Context, step venom.TestStep) (interface{}, erro
135
134
}, nil
136
135
}
137
136
138
- func performActions (page playwrightgo.Page , actions []string ) error {
137
+ // parseActionLine parses a line containing an Action expression and returns
138
+ // the actionName, the arguments (rest of the line), the actionFunc or an error
139
+ func parseActionLine (actionLine string ) (string , string , ActionFunc , error ) {
140
+ if actionLine == "" {
141
+ return "" , "" , nil , fmt .Errorf ("action line MUST not be empty" )
142
+ }
143
+ parts := strings .SplitN (strings .TrimSpace (actionLine ), " " , 2 )
144
+ if len (parts ) < 2 {
145
+ return "" , "" , nil , fmt .Errorf ("action line MUST have atleast two arguments: ACTION <selector>" )
146
+ }
147
+ actionName , arguments := parts [0 ], parts [1 ]
148
+ actionFunc , ok := actionMap [actionName ]
149
+ if ! ok {
150
+ return "" , "" , nil , fmt .Errorf ("invalid or unsupported action specified '%s'" , actionName )
151
+ }
152
+ return actionName , arguments , actionFunc , nil
153
+ }
154
+
155
+ func performActions (ctx context.Context , page playwrightgo.Page , actions []string ) error {
139
156
for _ , action := range actions {
140
- fmt .Println ("perform action step" , action )
141
- parts := strings .SplitN (strings .TrimSpace (action ), " " , 2 )
142
- actionName , arguments := parts [0 ], parts [1 ]
143
- actionFunc , ok := actionMap [actionName ]
144
- if ! ok {
145
- return fmt .Errorf ("invalid or unsupported action specified '%s'" , actionName )
157
+ actionName , arguments , actionFunc , err := parseActionLine (action )
158
+ if err != nil {
159
+ return err
146
160
}
161
+
162
+ venom .Debug (ctx , fmt .Sprintf ("perform action '%s' with arguments '%v'\n " , actionName , arguments ))
163
+
147
164
selectorAndArgs := strings .SplitN (strings .TrimSpace (arguments ), " " , 2 )
148
165
selector := removeQuotes (selectorAndArgs [0 ])
149
- var err error
166
+
167
+ var actErr error
150
168
if len (selectorAndArgs ) <= 1 {
151
- err = actionFunc (page , selector , nil )
169
+ actErr = actionFunc (page , selector , nil )
152
170
} else {
153
- err = actionFunc (page , selector , removeQuotes (selectorAndArgs [1 ]))
171
+ actErr = actionFunc (page , selector , removeQuotes (selectorAndArgs [1 ]))
154
172
}
155
- if err != nil {
156
- return err
173
+ if actErr != nil {
174
+ return actErr
157
175
}
158
176
}
159
177
return nil
0 commit comments