mirror of
https://github.com/MontFerret/ferret.git
synced 2026-05-22 10:15:21 +02:00
#27 Added logging
This commit is contained in:
@@ -78,7 +78,7 @@ func (c *FqlCompiler) Compile(query string) (program *runtime.Program, err error
|
||||
}
|
||||
}()
|
||||
|
||||
l := newVisitor(c.funcs)
|
||||
l := newVisitor(query, c.funcs)
|
||||
|
||||
res := p.Visit(l).(*result)
|
||||
|
||||
|
||||
@@ -1688,39 +1688,24 @@ func TestForTernaryExpression(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
//func TestHtml(t *testing.T) {
|
||||
// Convey("Should load a document", t, func() {
|
||||
// c := compiler.New()
|
||||
//
|
||||
// prog, err := c.Compile(`
|
||||
//LET doc = DOCUMENT('https://soundcloud.com/charts/top', true)
|
||||
//
|
||||
//// TODO: We need a better way of waiting for page loading
|
||||
//// Something line WAIT_FOR(doc, selector)
|
||||
//SLEEP(2000)
|
||||
//
|
||||
//LET tracks = ELEMENTS(doc, '.chartTrack__details')
|
||||
//
|
||||
//LOG("found", LENGTH(tracks), "tracks")
|
||||
//
|
||||
//FOR track IN tracks
|
||||
// // LET username = ELEMENT(track, '.chartTrack__username')
|
||||
// // LET title = ELEMENT(track, '.chartTrack__title')
|
||||
//
|
||||
// // LOG("NODE", track.nodeName)
|
||||
//
|
||||
// SLEEP(500)
|
||||
//
|
||||
// RETURN track.innerHtml
|
||||
//
|
||||
// `)
|
||||
//
|
||||
// So(err, ShouldBeNil)
|
||||
//
|
||||
// out, err := prog.Run(context.Background(), runtime.WithBrowser("http://127.0.0.1:9222"))
|
||||
//
|
||||
// So(err, ShouldBeNil)
|
||||
//
|
||||
// So(string(out), ShouldEqual, `"int"`)
|
||||
// })
|
||||
//}
|
||||
func TestHtml(t *testing.T) {
|
||||
Convey("Should load a document", t, func() {
|
||||
c := compiler.New()
|
||||
|
||||
out, err := c.MustCompile(`
|
||||
LET doc = DOCUMENT("https://github.com/", true)
|
||||
LET btn = ELEMENT(doc, ".HeaderMenu a")
|
||||
|
||||
CLICK(btn)
|
||||
WAIT_NAVIGATION(doc)
|
||||
WAIT_ELEMENT(doc, '.IconNav')
|
||||
|
||||
RETURN INNER_HTML_ALL(doc, '.IconNav a')
|
||||
|
||||
`).Run(context.Background())
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
So(string(out), ShouldEqual, `"int"`)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -18,13 +18,14 @@ import (
|
||||
|
||||
type visitor struct {
|
||||
*fql.BaseFqlParserVisitor
|
||||
|
||||
src string
|
||||
funcs map[string]core.Function
|
||||
}
|
||||
|
||||
func newVisitor(funcs map[string]core.Function) *visitor {
|
||||
func newVisitor(src string, funcs map[string]core.Function) *visitor {
|
||||
return &visitor{
|
||||
&fql.BaseFqlParserVisitor{},
|
||||
src,
|
||||
funcs,
|
||||
}
|
||||
}
|
||||
@@ -38,7 +39,7 @@ func (v *visitor) VisitProgram(ctx *fql.ProgramContext) interface{} {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return runtime.NewProgram(block), nil
|
||||
return runtime.NewProgram(v.src, block)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user