Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unimplemented apis #1264

Merged
merged 9 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 9 additions & 74 deletions browser/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ func mapRequest(vu moduleVU, r *common.Request) mapping {
rt := vu.Runtime()
maps := mapping{
"allHeaders": r.AllHeaders,
"failure": r.Failure,
"frame": func() *goja.Object {
mf := mapFrame(vu, r.Frame())
return rt.ToValue(mf).ToObject(rt)
Expand All @@ -127,16 +126,7 @@ func mapRequest(vu moduleVU, r *common.Request) mapping {
"method": r.Method,
"postData": r.PostData,
"postDataBuffer": r.PostDataBuffer,
"postDataJSON": r.PostDataJSON,
"redirectedFrom": func() *goja.Object {
mr := mapRequest(vu, r.RedirectedFrom())
return rt.ToValue(mr).ToObject(rt)
},
"redirectedTo": func() *goja.Object {
mr := mapRequest(vu, r.RedirectedTo())
return rt.ToValue(mr).ToObject(rt)
},
"resourceType": r.ResourceType,
"resourceType": r.ResourceType,
"response": func() *goja.Object {
mr := mapResponse(vu, r.Response())
return rt.ToValue(mr).ToObject(rt)
Expand All @@ -158,7 +148,6 @@ func mapResponse(vu moduleVU, r *common.Response) mapping {
maps := mapping{
"allHeaders": r.AllHeaders,
"body": r.Body,
"finished": r.Finished,
"frame": func() *goja.Object {
mf := mapFrame(vu, r.Frame())
return rt.ToValue(mf).ToObject(rt)
Expand Down Expand Up @@ -219,13 +208,6 @@ func mapJSHandle(vu moduleVU, jsh common.JSHandleAPI) mapping {
}
return dst, nil
},
"getProperty": func(propertyName string) *goja.Object {
var (
h = jsh.GetProperty(propertyName)
m = mapJSHandle(vu, h)
)
return rt.ToValue(m).ToObject(rt)
},
"jsonValue": jsh.JSONValue,
}
}
Expand Down Expand Up @@ -364,9 +346,7 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping {
func mapFrame(vu moduleVU, f *common.Frame) mapping {
rt := vu.Runtime()
maps := mapping{
"addScriptTag": f.AddScriptTag,
"addStyleTag": f.AddStyleTag,
"check": f.Check,
"check": f.Check,
"childFrames": func() *goja.Object {
var (
mcfs []mapping
Expand Down Expand Up @@ -564,11 +544,8 @@ func parseWaitForFunctionArgs(
func mapPage(vu moduleVU, p *common.Page) mapping {
rt := vu.Runtime()
maps := mapping{
"addInitScript": p.AddInitScript,
"addScriptTag": p.AddScriptTag,
"addStyleTag": p.AddStyleTag,
"bringToFront": p.BringToFront,
"check": p.Check,
"bringToFront": p.BringToFront,
"check": p.Check,
"click": func(selector string, opts goja.Value) (*goja.Promise, error) {
popts, err := parseFrameClickOptions(vu.Context(), opts, p.Timeout())
if err != nil {
Expand All @@ -595,7 +572,6 @@ func mapPage(vu moduleVU, p *common.Page) mapping {
}
return p.DispatchEvent(selector, typ, exportArg(eventInit), popts) //nolint:wrapcheck
},
"dragAndDrop": p.DragAndDrop,
"emulateMedia": p.EmulateMedia,
"emulateVisionDeficiency": p.EmulateVisionDeficiency,
"evaluate": func(pageFunction goja.Value, gargs ...goja.Value) any {
Expand All @@ -608,11 +584,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping {
}
return mapJSHandle(vu, jsh), nil
},
"exposeBinding": p.ExposeBinding,
"exposeFunction": p.ExposeFunction,
"fill": p.Fill,
"focus": p.Focus,
"frame": p.Frame,
"fill": p.Fill,
"focus": p.Focus,
"frames": func() *goja.Object {
var (
mfrs []mapping
Expand All @@ -624,13 +597,6 @@ func mapPage(vu moduleVU, p *common.Page) mapping {
return rt.ToValue(mfrs).ToObject(rt)
},
"getAttribute": p.GetAttribute,
"goBack": func(opts goja.Value) *goja.Promise {
return k6ext.Promise(vu.Context(), func() (any, error) {
resp := p.GoBack(opts)
return mapResponse(vu, resp), nil
})
},
"goForward": p.GoForward,
"goto": func(url string, opts goja.Value) (*goja.Promise, error) {
gopts := common.NewFrameGotoOptions(
p.Referrer(),
Expand Down Expand Up @@ -689,8 +655,6 @@ func mapPage(vu moduleVU, p *common.Page) mapping {
return p.On(event, runInTaskQueue) //nolint:wrapcheck
},
"opener": p.Opener,
"pause": p.Pause,
"pdf": p.Pdf,
"press": p.Press,
"reload": func(opts goja.Value) (*goja.Object, error) {
resp, err := p.Reload(opts)
Expand All @@ -702,7 +666,6 @@ func mapPage(vu moduleVU, p *common.Page) mapping {

return rt.ToValue(r).ToObject(rt), nil
},
"route": p.Route,
"screenshot": func(opts goja.Value) (*goja.ArrayBuffer, error) {
ctx := vu.Context()

Expand Down Expand Up @@ -741,11 +704,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping {
"touchscreen": rt.ToValue(p.GetTouchscreen()).ToObject(rt),
"type": p.Type,
"uncheck": p.Uncheck,
"unroute": p.Unroute,
"url": p.URL,
"video": p.Video,
"viewportSize": p.ViewportSize,
"waitForEvent": p.WaitForEvent,
"waitForFunction": func(pageFunc, opts goja.Value, args ...goja.Value) (*goja.Promise, error) {
js, popts, pargs, err := parseWaitForFunctionArgs(
vu.Context(), p.Timeout(), pageFunc, opts, args...,
Expand Down Expand Up @@ -773,8 +733,6 @@ func mapPage(vu moduleVU, p *common.Page) mapping {
return mapResponse(vu, resp), nil
}), nil
},
"waitForRequest": p.WaitForRequest,
"waitForResponse": p.WaitForResponse,
"waitForSelector": func(selector string, opts goja.Value) (mapping, error) {
eh, err := p.WaitForSelector(selector, opts)
if err != nil {
Expand Down Expand Up @@ -825,15 +783,6 @@ func mapPage(vu moduleVU, p *common.Page) mapping {
// mapWorker to the JS module.
func mapWorker(vu moduleVU, w *common.Worker) mapping {
return mapping{
"evaluate": w.Evaluate,
"evaluateHandle": func(pageFunc goja.Value, args ...goja.Value) (mapping, error) {
h, err := w.EvaluateHandle(pageFunc, args...)
if err != nil {
panicIfFatalError(vu.Context(), err)
return nil, err //nolint:wrapcheck
}
return mapJSHandle(vu, h), nil
},
"url": w.URL(),
}
}
Expand Down Expand Up @@ -875,31 +824,17 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin
"clearPermissions": bc.ClearPermissions,
"close": bc.Close,
"cookies": bc.Cookies,
"exposeBinding": bc.ExposeBinding,
"exposeFunction": bc.ExposeFunction,
"grantPermissions": func(permissions []string, opts goja.Value) error {
pOpts := common.NewGrantPermissionsOptions()
pOpts.Parse(vu.Context(), opts)

return bc.GrantPermissions(permissions, pOpts) //nolint:wrapcheck
},
"newCDPSession": bc.NewCDPSession,
"route": bc.Route,
"setDefaultNavigationTimeout": bc.SetDefaultNavigationTimeout,
"setDefaultTimeout": bc.SetDefaultTimeout,
"setExtraHTTPHeaders": func(headers map[string]string) *goja.Promise {
ctx := vu.Context()
return k6ext.Promise(ctx, func() (result any, reason error) {
err := bc.SetExtraHTTPHeaders(headers)
panicIfFatalError(ctx, err)
return nil, err //nolint:wrapcheck
})
},
"setGeolocation": bc.SetGeolocation,
"setHTTPCredentials": bc.SetHTTPCredentials, //nolint:staticcheck
"setOffline": bc.SetOffline,
"storageState": bc.StorageState,
"unroute": bc.Unroute,
"setGeolocation": bc.SetGeolocation,
"setHTTPCredentials": bc.SetHTTPCredentials, //nolint:staticcheck
"setOffline": bc.SetOffline,
"waitForEvent": func(event string, optsOrPredicate goja.Value) (*goja.Promise, error) {
ctx := vu.Context()
popts := common.NewWaitForEventOptions(
Expand Down
33 changes: 0 additions & 33 deletions browser/mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,29 +262,19 @@ type browserContextAPI interface {
ClearPermissions()
Close()
Cookies(urls ...string) ([]*common.Cookie, error)
ExposeBinding(name string, callback goja.Callable, opts goja.Value)
ExposeFunction(name string, callback goja.Callable)
GrantPermissions(permissions []string, opts goja.Value)
NewCDPSession() any
NewPage() (*common.Page, error)
Pages() []*common.Page
Route(url goja.Value, handler goja.Callable)
SetDefaultNavigationTimeout(timeout int64)
SetDefaultTimeout(timeout int64)
SetExtraHTTPHeaders(headers map[string]string) error
SetGeolocation(geolocation goja.Value)
SetHTTPCredentials(httpCredentials goja.Value)
SetOffline(offline bool)
StorageState(opts goja.Value)
Unroute(url goja.Value, handler goja.Callable)
WaitForEvent(event string, optsOrPredicate goja.Value) (any, error)
}

// pageAPI is the interface of a single browser tab.
type pageAPI interface {
AddInitScript(script goja.Value, arg goja.Value)
AddScriptTag(opts goja.Value)
AddStyleTag(opts goja.Value)
BringToFront()
Check(selector string, opts goja.Value)
Click(selector string, opts goja.Value) error
Expand All @@ -293,23 +283,17 @@ type pageAPI interface {
Context() *common.BrowserContext
Dblclick(selector string, opts goja.Value)
DispatchEvent(selector string, typ string, eventInit goja.Value, opts goja.Value)
DragAndDrop(source string, target string, opts goja.Value)
EmulateMedia(opts goja.Value)
EmulateVisionDeficiency(typ string)
Evaluate(pageFunc goja.Value, arg ...goja.Value) any
EvaluateHandle(pageFunc goja.Value, arg ...goja.Value) (common.JSHandleAPI, error)
ExposeBinding(name string, callback goja.Callable, opts goja.Value)
ExposeFunction(name string, callback goja.Callable)
Fill(selector string, value string, opts goja.Value)
Focus(selector string, opts goja.Value)
Frame(frameSelector goja.Value) *common.Frame
Frames() []*common.Frame
GetAttribute(selector string, name string, opts goja.Value) goja.Value
GetKeyboard() *common.Keyboard
GetMouse() *common.Mouse
GetTouchscreen() *common.Touchscreen
GoBack(opts goja.Value) *common.Response
GoForward(opts goja.Value) *common.Response
Goto(url string, opts goja.Value) (*common.Response, error)
Hover(selector string, opts goja.Value)
InnerHTML(selector string, opts goja.Value) string
Expand All @@ -326,13 +310,10 @@ type pageAPI interface {
MainFrame() *common.Frame
On(event string, handler func(*common.ConsoleMessage) error) error
Opener() pageAPI
Pause()
Pdf(opts goja.Value) []byte
Press(selector string, key string, opts goja.Value)
Query(selector string) (*common.ElementHandle, error)
QueryAll(selector string) ([]*common.ElementHandle, error)
Reload(opts goja.Value) *common.Response
Route(url goja.Value, handler goja.Callable)
Screenshot(opts goja.Value) goja.ArrayBuffer
SelectOption(selector string, values goja.Value, opts goja.Value) []string
SetContent(html string, opts goja.Value)
Expand All @@ -348,16 +329,11 @@ type pageAPI interface {
Title() string
Type(selector string, text string, opts goja.Value)
Uncheck(selector string, opts goja.Value)
Unroute(url goja.Value, handler goja.Callable)
URL() string
Video() any
ViewportSize() map[string]float64
WaitForEvent(event string, optsOrPredicate goja.Value) any
WaitForFunction(fn, opts goja.Value, args ...goja.Value) (any, error)
WaitForLoadState(state string, opts goja.Value)
WaitForNavigation(opts goja.Value) (*common.Response, error)
WaitForRequest(urlOrPredicate, opts goja.Value) *common.Request
WaitForResponse(urlOrPredicate, opts goja.Value) *common.Response
WaitForSelector(selector string, opts goja.Value) (*common.ElementHandle, error)
WaitForTimeout(timeout int64)
Workers() []*common.Worker
Expand All @@ -373,8 +349,6 @@ type consoleMessageAPI interface {

// frameAPI is the interface of a CDP target frame.
type frameAPI interface {
AddScriptTag(opts goja.Value)
AddStyleTag(opts goja.Value)
Check(selector string, opts goja.Value)
ChildFrames() []*common.Frame
Click(selector string, opts goja.Value) error
Expand Down Expand Up @@ -469,7 +443,6 @@ type elementHandleAPI interface {
// requestAPI is the interface of an HTTP request.
type requestAPI interface {
AllHeaders() map[string]string
Failure() goja.Value
Frame() *common.Frame
HeaderValue(string) goja.Value
Headers() map[string]string
Expand All @@ -478,9 +451,6 @@ type requestAPI interface {
Method() string
PostData() string
PostDataBuffer() goja.ArrayBuffer
PostDataJSON() string
RedirectedFrom() requestAPI
RedirectedTo() requestAPI
ResourceType() string
Response() *common.Response
Size() common.HTTPMessageSize
Expand All @@ -492,7 +462,6 @@ type requestAPI interface {
type responseAPI interface {
AllHeaders() map[string]string
Body() goja.ArrayBuffer
Finished() bool
Frame() *common.Frame
HeaderValue(string) goja.Value
HeaderValues(string) []string
Expand Down Expand Up @@ -573,7 +542,5 @@ type mouseAPI interface { //nolint: unused

// workerAPI is the interface of a web worker.
type workerAPI interface {
Evaluate(pageFunc goja.Value, args ...goja.Value) any
EvaluateHandle(pageFunc goja.Value, args ...goja.Value) (common.JSHandleAPI, error)
URL() string
}
10 changes: 0 additions & 10 deletions chromium/browser_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ import (
"github.com/grafana/xk6-browser/log"
"github.com/grafana/xk6-browser/storage"

k6common "go.k6.io/k6/js/common"
k6modules "go.k6.io/k6/js/modules"
k6lib "go.k6.io/k6/lib"

"github.com/dop251/goja"
)

// BrowserType provides methods to launch a Chrome browser instance or connect to an existing one.
Expand Down Expand Up @@ -214,13 +211,6 @@ func (b *BrowserType) tmpdir() string {
return dir
}

// LaunchPersistentContext launches the browser with persistent storage.
func (b *BrowserType) LaunchPersistentContext(_ string, _ goja.Value) *common.Browser {
rt := b.vu.Runtime()
k6common.Throw(rt, errors.New("BrowserType.LaunchPersistentContext(userDataDir, opts) has not been implemented yet"))
return nil
}

// Name returns the name of this browser type.
func (b *BrowserType) Name() string {
return "chromium"
Expand Down
Loading
Loading