1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-06-27 00:41:09 +02:00

Feature/#220 iframe support (#315)

* Refactored Virtual DOM structure
* Added new E2E tests
* Updated E2E Test Runner
This commit is contained in:
Tim Voronov
2019-06-19 17:58:56 -04:00
committed by GitHub
parent 8c07516ed1
commit d7b923e4c3
103 changed files with 2815 additions and 1629 deletions

View File

@ -22,7 +22,7 @@ func NewLib() map[string]core.Function {
"COOKIE_SET": CookieSet,
"CLICK": Click,
"CLICK_ALL": ClickAll,
"DOCUMENT": Document,
"DOCUMENT": Open,
"DOWNLOAD": Download,
"ELEMENT": Element,
"ELEMENT_EXISTS": ElementExists,
@ -67,27 +67,29 @@ func NewLib() map[string]core.Function {
}
}
func ValidateDocument(ctx context.Context, value core.Value) (core.Value, error) {
err := core.ValidateType(value, drivers.HTMLDocumentType, types.String)
func OpenOrCastPage(ctx context.Context, value core.Value) (drivers.HTMLPage, bool, error) {
err := core.ValidateType(value, drivers.HTMLPageType, types.String)
if err != nil {
return values.None, err
return nil, false, err
}
var doc drivers.HTMLDocument
var page drivers.HTMLPage
var closeAfter bool
if value.Type() == types.String {
buf, err := Document(ctx, value, values.NewBoolean(true))
buf, err := Open(ctx, value, values.NewBoolean(true))
if err != nil {
return values.None, err
return nil, false, err
}
doc = buf.(drivers.HTMLDocument)
page = buf.(drivers.HTMLPage)
closeAfter = true
} else {
doc = value.(drivers.HTMLDocument)
page = value.(drivers.HTMLPage)
}
return doc, nil
return page, closeAfter, nil
}
func waitTimeout(ctx context.Context, value values.Int) (context.Context, context.CancelFunc) {
@ -96,35 +98,3 @@ func waitTimeout(ctx context.Context, value values.Int) (context.Context, contex
time.Duration(value)*time.Millisecond,
)
}
func resolveElement(value core.Value) (drivers.HTMLElement, error) {
vt := value.Type()
if vt == drivers.HTMLDocumentType {
return value.(drivers.HTMLDocument).DocumentElement(), nil
} else if vt == drivers.HTMLElementType {
return value.(drivers.HTMLElement), nil
}
return nil, core.TypeError(value.Type(), drivers.HTMLDocumentType, drivers.HTMLElementType)
}
func toDocument(value core.Value) (drivers.HTMLDocument, error) {
err := core.ValidateType(value, drivers.HTMLDocumentType)
if err != nil {
return nil, err
}
return value.(drivers.HTMLDocument), nil
}
func toElement(value core.Value) (drivers.HTMLElement, error) {
err := core.ValidateType(value, drivers.HTMLElementType)
if err != nil {
return nil, err
}
return value.(drivers.HTMLElement), nil
}