Skip to content
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
28 changes: 0 additions & 28 deletions internal/seleniumtest/seleniumtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

socks5 "github.com/armon/go-socks5"
"github.com/blang/semver"
"github.com/chromedp/cdproto/browser"
"github.com/go-auxiliaries/selenium"
"github.com/go-auxiliaries/selenium/chrome"
"github.com/go-auxiliaries/selenium/firefox"
Expand Down Expand Up @@ -1804,35 +1803,8 @@ func testExecuteChromeDPCommand(t *testing.T, c Config) {
t.Log(product)
}

func testGenerateCDProtoContext(t *testing.T, c Config) {
caps := newTestCapabilities(t, c)

wd, err := NewRemote(t, caps, c.Addr)
if err != nil {
t.Fatalf("newRemote(_, _) returned error: %v", err)
}
defer func() {
_ = wd.Quit()
}()

version := browser.GetVersion()

_, product, _, _, _, err := version.Do(wd.GenerateCDProtoContext(context.Background()))

if err != nil {
t.Fatalf("cdproto execute error : %s", err.Error())
}

if strings.Index(product, "Chrome") > 0 {
t.Log(product)
} else {
t.Fatalf("invalid chrome version %s", product)
}
}

func RunChromeTests(t *testing.T, c Config) {
// Chrome-specific tests.
t.Run("Extension", runTest(testChromeExtension, c))
t.Run("ExecuteChromeDPCommand", runTest(testExecuteChromeDPCommand, c))
t.Run("GenerateCDProtoContext", runTest(testGenerateCDProtoContext, c))
}
68 changes: 0 additions & 68 deletions remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package selenium

import (
"bytes"
"context"
"encoding/base64"
"encoding/json"
"errors"
Expand All @@ -19,9 +18,6 @@ import (
"strings"
"time"

"github.com/chromedp/cdproto/cdp"
"github.com/mailru/easyjson"

"github.com/blang/semver"
"github.com/go-auxiliaries/selenium/firefox"
"github.com/go-auxiliaries/selenium/log"
Expand Down Expand Up @@ -1297,70 +1293,6 @@ func (wd *remoteWD) execChromeDPCommand(cmd string, params map[string]interface{
return reply.Value, nil
}

// CDProtoExecutor execute Chrome DevTools Protocol command through cdproto
type CDProtoExecutor struct {
*remoteWD
}

var _ cdp.Executor = (*CDProtoExecutor)(nil)

// Execute executes a Chrome DevTools Protocol command.
// So that CDProtoExecutor can be executor for cdproto,
// refer to https://github.com/chromedp/cdproto/blob/master/cdp/types.go
func (e CDProtoExecutor) Execute(ctx context.Context, cmd string, params easyjson.Marshaler, res easyjson.Unmarshaler) (err error) {
if e.browser != "chrome" {
return fmt.Errorf("executing a Chrome DevTools command through cdproto is only supported in Chrome, not %s", e.browser)
}

select {
case <-ctx.Done():
return ctx.Err()
default:
}

body := map[string]interface{}{"cmd": cmd}

if params == nil {
// params can't be nil
body["params"] = make(map[string]string)
} else {
body["params"] = params
}

data, err := json.Marshal(body)
if err != nil {
return
}

response, err := e.execChromeDPCommandRaw(data)
if err != nil {
return
}

reply := new(struct{ Value easyjson.Unmarshaler })
reply.Value = res

if err = json.Unmarshal(response, reply); err != nil {
debugLog("cdproto value parse error :%+v", res)
return
}

debugLog("cdproto value return :%+v", res)

return
}

func (wd *remoteWD) generateCDProtoExecutor() cdp.Executor {
return CDProtoExecutor{wd}
}

func (wd *remoteWD) GenerateCDProtoContext(ctx context.Context) context.Context {
if ctx == nil {
ctx = context.Background()
}
return cdp.WithExecutor(ctx, wd.generateCDProtoExecutor())
}

func (wd *remoteWD) ExecuteChromeDPCommand(cmd string, params map[string]interface{}) (interface{}, error) {
if wd.browser != "chrome" {
return nil, fmt.Errorf("executing a Chrome DevTools command is only supported in Chrome, not %s", wd.browser)
Expand Down
5 changes: 0 additions & 5 deletions selenium.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package selenium

import (
"context"
"time"

"github.com/go-auxiliaries/selenium/chrome"
Expand Down Expand Up @@ -446,10 +445,6 @@ type WebDriver interface {
// ExecuteChromeDPCommand executes a Chrome DevTools Protocol command.
// See https://chromedevtools.github.io/devtools-protocol/ for available commands.
ExecuteChromeDPCommand(cmd string, params map[string]interface{}) (interface{}, error)
// GenerateCDProtoContext generates context with an executor
// which can execute a Chrome DevTools Protocol command through cdproto.
// See https://github.com/chromedp/cdproto for usage information.
GenerateCDProtoContext(ctx context.Context) context.Context
// ExecuteScript executes a script.
ExecuteScript(script string, args []interface{}) (interface{}, error)
// ExecuteScriptAsync asynchronously executes a script.
Expand Down