1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-12 11:15:14 +02:00

Externalized common timeout values (#371)

* Externalized common timeout values

* Updated go.sum
This commit is contained in:
Tim Voronov 2019-09-05 12:17:22 -04:00 committed by GitHub
parent 9b762d32ee
commit 2d645434d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 113 additions and 107 deletions

View File

@ -0,0 +1,12 @@
LET url = @dynamic + "?redirect=/forms"
LET doc = DOCUMENT(url, true)
WAIT_ELEMENT(doc, "form")
LET form = ELEMENT(doc, "#page-form")
INPUT(form, "#text_input", "foo", 100)
LET output = ELEMENT(doc, "#text_output")
RETURN EXPECT(output.innerText, "foo")

12
go.sum
View File

@ -21,7 +21,6 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/derekparker/trie v0.0.0-20190812220523-e66023ee76eb h1:HGjKnH6D1WD8sc9SfCkWkeD4OteWPPXD+ayJY+P1Bgk=
github.com/derekparker/trie v0.0.0-20190812220523-e66023ee76eb/go.mod h1:D6ICZm05D9VN1n/8iOtBxLpXtoGp6HDFUJ1RNVieOSE=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=
@ -30,18 +29,12 @@ github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvK
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/labstack/echo v3.3.10+incompatible h1:pGRcYk231ExFAyoAjAfD85kQzRJCRI8bbnE7CX5OEgg=
github.com/labstack/echo v3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s=
github.com/labstack/echo/v4 v4.1.10 h1:/yhIpO50CBInUbE/nHJtGIyhBv0dJe2cDAYxc3V3uMo=
github.com/labstack/echo/v4 v4.1.10/go.mod h1:i541M3Fj6f76NZtHSj7TXnyM8n2gaodfvfxNnFqi74g=
github.com/labstack/gommon v0.3.0 h1:JEeO0bvc78PKdyHxloTKiF8BD5iGrH8T6MSeGvSgob0=
github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k=
github.com/mafredri/cdp v0.24.2 h1:Rzhj/EQw9opbiwUpNML7P+4Hvf0/nSYPaDbiCEpILOM=
github.com/mafredri/cdp v0.24.2/go.mod h1:hgdiA0yp1uqhSaDOHJWPgXpMbh+LAfUdD9vbN2AM8gE=
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.9 h1:d5US/mDsogSGW37IV293h//ZFaeajb69h+EHFsv2xGg=
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM=
@ -62,14 +55,10 @@ github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337/go.mod h1:s
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.0.1 h1:tY9CJiPnMXf1ERmG2EyK7gNUd+c6RKGD0IfU8WdUSz8=
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc=
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@ -79,7 +68,6 @@ golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 h1:k7pJ2yAPLPgbskkFdhRCsA77k
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

View File

@ -326,19 +326,19 @@ func (doc *HTMLDocument) ClickBySelectorAll(ctx context.Context, selector values
}
func (doc *HTMLDocument) SelectBySelector(ctx context.Context, selector values.String, value *values.Array) (*values.Array, error) {
return doc.input.SelectBySelector(ctx, doc.element.id.nodeID, selector, value)
return doc.input.SelectBySelector(ctx, doc.element.id.nodeID, selector.String(), value)
}
func (doc *HTMLDocument) FocusBySelector(ctx context.Context, selector values.String) error {
return doc.input.FocusBySelector(ctx, doc.element.id.nodeID, selector)
return doc.input.FocusBySelector(ctx, doc.element.id.nodeID, selector.String())
}
func (doc *HTMLDocument) MoveMouseBySelector(ctx context.Context, selector values.String) error {
return doc.input.MoveMouseBySelector(ctx, doc.element.id.nodeID, selector)
return doc.input.MoveMouseBySelector(ctx, doc.element.id.nodeID, selector.String())
}
func (doc *HTMLDocument) MoveMouseByXY(ctx context.Context, x, y values.Float) error {
return doc.input.MoveMouseByXY(ctx, x, y)
return doc.input.MoveMouseByXY(ctx, float64(x), float64(y))
}
func (doc *HTMLDocument) WaitForElement(ctx context.Context, selector values.String, when drivers.WaitEvent) error {
@ -497,11 +497,11 @@ func (doc *HTMLDocument) ScrollBottom(ctx context.Context) error {
}
func (doc *HTMLDocument) ScrollBySelector(ctx context.Context, selector values.String) error {
return doc.input.ScrollIntoViewBySelector(ctx, selector)
return doc.input.ScrollIntoViewBySelector(ctx, selector.String())
}
func (doc *HTMLDocument) ScrollByXY(ctx context.Context, x, y values.Float) error {
return doc.input.ScrollByXY(ctx, x, y)
return doc.input.ScrollByXY(ctx, float64(x), float64(y))
}
func (doc *HTMLDocument) loadChildren(ctx context.Context) (value core.Value, e error) {

View File

@ -2,15 +2,13 @@ package cdp
import (
"context"
"sync"
"time"
"github.com/mafredri/cdp"
"github.com/mafredri/cdp/devtool"
"github.com/mafredri/cdp/protocol/target"
"github.com/mafredri/cdp/rpcc"
"github.com/mafredri/cdp/session"
"github.com/pkg/errors"
"sync"
"github.com/MontFerret/ferret/pkg/drivers"
"github.com/MontFerret/ferret/pkg/runtime/logging"
@ -18,7 +16,6 @@ import (
const DriverName = "cdp"
const BlankPageURL = "about:blank"
const DefaultTimeout = 5000 * time.Millisecond
var defaultViewport = &drivers.Viewport{
Width: 1600,

View File

@ -8,6 +8,7 @@ import (
"strconv"
"strings"
"sync"
"time"
"github.com/MontFerret/ferret/pkg/drivers"
"github.com/MontFerret/ferret/pkg/drivers/cdp/eval"
@ -208,7 +209,7 @@ func (el *HTMLElement) MarshalJSON() ([]byte, error) {
}
func (el *HTMLElement) String() string {
ctx, cancel := context.WithTimeout(context.Background(), DefaultTimeout)
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(drivers.DefaultWaitTimeout)*time.Millisecond)
defer cancel()
res, err := el.GetInnerHTML(ctx)
@ -1056,11 +1057,11 @@ func (el *HTMLElement) Click(ctx context.Context) error {
}
func (el *HTMLElement) ClickBySelector(ctx context.Context, selector values.String) error {
return el.input.ClickBySelector(ctx, el.id.nodeID, selector)
return el.input.ClickBySelector(ctx, el.id.nodeID, selector.String())
}
func (el *HTMLElement) ClickBySelectorAll(ctx context.Context, selector values.String) error {
return el.input.ClickBySelectorAll(ctx, el.id.nodeID, selector)
return el.input.ClickBySelectorAll(ctx, el.id.nodeID, selector.String())
}
func (el *HTMLElement) Input(ctx context.Context, value core.Value, delay values.Int) error {
@ -1069,17 +1070,17 @@ func (el *HTMLElement) Input(ctx context.Context, value core.Value, delay values
}
return el.input.Type(ctx, el.id.objectID, input.TypeParams{
Text: value,
Text: value.String(),
Clear: false,
Delay: delay,
Delay: time.Duration(delay) * time.Millisecond,
})
}
func (el *HTMLElement) InputBySelector(ctx context.Context, selector values.String, value core.Value, delay values.Int) error {
return el.input.TypeBySelector(ctx, el.id.nodeID, selector, input.TypeParams{
Text: value,
return el.input.TypeBySelector(ctx, el.id.nodeID, selector.String(), input.TypeParams{
Text: value.String(),
Clear: false,
Delay: delay,
Delay: time.Duration(delay) * time.Millisecond,
})
}
@ -1088,7 +1089,7 @@ func (el *HTMLElement) Clear(ctx context.Context) error {
}
func (el *HTMLElement) ClearBySelector(ctx context.Context, selector values.String) error {
return el.input.ClearBySelector(ctx, el.id.nodeID, selector)
return el.input.ClearBySelector(ctx, el.id.nodeID, selector.String())
}
func (el *HTMLElement) Select(ctx context.Context, value *values.Array) (*values.Array, error) {

View File

@ -4,6 +4,7 @@ import (
"context"
"reflect"
"sync"
"time"
"github.com/mafredri/cdp/protocol/dom"
"github.com/mafredri/cdp/protocol/page"
@ -289,7 +290,7 @@ func (broker *EventBroker) emit(ctx context.Context, event Event, message interf
case <-ctx.Done():
return
default:
ctx2, fn := drivers.WithDefaultTimeout(ctx)
ctx2, fn := context.WithTimeout(ctx, time.Duration(drivers.DefaultTimeout)*time.Millisecond)
listener(ctx2, message)

View File

@ -62,7 +62,7 @@ func (k *Keyboard) Up(ctx context.Context, char string) error {
)
}
func (k *Keyboard) Type(ctx context.Context, text string, delay int) error {
func (k *Keyboard) Type(ctx context.Context, text string, delay time.Duration) error {
for _, ch := range text {
ch := string(ch)
@ -70,7 +70,7 @@ func (k *Keyboard) Type(ctx context.Context, text string, delay int) error {
return err
}
releaseDelay := randomDuration(delay) * time.Millisecond
releaseDelay := randomDuration(int(delay))
time.Sleep(releaseDelay)
if err := k.Up(ctx, ch); err != nil {

View File

@ -8,6 +8,7 @@ import (
"github.com/mafredri/cdp/protocol/dom"
"github.com/mafredri/cdp/protocol/runtime"
"github.com/MontFerret/ferret/pkg/drivers"
"github.com/MontFerret/ferret/pkg/drivers/cdp/eval"
"github.com/MontFerret/ferret/pkg/drivers/cdp/templates"
"github.com/MontFerret/ferret/pkg/runtime/core"
@ -16,9 +17,9 @@ import (
type (
TypeParams struct {
Text core.Value
Clear values.Boolean
Delay values.Int
Text string
Clear bool
Delay time.Duration
}
Manager struct {
@ -69,14 +70,14 @@ func (m *Manager) ScrollIntoView(ctx context.Context, objectID runtime.RemoteObj
)
}
func (m *Manager) ScrollIntoViewBySelector(ctx context.Context, selector values.String) error {
return m.exec.Eval(ctx, templates.ScrollIntoViewBySelector(selector.String()))
func (m *Manager) ScrollIntoViewBySelector(ctx context.Context, selector string) error {
return m.exec.Eval(ctx, templates.ScrollIntoViewBySelector(selector))
}
func (m *Manager) ScrollByXY(ctx context.Context, x, y values.Float) error {
func (m *Manager) ScrollByXY(ctx context.Context, x, y float64) error {
return m.exec.Eval(
ctx,
templates.Scroll(eval.ParamFloat(float64(x)), eval.ParamFloat(float64(y))),
templates.Scroll(eval.ParamFloat(x), eval.ParamFloat(y)),
)
}
@ -90,14 +91,14 @@ func (m *Manager) Focus(ctx context.Context, objectID runtime.RemoteObjectID) er
return m.client.DOM.Focus(ctx, dom.NewFocusArgs().SetObjectID(objectID))
}
func (m *Manager) FocusBySelector(ctx context.Context, parentNodeID dom.NodeID, selector values.String) error {
func (m *Manager) FocusBySelector(ctx context.Context, parentNodeID dom.NodeID, selector string) error {
err := m.ScrollIntoViewBySelector(ctx, selector)
if err != nil {
return err
}
found, err := m.client.DOM.QuerySelector(ctx, dom.NewQuerySelectorArgs(parentNodeID, selector.String()))
found, err := m.client.DOM.QuerySelector(ctx, dom.NewQuerySelectorArgs(parentNodeID, selector))
if err != nil {
return nil
@ -120,12 +121,12 @@ func (m *Manager) MoveMouse(ctx context.Context, objectID runtime.RemoteObjectID
return m.mouse.Move(ctx, q.X, q.Y)
}
func (m *Manager) MoveMouseBySelector(ctx context.Context, parentNodeID dom.NodeID, selector values.String) error {
func (m *Manager) MoveMouseBySelector(ctx context.Context, parentNodeID dom.NodeID, selector string) error {
if err := m.ScrollIntoViewBySelector(ctx, selector); err != nil {
return err
}
found, err := m.client.DOM.QuerySelector(ctx, dom.NewQuerySelectorArgs(parentNodeID, selector.String()))
found, err := m.client.DOM.QuerySelector(ctx, dom.NewQuerySelectorArgs(parentNodeID, selector))
if err != nil {
return err
@ -140,12 +141,12 @@ func (m *Manager) MoveMouseBySelector(ctx context.Context, parentNodeID dom.Node
return m.mouse.Move(ctx, q.X, q.Y)
}
func (m *Manager) MoveMouseByXY(ctx context.Context, x, y values.Float) error {
func (m *Manager) MoveMouseByXY(ctx context.Context, x, y float64) error {
if err := m.ScrollByXY(ctx, x, y); err != nil {
return err
}
return m.mouse.Move(ctx, float64(x), float64(y))
return m.mouse.Move(ctx, x, y)
}
func (m *Manager) Click(ctx context.Context, objectID runtime.RemoteObjectID) error {
@ -159,19 +160,19 @@ func (m *Manager) Click(ctx context.Context, objectID runtime.RemoteObjectID) er
return err
}
if err := m.mouse.Click(ctx, points.X, points.Y, 50); err != nil {
if err := m.mouse.Click(ctx, points.X, points.Y, drivers.DefaultInputDelay); err != nil {
return nil
}
return nil
}
func (m *Manager) ClickBySelector(ctx context.Context, parentNodeID dom.NodeID, selector values.String) error {
func (m *Manager) ClickBySelector(ctx context.Context, parentNodeID dom.NodeID, selector string) error {
if err := m.ScrollIntoViewBySelector(ctx, selector); err != nil {
return err
}
found, err := m.client.DOM.QuerySelector(ctx, dom.NewQuerySelectorArgs(parentNodeID, selector.String()))
found, err := m.client.DOM.QuerySelector(ctx, dom.NewQuerySelectorArgs(parentNodeID, selector))
if err != nil {
return err
@ -183,29 +184,29 @@ func (m *Manager) ClickBySelector(ctx context.Context, parentNodeID dom.NodeID,
return err
}
if err := m.mouse.Click(ctx, points.X, points.Y, 50); err != nil {
if err := m.mouse.Click(ctx, points.X, points.Y, drivers.DefaultInputDelay); err != nil {
return nil
}
return nil
}
func (m *Manager) ClickBySelectorAll(ctx context.Context, parentNodeID dom.NodeID, selector values.String) error {
func (m *Manager) ClickBySelectorAll(ctx context.Context, parentNodeID dom.NodeID, selector string) error {
if err := m.ScrollIntoViewBySelector(ctx, selector); err != nil {
return err
}
found, err := m.client.DOM.QuerySelectorAll(ctx, dom.NewQuerySelectorAllArgs(parentNodeID, selector.String()))
found, err := m.client.DOM.QuerySelectorAll(ctx, dom.NewQuerySelectorAllArgs(parentNodeID, selector))
if err != nil {
return err
}
for _, nodeID := range found.NodeIDs {
_, min := core.NumberBoundaries(100)
beforeTypeDelay := time.Duration(min)
_, min := core.NumberBoundaries(drivers.DefaultInputDelay * 2)
beforeTypeDelay := time.Duration(min) * time.Millisecond
time.Sleep(beforeTypeDelay * time.Millisecond)
time.Sleep(beforeTypeDelay)
points, err := GetClickablePointByNodeID(ctx, m.client, nodeID)
@ -213,7 +214,7 @@ func (m *Manager) ClickBySelectorAll(ctx context.Context, parentNodeID dom.NodeI
return err
}
if err := m.mouse.Click(ctx, points.X, points.Y, 50); err != nil {
if err := m.mouse.Click(ctx, points.X, points.Y, drivers.DefaultInputDelay); err != nil {
return nil
}
}
@ -246,22 +247,22 @@ func (m *Manager) Type(ctx context.Context, objectID runtime.RemoteObjectID, par
}
}
_, min := core.NumberBoundaries(float64(params.Delay))
beforeTypeDelay := time.Duration(min)
d := core.NumberLowerBoundary(float64(params.Delay))
beforeTypeDelay := time.Duration(d)
time.Sleep(beforeTypeDelay * time.Millisecond)
time.Sleep(beforeTypeDelay)
return m.keyboard.Type(ctx, params.Text.String(), int(params.Delay))
return m.keyboard.Type(ctx, params.Text, params.Delay)
}
func (m *Manager) TypeBySelector(ctx context.Context, parentNodeID dom.NodeID, selector values.String, params TypeParams) error {
func (m *Manager) TypeBySelector(ctx context.Context, parentNodeID dom.NodeID, selector string, params TypeParams) error {
err := m.ScrollIntoViewBySelector(ctx, selector)
if err != nil {
return err
}
found, err := m.client.DOM.QuerySelector(ctx, dom.NewQuerySelectorArgs(parentNodeID, selector.String()))
found, err := m.client.DOM.QuerySelector(ctx, dom.NewQuerySelectorArgs(parentNodeID, selector))
if err != nil {
return err
@ -285,12 +286,12 @@ func (m *Manager) TypeBySelector(ctx context.Context, parentNodeID dom.NodeID, s
}
}
_, min := core.NumberBoundaries(float64(params.Delay))
beforeTypeDelay := time.Duration(min)
d := core.NumberLowerBoundary(float64(params.Delay))
beforeTypeDelay := time.Duration(d)
time.Sleep(beforeTypeDelay * time.Millisecond)
time.Sleep(beforeTypeDelay)
return m.keyboard.Type(ctx, params.Text.String(), int(params.Delay))
return m.keyboard.Type(ctx, params.Text, params.Delay)
}
func (m *Manager) Clear(ctx context.Context, objectID runtime.RemoteObjectID) error {
@ -315,14 +316,14 @@ func (m *Manager) Clear(ctx context.Context, objectID runtime.RemoteObjectID) er
return m.ClearByXY(ctx, points)
}
func (m *Manager) ClearBySelector(ctx context.Context, parentNodeID dom.NodeID, selector values.String) error {
func (m *Manager) ClearBySelector(ctx context.Context, parentNodeID dom.NodeID, selector string) error {
err := m.ScrollIntoViewBySelector(ctx, selector)
if err != nil {
return err
}
found, err := m.client.DOM.QuerySelector(ctx, dom.NewQuerySelectorArgs(parentNodeID, selector.String()))
found, err := m.client.DOM.QuerySelector(ctx, dom.NewQuerySelectorArgs(parentNodeID, selector))
if err != nil {
return err
@ -375,12 +376,12 @@ func (m *Manager) Select(ctx context.Context, objectID runtime.RemoteObjectID, v
return arr, nil
}
func (m *Manager) SelectBySelector(ctx context.Context, parentNodeID dom.NodeID, selector values.String, value *values.Array) (*values.Array, error) {
func (m *Manager) SelectBySelector(ctx context.Context, parentNodeID dom.NodeID, selector string, value *values.Array) (*values.Array, error) {
if err := m.FocusBySelector(ctx, parentNodeID, selector); err != nil {
return values.NewArray(0), err
}
res, err := m.exec.EvalWithReturnValue(ctx, templates.SelectBySelector(selector.String(), value.String()))
res, err := m.exec.EvalWithReturnValue(ctx, templates.SelectBySelector(selector, value.String()))
if err != nil {
return values.NewArray(0), err

8
pkg/drivers/consts.go Normal file
View File

@ -0,0 +1,8 @@
package drivers
const (
DefaultPageLoadTimeout = 60000
DefaultWaitTimeout = 5000
DefaultInputDelay = 25
DefaultTimeout = 30000
)

View File

@ -2,14 +2,10 @@ package drivers
import (
"context"
"io"
"time"
"github.com/MontFerret/ferret/pkg/runtime/core"
"io"
)
const DefaultTimeout = time.Second * 30
type (
ctxKey struct{}

View File

@ -1,15 +1,9 @@
package drivers
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/core"
)
func WithDefaultTimeout(ctx context.Context) (context.Context, context.CancelFunc) {
return context.WithTimeout(ctx, DefaultTimeout)
}
func ToPage(value core.Value) (HTMLPage, error) {
err := core.ValidateType(value, HTMLPageType)

View File

@ -57,10 +57,9 @@ In=56
Param=57
Identifier=58
StringLiteral=59
TemplateStringLiteral=60
IntegerLiteral=61
FloatLiteral=62
NamespaceSegment=63
IntegerLiteral=60
FloatLiteral=61
NamespaceSegment=62
':'=5
';'=6
'.'=7

View File

@ -36,6 +36,14 @@ func NumberBoundaries(input float64) (max float64, min float64) {
return
}
func NumberUpperBoundary(input float64) float64 {
return input * 2
}
func NumberLowerBoundary(input float64) float64 {
return input / 2
}
func Random(max float64, min float64) float64 {
r := rand.Float64()
i := r * (max - min + 1)

View File

@ -76,7 +76,7 @@ func newDefaultDocLoadParams(url values.String) PageLoadParams {
Params: drivers.Params{
URL: url.String(),
},
Timeout: time.Second * 30,
Timeout: drivers.DefaultPageLoadTimeout * time.Millisecond,
}
}

View File

@ -27,7 +27,7 @@ func Input(ctx context.Context, args ...core.Value) (core.Value, error) {
return values.False, err
}
delay := values.NewInt(25)
delay := values.NewInt(drivers.DefaultInputDelay)
// INPUT(el, value)
if len(args) == 2 {
@ -48,9 +48,7 @@ func Input(ctx context.Context, args ...core.Value) (core.Value, error) {
return values.True, el.Input(ctx, value, delay)
default:
// INPUT(el, selector, value)
err := core.ValidateType(args[1], types.String)
if err != nil {
if err := core.ValidateType(args[1], types.String); err != nil {
return values.False, err
}
@ -59,12 +57,16 @@ func Input(ctx context.Context, args ...core.Value) (core.Value, error) {
}
} else {
// INPUT(el, selector, value, delay)
err := core.ValidateType(args[3], types.Int)
if err != nil {
if err := core.ValidateType(args[1], types.String); err != nil {
return values.False, err
}
if err := core.ValidateType(args[3], types.Int); err != nil {
return values.False, err
}
selector = values.ToString(args[1])
value = args[2]
delay = values.ToInt(args[3])
}

View File

@ -10,8 +10,6 @@ import (
"github.com/MontFerret/ferret/pkg/runtime/values/types"
)
const defaultTimeout = 5000
func RegisterLib(ns core.Namespace) error {
return ns.RegisterFunctions(core.Functions{
"ATTR_GET": AttributeGet,
@ -74,6 +72,7 @@ func RegisterLib(ns core.Namespace) error {
func OpenOrCastPage(ctx context.Context, value core.Value) (drivers.HTMLPage, bool, error) {
err := core.ValidateType(value, drivers.HTMLPageType, types.String)
if err != nil {
return nil, false, err
}

View File

@ -34,7 +34,7 @@ func Navigate(ctx context.Context, args ...core.Value) (core.Value, error) {
return values.None, err
}
timeout := values.NewInt(defaultTimeout)
timeout := values.NewInt(drivers.DefaultWaitTimeout)
if len(args) > 2 {
err = core.ValidateType(args[2], types.Int)

View File

@ -30,7 +30,7 @@ func NavigateBack(ctx context.Context, args ...core.Value) (core.Value, error) {
}
skip := values.NewInt(1)
timeout := values.NewInt(defaultTimeout)
timeout := values.NewInt(drivers.DefaultWaitTimeout)
if len(args) > 1 {
err = core.ValidateType(args[1], types.Int)

View File

@ -30,7 +30,7 @@ func NavigateForward(ctx context.Context, args ...core.Value) (core.Value, error
}
skip := values.NewInt(1)
timeout := values.NewInt(defaultTimeout)
timeout := values.NewInt(drivers.DefaultWaitTimeout)
if len(args) > 1 {
err = core.ValidateType(args[1], types.Int)

View File

@ -39,7 +39,7 @@ func waitAttributeWhen(ctx context.Context, args []core.Value, when drivers.Wait
return values.None, err
}
timeout := values.NewInt(defaultTimeout)
timeout := values.NewInt(drivers.DefaultWaitTimeout)
// if a document is passed
// WAIT_ATTR(doc, selector, attrName, attrValue, timeout)

View File

@ -59,7 +59,7 @@ func waitAttributeAllWhen(ctx context.Context, args []core.Value, when drivers.W
selector := args[1].(values.String)
name := args[2].(values.String)
value := args[3]
timeout := values.NewInt(defaultTimeout)
timeout := values.NewInt(drivers.DefaultWaitTimeout)
if len(args) == 5 {
err = core.ValidateType(args[4], types.Int)

View File

@ -57,7 +57,7 @@ func waitClassWhen(ctx context.Context, args []core.Value, when drivers.WaitEven
return values.None, err
}
timeout := values.NewInt(defaultTimeout)
timeout := values.NewInt(drivers.DefaultWaitTimeout)
// if a document is passed
if arg1.Type() == drivers.HTMLPageType || arg1.Type() == drivers.HTMLDocumentType {

View File

@ -58,7 +58,7 @@ func waitClassAllWhen(ctx context.Context, args []core.Value, when drivers.WaitE
selector := args[1].(values.String)
class := args[2].(values.String)
timeout := values.NewInt(defaultTimeout)
timeout := values.NewInt(drivers.DefaultWaitTimeout)
if len(args) == 4 {
err = core.ValidateType(args[3], types.Int)

View File

@ -41,7 +41,7 @@ func waitElementWhen(ctx context.Context, args []core.Value, when drivers.WaitEv
}
selector := args[1].String()
timeout := values.NewInt(defaultTimeout)
timeout := values.NewInt(drivers.DefaultWaitTimeout)
if len(args) > 2 {
err = core.ValidateType(args[2], types.Int)

View File

@ -26,7 +26,7 @@ func WaitNavigation(ctx context.Context, args ...core.Value) (core.Value, error)
return values.None, err
}
timeout := values.NewInt(defaultTimeout)
timeout := values.NewInt(drivers.DefaultWaitTimeout)
if len(args) > 1 {
err = core.ValidateType(args[1], types.Int)

View File

@ -39,7 +39,7 @@ func waitStyleWhen(ctx context.Context, args []core.Value, when drivers.WaitEven
return values.None, err
}
timeout := values.NewInt(defaultTimeout)
timeout := values.NewInt(drivers.DefaultWaitTimeout)
// if a document is passed
// WAIT_ATTR(doc, selector, attrName, attrValue, timeout)

View File

@ -47,7 +47,7 @@ func waitStyleAllWhen(ctx context.Context, args []core.Value, when drivers.WaitE
selector := args[1].(values.String)
name := args[2].(values.String)
value := args[3]
timeout := values.NewInt(defaultTimeout)
timeout := values.NewInt(drivers.DefaultWaitTimeout)
if len(args) == 5 {
err = core.ValidateType(args[4], types.Int)