1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-11-23 21:54:45 +02:00

Feature/#229 wait no element (#249)

* Added possibility to wait for an element or a class absence
This commit is contained in:
Tim Voronov
2019-03-06 21:52:41 -05:00
committed by GitHub
parent 5188f9e71b
commit d0caef8be7
23 changed files with 385 additions and 102 deletions

View File

@@ -14,36 +14,39 @@ const defaultTimeout = 5000
func NewLib() map[string]core.Function {
return map[string]core.Function{
"CLICK": Click,
"CLICK_ALL": ClickAll,
"DOCUMENT": Document,
"DOWNLOAD": Download,
"ELEMENT": Element,
"ELEMENT_EXISTS": ElementExists,
"ELEMENTS": Elements,
"ELEMENTS_COUNT": ElementsCount,
"HOVER": Hover,
"INNER_HTML": InnerHTML,
"INNER_HTML_ALL": InnerHTMLAll,
"INNER_TEXT": InnerText,
"INNER_TEXT_ALL": InnerTextAll,
"INPUT": Input,
"MOUSE": MouseMoveXY,
"NAVIGATE": Navigate,
"NAVIGATE_BACK": NavigateBack,
"NAVIGATE_FORWARD": NavigateForward,
"PAGINATION": Pagination,
"PDF": PDF,
"SCREENSHOT": Screenshot,
"SCROLL": ScrollXY,
"SCROLL_BOTTOM": ScrollBottom,
"SCROLL_ELEMENT": ScrollInto,
"SCROLL_TOP": ScrollTop,
"SELECT": Select,
"WAIT_ELEMENT": WaitElement,
"WAIT_CLASS": WaitClass,
"WAIT_CLASS_ALL": WaitClassAll,
"WAIT_NAVIGATION": WaitNavigation,
"CLICK": Click,
"CLICK_ALL": ClickAll,
"DOCUMENT": Document,
"DOWNLOAD": Download,
"ELEMENT": Element,
"ELEMENT_EXISTS": ElementExists,
"ELEMENTS": Elements,
"ELEMENTS_COUNT": ElementsCount,
"HOVER": Hover,
"INNER_HTML": InnerHTML,
"INNER_HTML_ALL": InnerHTMLAll,
"INNER_TEXT": InnerText,
"INNER_TEXT_ALL": InnerTextAll,
"INPUT": Input,
"MOUSE": MouseMoveXY,
"NAVIGATE": Navigate,
"NAVIGATE_BACK": NavigateBack,
"NAVIGATE_FORWARD": NavigateForward,
"PAGINATION": Pagination,
"PDF": PDF,
"SCREENSHOT": Screenshot,
"SCROLL": ScrollXY,
"SCROLL_BOTTOM": ScrollBottom,
"SCROLL_ELEMENT": ScrollInto,
"SCROLL_TOP": ScrollTop,
"SELECT": Select,
"WAIT_ELEMENT": WaitElement,
"WAIT_NO_ELEMENT": WaitNoElement,
"WAIT_CLASS": WaitClass,
"WAIT_NO_CLASS": WaitNoClass,
"WAIT_CLASS_ALL": WaitClassAll,
"WAIT_NO_CLASS_ALL": WaitNoClassAll,
"WAIT_NAVIGATION": WaitNavigation,
}
}

View File

@@ -18,6 +18,23 @@ import (
// @param timeout (Int, optional) - If document is passed, this param must represent timeout.
// Otherwise not passed.
func WaitClass(ctx context.Context, args ...core.Value) (core.Value, error) {
return waitClassWhen(ctx, args, drivers.WaitEventPresence)
}
// WaitClass waits for a class to disappear on a given element.
// Stops the execution until the navigation ends or operation times out.
// @param docOrEl (HTMLDocument|HTMLElement) - Target document or element.
// @param selectorOrClass (String) - If document is passed, this param must represent an element selector.
// Otherwise target class.
// @param classOrTimeout (String|Int, optional) - If document is passed, this param must represent target class name.
// Otherwise timeout.
// @param timeout (Int, optional) - If document is passed, this param must represent timeout.
// Otherwise not passed.
func WaitNoClass(ctx context.Context, args ...core.Value) (core.Value, error) {
return waitClassWhen(ctx, args, drivers.WaitEventAbsence)
}
func waitClassWhen(ctx context.Context, args []core.Value, when drivers.WaitEvent) (core.Value, error) {
err := core.ValidateArgs(args, 2, 4)
if err != nil {
@@ -74,7 +91,7 @@ func WaitClass(ctx context.Context, args ...core.Value) (core.Value, error) {
ctx, fn := waitTimeout(ctx, timeout)
defer fn()
return values.None, doc.WaitForClassBySelector(ctx, selector, class)
return values.None, doc.WaitForClassBySelector(ctx, selector, class, when)
}
el := arg1.(drivers.HTMLElement)
@@ -93,5 +110,5 @@ func WaitClass(ctx context.Context, args ...core.Value) (core.Value, error) {
ctx, fn := waitTimeout(ctx, timeout)
defer fn()
return values.None, el.WaitForClass(ctx, class)
return values.None, el.WaitForClass(ctx, class, when)
}

View File

@@ -2,6 +2,7 @@ package html
import (
"context"
"github.com/MontFerret/ferret/pkg/drivers"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
"github.com/MontFerret/ferret/pkg/runtime/values/types"
@@ -14,6 +15,20 @@ import (
// @param class (String) - String of target CSS class.
// @param timeout (Int, optional) - Optional timeout.
func WaitClassAll(ctx context.Context, args ...core.Value) (core.Value, error) {
return waitClassAllWhen(ctx, args, drivers.WaitEventPresence)
}
// WaitClassAll waits for a class to disappear on all matched elements.
// Stops the execution until the navigation ends or operation times out.
// @param doc (HTMLDocument) - Parent document.
// @param selector (String) - String of CSS selector.
// @param class (String) - String of target CSS class.
// @param timeout (Int, optional) - Optional timeout.
func WaitNoClassAll(ctx context.Context, args ...core.Value) (core.Value, error) {
return waitClassAllWhen(ctx, args, drivers.WaitEventAbsence)
}
func waitClassAllWhen(ctx context.Context, args []core.Value, when drivers.WaitEvent) (core.Value, error) {
err := core.ValidateArgs(args, 3, 4)
if err != nil {
@@ -57,5 +72,5 @@ func WaitClassAll(ctx context.Context, args ...core.Value) (core.Value, error) {
ctx, fn := waitTimeout(ctx, timeout)
defer fn()
return values.None, doc.WaitForClassBySelectorAll(ctx, selector, class)
return values.None, doc.WaitForClassBySelectorAll(ctx, selector, class, when)
}

View File

@@ -2,6 +2,7 @@ package html
import (
"context"
"github.com/MontFerret/ferret/pkg/drivers"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
"github.com/MontFerret/ferret/pkg/runtime/values/types"
@@ -13,6 +14,19 @@ import (
// @param selector (String) - Target element's selector.
// @param timeout (Int, optional) - Optional timeout. Default 5000 ms.
func WaitElement(ctx context.Context, args ...core.Value) (core.Value, error) {
return waitElementWhen(ctx, args, drivers.WaitEventPresence)
}
// WaitNoElements waits for element to disappear in the DOM.
// Stops the execution until it does not find an element or operation times out.
// @param doc (HTMLDocument) - Driver HTMLDocument.
// @param selector (String) - Target element's selector.
// @param timeout (Int, optional) - Optional timeout. Default 5000 ms.
func WaitNoElement(ctx context.Context, args ...core.Value) (core.Value, error) {
return waitElementWhen(ctx, args, drivers.WaitEventAbsence)
}
func waitElementWhen(ctx context.Context, args []core.Value, when drivers.WaitEvent) (core.Value, error) {
err := core.ValidateArgs(args, 2, 3)
if err != nil {
@@ -41,5 +55,5 @@ func WaitElement(ctx context.Context, args ...core.Value) (core.Value, error) {
ctx, fn := waitTimeout(ctx, timeout)
defer fn()
return values.None, doc.WaitForSelector(ctx, values.NewString(selector))
return values.None, doc.WaitForElement(ctx, values.NewString(selector), when)
}