mirror of
https://github.com/MontFerret/ferret.git
synced 2026-06-20 01:17:53 +02:00
Missed updating a bunch of identifiers
This commit is contained in:
@@ -55,15 +55,15 @@ func ToIterator(value core.Value) (Iterator, error) {
|
|||||||
return NewArrayIterator(value.(*values.Array)), nil
|
return NewArrayIterator(value.(*values.Array)), nil
|
||||||
case core.ObjectType:
|
case core.ObjectType:
|
||||||
return NewObjectIterator(value.(*values.Object)), nil
|
return NewObjectIterator(value.(*values.Object)), nil
|
||||||
case core.HtmlElementType, core.HtmlDocumentType:
|
case core.HTMLElementType, core.HTMLDocumentType:
|
||||||
return NewHTMLNodeIterator(value.(values.HTMLNode)), nil
|
return NewHTMLNodeIterator(value.(values.HTMLNode)), nil
|
||||||
default:
|
default:
|
||||||
return nil, core.TypeError(
|
return nil, core.TypeError(
|
||||||
value.Type(),
|
value.Type(),
|
||||||
core.ArrayType,
|
core.ArrayType,
|
||||||
core.ObjectType,
|
core.ObjectType,
|
||||||
core.HtmlDocumentType,
|
core.HTMLDocumentType,
|
||||||
core.HtmlElementType,
|
core.HTMLElementType,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ func GetIn(from core.Value, byPath []core.Value) (core.Value, error) {
|
|||||||
case "innerText":
|
case "innerText":
|
||||||
result = el.InnerText()
|
result = el.InnerText()
|
||||||
case "innerHtml":
|
case "innerHtml":
|
||||||
result = el.InnerHtml()
|
result = el.InnerHTML()
|
||||||
case "value":
|
case "value":
|
||||||
result = el.Value()
|
result = el.Value()
|
||||||
case "attributes":
|
case "attributes":
|
||||||
@@ -73,7 +73,7 @@ func GetIn(from core.Value, byPath []core.Value) (core.Value, error) {
|
|||||||
doc, ok := result.(HTMLDocument)
|
doc, ok := result.(HTMLDocument)
|
||||||
|
|
||||||
if ok {
|
if ok {
|
||||||
result = doc.Url()
|
result = doc.URL()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ func Length(_ context.Context, inputs ...core.Value) (core.Value, error) {
|
|||||||
core.StringType,
|
core.StringType,
|
||||||
core.ArrayType,
|
core.ArrayType,
|
||||||
core.ObjectType,
|
core.ObjectType,
|
||||||
core.HtmlElementType,
|
core.HTMLElementType,
|
||||||
core.HtmlDocumentType,
|
core.HTMLDocumentType,
|
||||||
core.BinaryType,
|
core.BinaryType,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+12
-12
@@ -23,13 +23,13 @@ func Click(_ context.Context, args ...core.Value) (core.Value, error) {
|
|||||||
if len(args) == 1 {
|
if len(args) == 1 {
|
||||||
arg1 := args[0]
|
arg1 := args[0]
|
||||||
|
|
||||||
err := core.ValidateType(arg1, core.HtmlElementType)
|
err := core.ValidateType(arg1, core.HTMLElementType)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return values.False, err
|
return values.False, err
|
||||||
}
|
}
|
||||||
|
|
||||||
el, ok := arg1.(*dynamic.HtmlElement)
|
el, ok := arg1.(*dynamic.HTMLElement)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return values.False, core.Error(core.ErrInvalidType, "expected dynamic element")
|
return values.False, core.Error(core.ErrInvalidType, "expected dynamic element")
|
||||||
@@ -42,13 +42,13 @@ func Click(_ context.Context, args ...core.Value) (core.Value, error) {
|
|||||||
arg1 := args[0]
|
arg1 := args[0]
|
||||||
selector := args[1].String()
|
selector := args[1].String()
|
||||||
|
|
||||||
err = core.ValidateType(arg1, core.HtmlDocumentType)
|
err = core.ValidateType(arg1, core.HTMLDocumentType)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return values.None, err
|
return values.None, err
|
||||||
}
|
}
|
||||||
|
|
||||||
doc, ok := arg1.(*dynamic.HtmlDocument)
|
doc, ok := arg1.(*dynamic.HTMLDocument)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return values.False, core.Error(core.ErrInvalidType, "expected dynamic document")
|
return values.False, core.Error(core.ErrInvalidType, "expected dynamic document")
|
||||||
@@ -73,13 +73,13 @@ func ClickAll(_ context.Context, args ...core.Value) (core.Value, error) {
|
|||||||
arg1 := args[0]
|
arg1 := args[0]
|
||||||
selector := args[1].String()
|
selector := args[1].String()
|
||||||
|
|
||||||
err = core.ValidateType(arg1, core.HtmlDocumentType)
|
err = core.ValidateType(arg1, core.HTMLDocumentType)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return values.None, err
|
return values.None, err
|
||||||
}
|
}
|
||||||
|
|
||||||
doc, ok := arg1.(*dynamic.HtmlDocument)
|
doc, ok := arg1.(*dynamic.HTMLDocument)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return values.False, core.Error(core.ErrInvalidType, "expected dynamic document")
|
return values.False, core.Error(core.ErrInvalidType, "expected dynamic document")
|
||||||
@@ -102,7 +102,7 @@ func Navigate(_ context.Context, args ...core.Value) (core.Value, error) {
|
|||||||
return values.None, err
|
return values.None, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = core.ValidateType(args[0], core.HtmlDocumentType)
|
err = core.ValidateType(args[0], core.HTMLDocumentType)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return values.None, err
|
return values.None, err
|
||||||
@@ -114,7 +114,7 @@ func Navigate(_ context.Context, args ...core.Value) (core.Value, error) {
|
|||||||
return values.None, err
|
return values.None, err
|
||||||
}
|
}
|
||||||
|
|
||||||
doc, ok := args[0].(*dynamic.HtmlDocument)
|
doc, ok := args[0].(*dynamic.HTMLDocument)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return values.False, core.Error(core.ErrInvalidType, "expected dynamic document")
|
return values.False, core.Error(core.ErrInvalidType, "expected dynamic document")
|
||||||
@@ -141,13 +141,13 @@ func Input(_ context.Context, args ...core.Value) (core.Value, error) {
|
|||||||
if len(args) == 2 {
|
if len(args) == 2 {
|
||||||
arg1 := args[0]
|
arg1 := args[0]
|
||||||
|
|
||||||
err := core.ValidateType(arg1, core.HtmlElementType)
|
err := core.ValidateType(arg1, core.HTMLElementType)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return values.False, err
|
return values.False, err
|
||||||
}
|
}
|
||||||
|
|
||||||
el, ok := arg1.(*dynamic.HtmlElement)
|
el, ok := arg1.(*dynamic.HTMLElement)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return values.False, core.Error(core.ErrInvalidType, "expected dynamic element")
|
return values.False, core.Error(core.ErrInvalidType, "expected dynamic element")
|
||||||
@@ -164,7 +164,7 @@ func Input(_ context.Context, args ...core.Value) (core.Value, error) {
|
|||||||
|
|
||||||
arg1 := args[0]
|
arg1 := args[0]
|
||||||
|
|
||||||
err = core.ValidateType(arg1, core.HtmlDocumentType)
|
err = core.ValidateType(arg1, core.HTMLDocumentType)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return values.False, err
|
return values.False, err
|
||||||
@@ -178,7 +178,7 @@ func Input(_ context.Context, args ...core.Value) (core.Value, error) {
|
|||||||
return values.False, err
|
return values.False, err
|
||||||
}
|
}
|
||||||
|
|
||||||
doc, ok := arg1.(*dynamic.HtmlDocument)
|
doc, ok := arg1.(*dynamic.HTMLDocument)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return values.False, core.Error(core.ErrInvalidType, "expected dynamic document")
|
return values.False, core.Error(core.ErrInvalidType, "expected dynamic document")
|
||||||
|
|||||||
@@ -23,13 +23,13 @@ func InnerHTML(_ context.Context, args ...core.Value) (core.Value, error) {
|
|||||||
arg1 := args[0]
|
arg1 := args[0]
|
||||||
selector := args[1].String()
|
selector := args[1].String()
|
||||||
|
|
||||||
err = core.ValidateType(arg1, core.HtmlDocumentType)
|
err = core.ValidateType(arg1, core.HTMLDocumentType)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return values.None, err
|
return values.None, err
|
||||||
}
|
}
|
||||||
|
|
||||||
doc, ok := arg1.(*dynamic.HtmlDocument)
|
doc, ok := arg1.(*dynamic.HTMLDocument)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document")
|
return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document")
|
||||||
@@ -54,13 +54,13 @@ func InnerHTMLAll(_ context.Context, args ...core.Value) (core.Value, error) {
|
|||||||
arg1 := args[0]
|
arg1 := args[0]
|
||||||
selector := args[1].String()
|
selector := args[1].String()
|
||||||
|
|
||||||
err = core.ValidateType(arg1, core.HtmlDocumentType)
|
err = core.ValidateType(arg1, core.HTMLDocumentType)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return values.None, err
|
return values.None, err
|
||||||
}
|
}
|
||||||
|
|
||||||
doc, ok := arg1.(*dynamic.HtmlDocument)
|
doc, ok := arg1.(*dynamic.HTMLDocument)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document")
|
return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document")
|
||||||
@@ -85,13 +85,13 @@ func InnerText(_ context.Context, args ...core.Value) (core.Value, error) {
|
|||||||
arg1 := args[0]
|
arg1 := args[0]
|
||||||
selector := args[1].String()
|
selector := args[1].String()
|
||||||
|
|
||||||
err = core.ValidateType(arg1, core.HtmlDocumentType)
|
err = core.ValidateType(arg1, core.HTMLDocumentType)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return values.None, err
|
return values.None, err
|
||||||
}
|
}
|
||||||
|
|
||||||
doc, ok := arg1.(*dynamic.HtmlDocument)
|
doc, ok := arg1.(*dynamic.HTMLDocument)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document")
|
return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document")
|
||||||
@@ -116,13 +116,13 @@ func InnerTextAll(_ context.Context, args ...core.Value) (core.Value, error) {
|
|||||||
arg1 := args[0]
|
arg1 := args[0]
|
||||||
selector := args[1].String()
|
selector := args[1].String()
|
||||||
|
|
||||||
err = core.ValidateType(arg1, core.HtmlDocumentType)
|
err = core.ValidateType(arg1, core.HTMLDocumentType)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return values.None, err
|
return values.None, err
|
||||||
}
|
}
|
||||||
|
|
||||||
doc, ok := arg1.(*dynamic.HtmlDocument)
|
doc, ok := arg1.(*dynamic.HTMLDocument)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document")
|
return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document")
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Driver interface {
|
type Driver interface {
|
||||||
GetDocument(ctx context.Context, url string) (values.HtmlNode, error)
|
GetDocument(ctx context.Context, url string) (values.HTMLNode, error)
|
||||||
Close() error
|
Close() error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ type HTMLDocument struct {
|
|||||||
client *cdp.Client
|
client *cdp.Client
|
||||||
events *events.EventBroker
|
events *events.EventBroker
|
||||||
url values.String
|
url values.String
|
||||||
element *HtmlElement
|
element *HTMLElement
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadHTMLDocument(
|
func LoadHTMLDocument(
|
||||||
@@ -144,7 +144,7 @@ func NewHTMLDocument(
|
|||||||
doc.conn = conn
|
doc.conn = conn
|
||||||
doc.client = client
|
doc.client = client
|
||||||
doc.events = broker
|
doc.events = broker
|
||||||
doc.element = NewHtmlElement(doc.logger, client, broker, root.NodeID, root, innerHTML)
|
doc.element = NewHTMLElement(doc.logger, client, broker, root.NodeID, root, innerHTML)
|
||||||
doc.url = ""
|
doc.url = ""
|
||||||
|
|
||||||
if root.BaseURL != nil {
|
if root.BaseURL != nil {
|
||||||
@@ -170,7 +170,7 @@ func NewHTMLDocument(
|
|||||||
doc.element.Close()
|
doc.element.Close()
|
||||||
|
|
||||||
// create a new root element wrapper
|
// create a new root element wrapper
|
||||||
doc.element = NewHtmlElement(doc.logger, client, broker, updated.NodeID, updated, innerHTML)
|
doc.element = NewHTMLElement(doc.logger, client, broker, updated.NodeID, updated, innerHTML)
|
||||||
doc.url = ""
|
doc.url = ""
|
||||||
|
|
||||||
if updated.BaseURL != nil {
|
if updated.BaseURL != nil {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ func NewDriver(address string) *Driver {
|
|||||||
return drv
|
return drv
|
||||||
}
|
}
|
||||||
|
|
||||||
func (drv *Driver) GetDocument(ctx context.Context, url string) (values.HtmlNode, error) {
|
func (drv *Driver) GetDocument(ctx context.Context, url string) (values.HTMLNode, error) {
|
||||||
err := drv.init(ctx)
|
err := drv.init(ctx)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -58,7 +58,7 @@ func (drv *Driver) GetDocument(ctx context.Context, url string) (values.HtmlNode
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return LoadHtmlDocument(ctx, conn, url)
|
return LoadHTMLDocument(ctx, conn, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (drv *Driver) Close() error {
|
func (drv *Driver) Close() error {
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ func (el *HTMLElement) String() string {
|
|||||||
|
|
||||||
func (el *HTMLElement) Compare(other core.Value) int {
|
func (el *HTMLElement) Compare(other core.Value) int {
|
||||||
switch other.Type() {
|
switch other.Type() {
|
||||||
case core.HtmlDocumentType:
|
case core.HTMLDocumentType:
|
||||||
other := other.(*HTMLElement)
|
other := other.(*HTMLElement)
|
||||||
|
|
||||||
id := int(el.id)
|
id := int(el.id)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type HTMLDocument struct {
|
type HTMLDocument struct {
|
||||||
*HtmlElement
|
*HTMLElement
|
||||||
url values.String
|
url values.String
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ func NewHTMLDocument(
|
|||||||
return nil, core.Error(core.ErrMissedArgument, "document root selection")
|
return nil, core.Error(core.ErrMissedArgument, "document root selection")
|
||||||
}
|
}
|
||||||
|
|
||||||
el, err := NewHtmlElement(node.Selection)
|
el, err := NewHTMLElement(node.Selection)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ func TestDocument(t *testing.T) {
|
|||||||
|
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
el, err := static.NewHtmlElement(doc.Selection)
|
el, err := static.NewHTMLElement(doc.Selection)
|
||||||
|
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ func (el *HTMLElement) NodeType() values.Int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
return values.NewInt(common.ToHtmlType(nodes[0].Type))
|
return values.NewInt(common.ToHTMLType(nodes[0].Type))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (el *HTMLElement) NodeName() values.String {
|
func (el *HTMLElement) NodeName() values.String {
|
||||||
|
|||||||
@@ -250,7 +250,7 @@ func TestElement(t *testing.T) {
|
|||||||
|
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
el, err := static.NewHtmlElement(doc.Find("body"))
|
el, err := static.NewHTMLElement(doc.Find("body"))
|
||||||
|
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
@@ -266,7 +266,7 @@ func TestElement(t *testing.T) {
|
|||||||
|
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
el, err := static.NewHtmlElement(doc.Find("body"))
|
el, err := static.NewHTMLElement(doc.Find("body"))
|
||||||
|
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
@@ -290,7 +290,7 @@ func TestElement(t *testing.T) {
|
|||||||
|
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
el, err := static.NewHtmlElement(doc.Find("body"))
|
el, err := static.NewHTMLElement(doc.Find("body"))
|
||||||
|
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
@@ -315,7 +315,7 @@ func TestElement(t *testing.T) {
|
|||||||
|
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
el, err := static.NewHtmlElement(doc.Find("#q"))
|
el, err := static.NewHTMLElement(doc.Find("#q"))
|
||||||
|
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
@@ -342,7 +342,7 @@ func TestElement(t *testing.T) {
|
|||||||
|
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
el, err := static.NewHtmlElement(doc.Find("h2"))
|
el, err := static.NewHTMLElement(doc.Find("h2"))
|
||||||
|
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
@@ -369,11 +369,11 @@ func TestElement(t *testing.T) {
|
|||||||
|
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
el, err := static.NewHtmlElement(doc.Find("#content"))
|
el, err := static.NewHTMLElement(doc.Find("#content"))
|
||||||
|
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
v := el.InnerHtml()
|
v := el.InnerHTML()
|
||||||
|
|
||||||
So(v, ShouldEqual, "<h2>Ferret</h2>")
|
So(v, ShouldEqual, "<h2>Ferret</h2>")
|
||||||
})
|
})
|
||||||
@@ -385,7 +385,7 @@ func TestElement(t *testing.T) {
|
|||||||
|
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
el, err := static.NewHtmlElement(doc.Find("body .card-img-top:nth-child(1)"))
|
el, err := static.NewHTMLElement(doc.Find("body .card-img-top:nth-child(1)"))
|
||||||
|
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ func NewDriver(setters ...Option) *Driver {
|
|||||||
return &Driver{client}
|
return &Driver{client}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) GetDocument(_ context.Context, url string) (values.HtmlNode, error) {
|
func (d *Driver) GetDocument(_ context.Context, url string) (values.HTMLNode, error) {
|
||||||
req, err := httpx.NewRequest(httpx.MethodGet, url, nil)
|
req, err := httpx.NewRequest(httpx.MethodGet, url, nil)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -55,10 +55,10 @@ func (d *Driver) GetDocument(_ context.Context, url string) (values.HtmlNode, er
|
|||||||
return nil, errors.Wrapf(err, "failed to parse a document %s", url)
|
return nil, errors.Wrapf(err, "failed to parse a document %s", url)
|
||||||
}
|
}
|
||||||
|
|
||||||
return NewHtmlDocument(url, doc)
|
return NewHTMLDocument(url, doc)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) ParseDocument(_ context.Context, str string) (values.HtmlNode, error) {
|
func (d *Driver) ParseDocument(_ context.Context, str string) (values.HTMLNode, error) {
|
||||||
buf := bytes.NewBuffer([]byte(str))
|
buf := bytes.NewBuffer([]byte(str))
|
||||||
|
|
||||||
doc, err := goquery.NewDocumentFromReader(buf)
|
doc, err := goquery.NewDocumentFromReader(buf)
|
||||||
@@ -67,7 +67,7 @@ func (d *Driver) ParseDocument(_ context.Context, str string) (values.HtmlNode,
|
|||||||
return nil, errors.Wrap(err, "failed to parse a document")
|
return nil, errors.Wrap(err, "failed to parse a document")
|
||||||
}
|
}
|
||||||
|
|
||||||
return NewHtmlDocument("#string", doc)
|
return NewHTMLDocument("#string", doc)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) Close() error {
|
func (d *Driver) Close() error {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ func Elements(_ context.Context, inputs ...core.Value) (core.Value, error) {
|
|||||||
return el.QuerySelectorAll(selector), nil
|
return el.QuerySelectorAll(selector), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func elementArgs(inputs []core.Value) (values.HtmlNode, values.String, error) {
|
func elementArgs(inputs []core.Value) (values.HTMLNode, values.String, error) {
|
||||||
if len(inputs) == 0 {
|
if len(inputs) == 0 {
|
||||||
return nil, values.EmptyString, core.Error(core.ErrMissedArgument, "element and arg2")
|
return nil, values.EmptyString, core.Error(core.ErrMissedArgument, "element and arg2")
|
||||||
}
|
}
|
||||||
@@ -38,14 +38,14 @@ func elementArgs(inputs []core.Value) (values.HtmlNode, values.String, error) {
|
|||||||
arg1 := inputs[0]
|
arg1 := inputs[0]
|
||||||
arg2 := inputs[1]
|
arg2 := inputs[1]
|
||||||
|
|
||||||
if arg1.Type() != core.HtmlDocumentType &&
|
if arg1.Type() != core.HTMLDocumentType &&
|
||||||
arg1.Type() != core.HtmlElementType {
|
arg1.Type() != core.HTMLElementType {
|
||||||
return nil, values.EmptyString, core.TypeError(arg1.Type(), core.HtmlDocumentType, core.HtmlElementType)
|
return nil, values.EmptyString, core.TypeError(arg1.Type(), core.HTMLDocumentType, core.HTMLElementType)
|
||||||
}
|
}
|
||||||
|
|
||||||
if arg2.Type() != core.StringType {
|
if arg2.Type() != core.StringType {
|
||||||
return nil, values.EmptyString, core.TypeError(arg2.Type(), core.StringType)
|
return nil, values.EmptyString, core.TypeError(arg2.Type(), core.StringType)
|
||||||
}
|
}
|
||||||
|
|
||||||
return arg1.(values.HtmlNode), arg2.(values.String), nil
|
return arg1.(values.HTMLNode), arg2.(values.String), nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,13 +24,13 @@ func WaitElement(_ context.Context, args ...core.Value) (core.Value, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = core.ValidateType(arg, core.HtmlDocumentType)
|
err = core.ValidateType(arg, core.HTMLDocumentType)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return values.None, err
|
return values.None, err
|
||||||
}
|
}
|
||||||
|
|
||||||
doc, ok := arg.(*dynamic.HtmlDocument)
|
doc, ok := arg.(*dynamic.HTMLDocument)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return values.False, core.Error(core.ErrInvalidType, "expected dynamic document")
|
return values.False, core.Error(core.ErrInvalidType, "expected dynamic document")
|
||||||
@@ -46,13 +46,13 @@ func WaitNavigation(_ context.Context, args ...core.Value) (core.Value, error) {
|
|||||||
return values.None, err
|
return values.None, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = core.ValidateType(args[0], core.HtmlDocumentType)
|
err = core.ValidateType(args[0], core.HTMLDocumentType)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return values.None, err
|
return values.None, err
|
||||||
}
|
}
|
||||||
|
|
||||||
doc, ok := args[0].(*dynamic.HtmlDocument)
|
doc, ok := args[0].(*dynamic.HTMLDocument)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return values.None, core.Error(core.ErrInvalidType, "expected dynamic document")
|
return values.None, core.Error(core.ErrInvalidType, "expected dynamic document")
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ func NewLib() map[string]core.Function {
|
|||||||
"CLICK_ALL": ClickAll,
|
"CLICK_ALL": ClickAll,
|
||||||
"NAVIGATE": Navigate,
|
"NAVIGATE": Navigate,
|
||||||
"INPUT": Input,
|
"INPUT": Input,
|
||||||
"INNER_HTML": InnerHtml,
|
"INNER_HTML": InnerHTML,
|
||||||
"INNER_HTML_ALL": InnerHtmlAll,
|
"INNER_HTML_ALL": InnerHTMLAll,
|
||||||
"INNER_TEXT": InnerText,
|
"INNER_TEXT": InnerText,
|
||||||
"INNER_TEXT_ALL": InnerTextAll,
|
"INNER_TEXT_ALL": InnerTextAll,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestJsonParse(t *testing.T) {
|
func TestJSONParse(t *testing.T) {
|
||||||
Convey("When args are not passed", t, func() {
|
Convey("When args are not passed", t, func() {
|
||||||
Convey("It should return an error", func() {
|
Convey("It should return an error", func() {
|
||||||
var err error
|
var err error
|
||||||
_, err = strings.JsonParse(context.Background())
|
_, err = strings.JSONParse(context.Background())
|
||||||
|
|
||||||
So(err, ShouldBeError)
|
So(err, ShouldBeError)
|
||||||
})
|
})
|
||||||
@@ -26,7 +26,7 @@ func TestJsonParse(t *testing.T) {
|
|||||||
|
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
out, err := strings.JsonParse(
|
out, err := strings.JSONParse(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
values.NewString(string(b)),
|
values.NewString(string(b)),
|
||||||
)
|
)
|
||||||
@@ -42,7 +42,7 @@ func TestJsonParse(t *testing.T) {
|
|||||||
|
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
out, err := strings.JsonParse(
|
out, err := strings.JSONParse(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
values.NewString(string(b)),
|
values.NewString(string(b)),
|
||||||
)
|
)
|
||||||
@@ -58,7 +58,7 @@ func TestJsonParse(t *testing.T) {
|
|||||||
|
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
out, err := strings.JsonParse(
|
out, err := strings.JSONParse(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
values.NewString(string(b)),
|
values.NewString(string(b)),
|
||||||
)
|
)
|
||||||
@@ -74,7 +74,7 @@ func TestJsonParse(t *testing.T) {
|
|||||||
|
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
out, err := strings.JsonParse(
|
out, err := strings.JSONParse(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
values.NewString(string(b)),
|
values.NewString(string(b)),
|
||||||
)
|
)
|
||||||
@@ -90,7 +90,7 @@ func TestJsonParse(t *testing.T) {
|
|||||||
|
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
out, err := strings.JsonParse(
|
out, err := strings.JSONParse(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
values.NewString(string(b)),
|
values.NewString(string(b)),
|
||||||
)
|
)
|
||||||
@@ -110,7 +110,7 @@ func TestJsonParse(t *testing.T) {
|
|||||||
|
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
out, err := strings.JsonParse(
|
out, err := strings.JSONParse(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
values.NewString(string(b)),
|
values.NewString(string(b)),
|
||||||
)
|
)
|
||||||
@@ -128,7 +128,7 @@ func TestJsonParse(t *testing.T) {
|
|||||||
|
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
out, err := strings.JsonParse(
|
out, err := strings.JSONParse(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
values.NewString(string(b)),
|
values.NewString(string(b)),
|
||||||
)
|
)
|
||||||
@@ -139,18 +139,18 @@ func TestJsonParse(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestJsonStringify(t *testing.T) {
|
func TestJSONStringify(t *testing.T) {
|
||||||
Convey("When args are not passed", t, func() {
|
Convey("When args are not passed", t, func() {
|
||||||
Convey("It should return an error", func() {
|
Convey("It should return an error", func() {
|
||||||
var err error
|
var err error
|
||||||
_, err = strings.JsonStringify(context.Background())
|
_, err = strings.JSONStringify(context.Background())
|
||||||
|
|
||||||
So(err, ShouldBeError)
|
So(err, ShouldBeError)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("It should serialize none", t, func() {
|
Convey("It should serialize none", t, func() {
|
||||||
out, err := strings.JsonStringify(
|
out, err := strings.JSONStringify(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
values.None,
|
values.None,
|
||||||
)
|
)
|
||||||
@@ -160,7 +160,7 @@ func TestJsonStringify(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Convey("It should serialize boolean", t, func() {
|
Convey("It should serialize boolean", t, func() {
|
||||||
out, err := strings.JsonStringify(
|
out, err := strings.JSONStringify(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
values.False,
|
values.False,
|
||||||
)
|
)
|
||||||
@@ -170,7 +170,7 @@ func TestJsonStringify(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Convey("It should serialize string", t, func() {
|
Convey("It should serialize string", t, func() {
|
||||||
out, err := strings.JsonStringify(
|
out, err := strings.JSONStringify(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
values.NewString("foobar"),
|
values.NewString("foobar"),
|
||||||
)
|
)
|
||||||
@@ -180,7 +180,7 @@ func TestJsonStringify(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Convey("It should serialize int", t, func() {
|
Convey("It should serialize int", t, func() {
|
||||||
out, err := strings.JsonStringify(
|
out, err := strings.JSONStringify(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
values.NewInt(1),
|
values.NewInt(1),
|
||||||
)
|
)
|
||||||
@@ -190,7 +190,7 @@ func TestJsonStringify(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Convey("It should serialize float", t, func() {
|
Convey("It should serialize float", t, func() {
|
||||||
out, err := strings.JsonStringify(
|
out, err := strings.JSONStringify(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
values.NewFloat(1.1),
|
values.NewFloat(1.1),
|
||||||
)
|
)
|
||||||
@@ -200,7 +200,7 @@ func TestJsonStringify(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Convey("It should serialize array", t, func() {
|
Convey("It should serialize array", t, func() {
|
||||||
out, err := strings.JsonStringify(
|
out, err := strings.JSONStringify(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
values.NewArrayWith(
|
values.NewArrayWith(
|
||||||
values.NewString("foo"),
|
values.NewString("foo"),
|
||||||
@@ -216,7 +216,7 @@ func TestJsonStringify(t *testing.T) {
|
|||||||
obj := values.NewObject()
|
obj := values.NewObject()
|
||||||
obj.Set(values.NewString("foo"), values.NewString("bar"))
|
obj.Set(values.NewString("foo"), values.NewString("bar"))
|
||||||
|
|
||||||
out, err := strings.JsonStringify(
|
out, err := strings.JSONStringify(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
obj,
|
obj,
|
||||||
)
|
)
|
||||||
@@ -230,7 +230,7 @@ func TestJsonStringify(t *testing.T) {
|
|||||||
|
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
out, err := strings.JsonStringify(
|
out, err := strings.JSONStringify(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
obj,
|
obj,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ func NewLib() map[string]core.Function {
|
|||||||
"ENCODE_URI_COMPONENT": EncodeURIComponent,
|
"ENCODE_URI_COMPONENT": EncodeURIComponent,
|
||||||
"FIND_FIRST": FindFirst,
|
"FIND_FIRST": FindFirst,
|
||||||
"FIND_LAST": FindLast,
|
"FIND_LAST": FindLast,
|
||||||
"JSON_PARSE": JsonParse,
|
"JSON_PARSE": JSONParse,
|
||||||
"JSON_STRINGIFY": JsonStringify,
|
"JSON_STRINGIFY": JSONStringify,
|
||||||
"LEFT": Left,
|
"LEFT": Left,
|
||||||
"LIKE": Like,
|
"LIKE": Like,
|
||||||
"LOWER": Lower,
|
"LOWER": Lower,
|
||||||
|
|||||||
@@ -60,8 +60,8 @@ func ToArray(_ context.Context, inputs ...core.Value) (core.Value, error) {
|
|||||||
core.FloatType,
|
core.FloatType,
|
||||||
core.StringType,
|
core.StringType,
|
||||||
core.DateTimeType,
|
core.DateTimeType,
|
||||||
core.HtmlElementType,
|
core.HTMLElementType,
|
||||||
core.HtmlDocumentType:
|
core.HTMLDocumentType:
|
||||||
return values.NewArrayWith(value), nil
|
return values.NewArrayWith(value), nil
|
||||||
case core.ArrayType:
|
case core.ArrayType:
|
||||||
return value, nil
|
return value, nil
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ func NewLib() map[string]core.Function {
|
|||||||
"IS_DATETIME": IsDateTime,
|
"IS_DATETIME": IsDateTime,
|
||||||
"IS_ARRAY": IsArray,
|
"IS_ARRAY": IsArray,
|
||||||
"IS_OBJECT": IsObject,
|
"IS_OBJECT": IsObject,
|
||||||
"IS_HTML_ELEMENT": IsHtmlElement,
|
"IS_HTML_ELEMENT": IsHTMLElement,
|
||||||
"IS_HTML_DOCUMENT": IsHtmlDocument,
|
"IS_HTML_DOCUMENT": IsHTMLDocument,
|
||||||
"IS_BINARY": IsBinary,
|
"IS_BINARY": IsBinary,
|
||||||
"TYPENAME": TypeName,
|
"TYPENAME": TypeName,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user