1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-16 11:37:36 +02:00
ferret/pkg/drivers/cdp/templates/wait_by_selector_all.go
Tim Voronov 82f7317ebe
Feature/#250 wait style (#257)
* Added WAIT_ATTR functions
2019-03-13 22:50:29 -04:00

44 lines
899 B
Go

package templates
import (
"fmt"
"github.com/MontFerret/ferret/pkg/drivers/cdp/eval"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
"github.com/MontFerret/ferret/pkg/drivers"
)
func WaitBySelectorAll(selector values.String, when drivers.WaitEvent, value core.Value, check string) string {
return fmt.Sprintf(`
var elements = document.querySelectorAll(%s); // selector
if (elements == null || elements.length === 0) {
return false;
}
var resultCount = 0;
elements.forEach((el) => {
var result = %s; // check
// when
if (result %s %s) {
resultCount++;
}
});
if (resultCount === elements.length) {
return true;
}
// null means we need to repeat
return null;
`,
eval.ParamString(selector.String()),
check,
WaitEventToEqOperator(when),
eval.Param(value),
)
}