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
|
|
|
|
|
2019-06-19 23:58:56 +02:00
|
|
|
IsDetached() values.Boolean
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-06-19 23:58:56 +02:00
|
|
|
GetNodeType() values.Int
|
|
|
|
|
|
|
|
GetNodeName() values.String
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-09-07 03:02:41 +02:00
|
|
|
GetChildNodes(ctx context.Context) (*values.Array, error)
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-09-07 03:02:41 +02:00
|
|
|
GetChildNode(ctx context.Context, idx values.Int) (core.Value, error)
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-09-07 03:02:41 +02:00
|
|
|
QuerySelector(ctx context.Context, selector values.String) (core.Value, error)
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-09-07 03:02:41 +02:00
|
|
|
QuerySelectorAll(ctx context.Context, selector values.String) (*values.Array, error)
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-09-07 03:02:41 +02:00
|
|
|
CountBySelector(ctx context.Context, selector values.String) (values.Int, error)
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-07-26 19:22:06 +02:00
|
|
|
ExistsBySelector(ctx context.Context, selector values.String) (values.Boolean, error)
|
2019-07-03 20:05:02 +02:00
|
|
|
|
|
|
|
XPath(ctx context.Context, expression values.String) (core.Value, error)
|
2019-02-20 01:10:18 +02:00
|
|
|
}
|
|
|
|
|
2019-06-19 23:58:56 +02:00
|
|
|
// HTMLElement is the most general base interface which most objects in a GetMainFrame implement.
|
2019-02-20 01:10:18 +02:00
|
|
|
HTMLElement interface {
|
|
|
|
HTMLNode
|
|
|
|
|
2019-07-11 23:16:34 +02:00
|
|
|
GetInnerText(ctx context.Context) (values.String, error)
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-07-11 23:16:34 +02:00
|
|
|
SetInnerText(ctx context.Context, innerText values.String) error
|
|
|
|
|
|
|
|
GetInnerHTML(ctx context.Context) (values.String, error)
|
|
|
|
|
|
|
|
SetInnerHTML(ctx context.Context, innerHTML values.String) error
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-09-07 03:02:41 +02:00
|
|
|
GetValue(ctx context.Context) (core.Value, error)
|
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-03-13 20:51:30 +02:00
|
|
|
GetStyles(ctx context.Context) (*values.Object, error)
|
|
|
|
|
|
|
|
GetStyle(ctx context.Context, name values.String) (core.Value, error)
|
|
|
|
|
|
|
|
SetStyles(ctx context.Context, values *values.Object) error
|
|
|
|
|
|
|
|
SetStyle(ctx context.Context, name values.String, value core.Value) error
|
|
|
|
|
|
|
|
RemoveStyle(ctx context.Context, name ...values.String) error
|
|
|
|
|
2019-09-07 03:02:41 +02:00
|
|
|
GetAttributes(ctx context.Context) (*values.Object, error)
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-09-07 03:02:41 +02:00
|
|
|
GetAttribute(ctx context.Context, name values.String) (core.Value, error)
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-03-13 20:51:30 +02:00
|
|
|
SetAttributes(ctx context.Context, values *values.Object) error
|
|
|
|
|
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-03-13 20:51:30 +02:00
|
|
|
RemoveAttribute(ctx context.Context, name ...values.String) error
|
|
|
|
|
2019-07-11 23:16:34 +02:00
|
|
|
GetInnerHTMLBySelector(ctx context.Context, selector values.String) (values.String, error)
|
|
|
|
|
|
|
|
SetInnerHTMLBySelector(ctx context.Context, selector, innerHTML values.String) error
|
|
|
|
|
|
|
|
GetInnerHTMLBySelectorAll(ctx context.Context, selector values.String) (*values.Array, error)
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-07-11 23:16:34 +02:00
|
|
|
GetInnerTextBySelector(ctx context.Context, selector values.String) (values.String, error)
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-07-11 23:16:34 +02:00
|
|
|
SetInnerTextBySelector(ctx context.Context, selector, innerText values.String) error
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-07-11 23:16:34 +02:00
|
|
|
GetInnerTextBySelectorAll(ctx context.Context, selector values.String) (*values.Array, error)
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-09-07 07:59:32 +02:00
|
|
|
Click(ctx context.Context, count values.Int) error
|
|
|
|
|
|
|
|
ClickBySelector(ctx context.Context, selector values.String, count values.Int) error
|
|
|
|
|
|
|
|
ClickBySelectorAll(ctx context.Context, selector values.String, count values.Int) error
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-09-01 22:09:35 +02:00
|
|
|
Clear(ctx context.Context) error
|
|
|
|
|
|
|
|
ClearBySelector(ctx context.Context, selector values.String) 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-09-01 22:09:35 +02:00
|
|
|
InputBySelector(ctx context.Context, selector values.String, value core.Value, delay values.Int) error
|
|
|
|
|
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-09-07 05:15:27 +02:00
|
|
|
SelectBySelector(ctx context.Context, selector values.String, value *values.Array) (*values.Array, error)
|
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
ScrollIntoView(ctx context.Context) error
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-07-23 22:13:04 +02:00
|
|
|
Focus(ctx context.Context) error
|
|
|
|
|
2019-09-07 05:15:27 +02:00
|
|
|
FocusBySelector(ctx context.Context, selector values.String) error
|
|
|
|
|
2019-09-07 18:59:37 +02:00
|
|
|
Blur(ctx context.Context) error
|
|
|
|
|
|
|
|
BlurBySelector(ctx context.Context, selector values.String) error
|
|
|
|
|
2019-02-21 04:24:05 +02:00
|
|
|
Hover(ctx context.Context) error
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-09-07 05:15:27 +02:00
|
|
|
HoverBySelector(ctx context.Context, selector values.String) error
|
|
|
|
|
2019-03-14 04:50:29 +02:00
|
|
|
WaitForAttribute(ctx context.Context, name values.String, value core.Value, when WaitEvent) error
|
2019-03-15 04:10:15 +02:00
|
|
|
|
|
|
|
WaitForStyle(ctx context.Context, name values.String, value core.Value, when WaitEvent) error
|
|
|
|
|
|
|
|
WaitForClass(ctx context.Context, class values.String, when WaitEvent) error
|
2019-02-20 01:10:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HTMLDocument interface {
|
|
|
|
HTMLNode
|
|
|
|
|
2019-06-19 23:58:56 +02:00
|
|
|
GetTitle() values.String
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-06-19 23:58:56 +02:00
|
|
|
GetElement() HTMLElement
|
2019-03-16 01:59:05 +02:00
|
|
|
|
2019-06-19 23:58:56 +02:00
|
|
|
GetURL() values.String
|
2019-03-16 01:59:05 +02:00
|
|
|
|
2019-06-19 23:58:56 +02:00
|
|
|
GetName() values.String
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-06-19 23:58:56 +02:00
|
|
|
GetParentDocument() HTMLDocument
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2019-06-19 23:58:56 +02:00
|
|
|
GetChildDocuments(ctx context.Context) (*values.Array, 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
|
|
|
|
|
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-14 04:50:29 +02:00
|
|
|
WaitForAttributeBySelector(ctx context.Context, selector, name values.String, value core.Value, when WaitEvent) error
|
|
|
|
|
|
|
|
WaitForAttributeBySelectorAll(ctx context.Context, selector, name values.String, value core.Value, when WaitEvent) error
|
2019-03-15 04:10:15 +02:00
|
|
|
|
|
|
|
WaitForStyleBySelector(ctx context.Context, selector, name values.String, value core.Value, when WaitEvent) error
|
|
|
|
|
|
|
|
WaitForStyleBySelectorAll(ctx context.Context, selector, name values.String, value core.Value, when WaitEvent) error
|
|
|
|
|
|
|
|
WaitForClassBySelector(ctx context.Context, selector, class values.String, when WaitEvent) error
|
|
|
|
|
|
|
|
WaitForClassBySelectorAll(ctx context.Context, selector, class values.String, when WaitEvent) error
|
2019-02-20 01:10:18 +02:00
|
|
|
}
|
2019-06-19 23:58:56 +02:00
|
|
|
|
|
|
|
// HTMLPage interface represents any web page loaded in the browser
|
|
|
|
// and serves as an entry point into the web page's content
|
|
|
|
HTMLPage interface {
|
|
|
|
core.Value
|
|
|
|
core.Iterable
|
|
|
|
core.Getter
|
|
|
|
core.Setter
|
|
|
|
collections.Measurable
|
|
|
|
io.Closer
|
|
|
|
|
|
|
|
IsClosed() values.Boolean
|
|
|
|
|
|
|
|
GetURL() values.String
|
|
|
|
|
|
|
|
GetMainFrame() HTMLDocument
|
|
|
|
|
|
|
|
GetFrames(ctx context.Context) (*values.Array, error)
|
|
|
|
|
|
|
|
GetFrame(ctx context.Context, idx values.Int) (core.Value, error)
|
|
|
|
|
|
|
|
GetCookies(ctx context.Context) (*values.Array, error)
|
|
|
|
|
|
|
|
SetCookies(ctx context.Context, cookies ...HTTPCookie) error
|
|
|
|
|
|
|
|
DeleteCookies(ctx context.Context, cookies ...HTTPCookie) error
|
|
|
|
|
|
|
|
PrintToPDF(ctx context.Context, params PDFParams) (values.Binary, error)
|
|
|
|
|
|
|
|
CaptureScreenshot(ctx context.Context, params ScreenshotParams) (values.Binary, error)
|
|
|
|
|
|
|
|
WaitForNavigation(ctx context.Context) error
|
|
|
|
|
|
|
|
Navigate(ctx context.Context, url values.String) error
|
|
|
|
|
|
|
|
NavigateBack(ctx context.Context, skip values.Int) (values.Boolean, error)
|
|
|
|
|
|
|
|
NavigateForward(ctx context.Context, skip values.Int) (values.Boolean, error)
|
2019-09-30 20:07:11 +02:00
|
|
|
|
|
|
|
GetResponse(ctx context.Context) (*HTTPResponse, error)
|
2019-06-19 23:58:56 +02:00
|
|
|
}
|
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
|
|
|
|
)
|