2019-02-20 01:10:18 +02:00
|
|
|
package drivers
|
|
|
|
|
|
|
|
import (
|
2019-02-21 04:24:05 +02:00
|
|
|
"context"
|
2019-02-20 01:10:18 +02:00
|
|
|
"io"
|
|
|
|
|
|
|
|
"github.com/MontFerret/ferret/pkg/runtime/collections"
|
|
|
|
"github.com/MontFerret/ferret/pkg/runtime/core"
|
|
|
|
"github.com/MontFerret/ferret/pkg/runtime/values"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
2019-03-07 04:52:41 +02:00
|
|
|
// WaitEvent is an enum that represents what event is needed to wait for
|
|
|
|
WaitEvent int
|
|
|
|
|
2019-02-20 01:10:18 +02:00
|
|
|
// Node is an interface from which a number of DOM API object types inherit.
|
|
|
|
// It allows those types to be treated similarly;
|
|
|
|
// for example, inheriting the same set of methods, or being tested in the same way.
|
|
|
|
HTMLNode interface {
|
|
|
|
core.Value
|
|
|
|
core.Iterable
|
|
|
|
core.Getter
|
|
|
|
core.Setter
|
|
|
|
collections.Measurable
|
|
|
|
io.Closer
|
|
|
|
|
|
|
|
NodeType() values.Int
|
|
|
|
|
|
|
|
NodeName() values.String
|
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
GetChildNodes(ctx context.Context) core.Value
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
GetChildNode(ctx context.Context, idx values.Int) core.Value
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
QuerySelector(ctx context.Context, selector values.String) core.Value
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
QuerySelectorAll(ctx context.Context, selector values.String) core.Value
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
CountBySelector(ctx context.Context, selector values.String) values.Int
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
ExistsBySelector(ctx context.Context, selector values.String) values.Boolean
|
2019-02-20 01:10:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// HTMLElement is the most general base interface which most objects in a Document implement.
|
|
|
|
HTMLElement interface {
|
|
|
|
HTMLNode
|
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
InnerText(ctx context.Context) values.String
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
InnerHTML(ctx context.Context) values.String
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
GetValue(ctx context.Context) core.Value
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
SetValue(ctx context.Context, value core.Value) error
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-26 04:46:39 +02:00
|
|
|
GetAttributes(ctx context.Context) *values.Object
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
GetAttribute(ctx context.Context, name values.String) core.Value
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
SetAttribute(ctx context.Context, name, value values.String) error
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
InnerHTMLBySelector(ctx context.Context, selector values.String) values.String
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
InnerHTMLBySelectorAll(ctx context.Context, selector values.String) *values.Array
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
InnerTextBySelector(ctx context.Context, selector values.String) values.String
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
InnerTextBySelectorAll(ctx context.Context, selector values.String) *values.Array
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
Click(ctx context.Context) (values.Boolean, error)
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
Input(ctx context.Context, value core.Value, delay values.Int) error
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
Select(ctx context.Context, value *values.Array) (*values.Array, error)
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
ScrollIntoView(ctx context.Context) error
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
Hover(ctx context.Context) error
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-03-07 04:52:41 +02:00
|
|
|
WaitForClass(ctx context.Context, class values.String, when WaitEvent) error
|
2019-02-20 01:10:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// The Document interface represents any web page loaded in the browser
|
|
|
|
// and serves as an entry point into the web page's content, which is the DOM tree.
|
|
|
|
HTMLDocument interface {
|
|
|
|
HTMLNode
|
|
|
|
|
|
|
|
DocumentElement() HTMLElement
|
|
|
|
|
|
|
|
GetURL() core.Value
|
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
SetURL(ctx context.Context, url values.String) error
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
Navigate(ctx context.Context, url values.String) error
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
NavigateBack(ctx context.Context, skip values.Int) (values.Boolean, error)
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
NavigateForward(ctx context.Context, skip values.Int) (values.Boolean, error)
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
ClickBySelector(ctx context.Context, selector values.String) (values.Boolean, error)
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
ClickBySelectorAll(ctx context.Context, selector values.String) (values.Boolean, error)
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
InputBySelector(ctx context.Context, selector values.String, value core.Value, delay values.Int) (values.Boolean, error)
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
SelectBySelector(ctx context.Context, selector values.String, value *values.Array) (*values.Array, error)
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
PrintToPDF(ctx context.Context, params PDFParams) (values.Binary, error)
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
CaptureScreenshot(ctx context.Context, params ScreenshotParams) (values.Binary, error)
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
ScrollTop(ctx context.Context) error
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
ScrollBottom(ctx context.Context) error
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
ScrollBySelector(ctx context.Context, selector values.String) error
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-02-24 00:52:01 +02:00
|
|
|
ScrollByXY(ctx context.Context, x, y values.Float) error
|
|
|
|
|
|
|
|
MoveMouseByXY(ctx context.Context, x, y values.Float) error
|
|
|
|
|
|
|
|
MoveMouseBySelector(ctx context.Context, selector values.String) error
|
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
WaitForNavigation(ctx context.Context) error
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-03-07 04:52:41 +02:00
|
|
|
WaitForElement(ctx context.Context, selector values.String, when WaitEvent) error
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-03-07 04:52:41 +02:00
|
|
|
WaitForClassBySelector(ctx context.Context, selector, class values.String, when WaitEvent) error
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-03-07 04:52:41 +02:00
|
|
|
WaitForClassBySelectorAll(ctx context.Context, selector, class values.String, when WaitEvent) error
|
2019-02-20 01:10:18 +02:00
|
|
|
}
|
|
|
|
)
|
2019-03-07 04:52:41 +02:00
|
|
|
|
|
|
|
const (
|
|
|
|
// Event indicating to wait for value to appear
|
|
|
|
WaitEventPresence = 0
|
|
|
|
|
|
|
|
// Event indicating to wait for value to disappear
|
|
|
|
WaitEventAbsence = 1
|
|
|
|
)
|