From 8764fb351aeddcbee2e02e91c78fe94693cee14e Mon Sep 17 00:00:00 2001 From: Xymos Date: Thu, 6 May 2021 11:07:33 +0100 Subject: [PATCH 01/25] draft wip actions --- remote.go | 29 +++++++++++++++++++++++++++++ selenium.go | 8 ++++++++ 2 files changed, 37 insertions(+) diff --git a/remote.go b/remote.go index 466d361..724ff3b 100644 --- a/remote.go +++ b/remote.go @@ -1095,6 +1095,35 @@ func (wd *remoteWD) KeyUp(keys string) error { return wd.keyAction("keyUp", keys) } +func (wd *remoteWD) PointerDown(button int) map[string]interface{} { + return map[string]interface{}{ + "type": "pointerDown", + "button": button, + } +} + +func (wd *remoteWD) MovePointerTo(x, y, duration int) map[string]interface{} { + + return map[string]interface{}{ + "type": "pointerMove", + "duration": duration, + "x": x, + "y": y, + } +} + +func (wd *remoteWD) PerformActions(actionType string, actions []map[string]interface{}) error { + + return wd.voidCommand("/session/%s/actions", map[string]interface{}{ + "actions": []interface{}{ + map[string]interface{}{ + "type": actionType, + "id": "mouse1", + "actions": actions, + }}, + }) +} + // TODO(minusnine): Implement PerformActions and ReleaseActions, for more // direct access to the W3C specification. func (wd *remoteWD) DismissAlert() error { diff --git a/selenium.go b/selenium.go index ac9dcd6..afc0b12 100644 --- a/selenium.go +++ b/selenium.go @@ -330,6 +330,14 @@ type WebDriver interface { // ButtonUp causes the left mouse button to be released. ButtonUp() error + // MovePointerTo creates an action to move mouse to location x,y + MovePointerTo(x, y, duration int) map[string]interface{} + + PointerDown(button int) map[string]interface{} + + // PerformActions performs the supplied actions + PerformActions(actionType string, actions []map[string]interface{}) error + // SendModifier sends the modifier key to the active element. The modifier // can be one of ShiftKey, ControlKey, AltKey, MetaKey. // From c1ae08ca42fdd073674b798197244847d8f17062 Mon Sep 17 00:00:00 2001 From: Xymos Date: Thu, 6 May 2021 14:56:20 +0100 Subject: [PATCH 02/25] added ReleaseActions --- remote.go | 5 ++++- selenium.go | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/remote.go b/remote.go index 724ff3b..929a801 100644 --- a/remote.go +++ b/remote.go @@ -1103,7 +1103,6 @@ func (wd *remoteWD) PointerDown(button int) map[string]interface{} { } func (wd *remoteWD) MovePointerTo(x, y, duration int) map[string]interface{} { - return map[string]interface{}{ "type": "pointerMove", "duration": duration, @@ -1124,6 +1123,10 @@ func (wd *remoteWD) PerformActions(actionType string, actions []map[string]inter }) } +func (wd *remoteWD) ReleaseActions() error { + return voidCommand("DELETE", wd.requestURL("/session/%s/actions", wd.id), nil) +} + // TODO(minusnine): Implement PerformActions and ReleaseActions, for more // direct access to the W3C specification. func (wd *remoteWD) DismissAlert() error { diff --git a/selenium.go b/selenium.go index afc0b12..43cef0d 100644 --- a/selenium.go +++ b/selenium.go @@ -335,9 +335,12 @@ type WebDriver interface { PointerDown(button int) map[string]interface{} - // PerformActions performs the supplied actions + // PerformActions performs stored actions PerformActions(actionType string, actions []map[string]interface{}) error + // ReleaseActions releases stored actions + ReleaseActions() error + // SendModifier sends the modifier key to the active element. The modifier // can be one of ShiftKey, ControlKey, AltKey, MetaKey. // From cf872b0937802e4704e96e1ff44e95ce53087426 Mon Sep 17 00:00:00 2001 From: Xymos Date: Thu, 6 May 2021 15:05:32 +0100 Subject: [PATCH 03/25] temporarily changed package path --- chrome/capabilities.go | 2 +- example_test.go | 2 +- firefox/capabilities.go | 2 +- go.mod | 2 +- internal/seleniumtest/seleniumtest.go | 10 +++++----- remote.go | 4 ++-- sauce_test.go | 6 +++--- selenium.go | 6 +++--- selenium_test.go | 6 +++--- 9 files changed, 20 insertions(+), 20 deletions(-) diff --git a/chrome/capabilities.go b/chrome/capabilities.go index f9ef726..4beca57 100644 --- a/chrome/capabilities.go +++ b/chrome/capabilities.go @@ -16,7 +16,7 @@ import ( "github.com/golang/protobuf/proto" "github.com/mediabuyerbot/go-crx3/pb" - "github.com/tebeka/selenium/internal/zip" + "github.com/x-Xymos/selenium/internal/zip" ) // CapabilitiesKey is the key in the top-level Capabilities map under which diff --git a/example_test.go b/example_test.go index 1e5fceb..a669d2a 100644 --- a/example_test.go +++ b/example_test.go @@ -6,7 +6,7 @@ import ( "strings" "time" - "github.com/tebeka/selenium" + "github.com/x-Xymos/selenium" ) // This example shows how to navigate to a http://play.golang.org page, input a diff --git a/firefox/capabilities.go b/firefox/capabilities.go index 5eb23b0..8e1f69f 100644 --- a/firefox/capabilities.go +++ b/firefox/capabilities.go @@ -5,7 +5,7 @@ import ( "bytes" "encoding/base64" - "github.com/tebeka/selenium/internal/zip" + "github.com/x-Xymos/selenium/internal/zip" ) // CapabilitiesKey is the name of the Firefox-specific key in the WebDriver diff --git a/go.mod b/go.mod index 80e4ad9..11284df 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/tebeka/selenium +module github.com/x-Xymos/selenium go 1.12 diff --git a/internal/seleniumtest/seleniumtest.go b/internal/seleniumtest/seleniumtest.go index e225928..1c1d412 100644 --- a/internal/seleniumtest/seleniumtest.go +++ b/internal/seleniumtest/seleniumtest.go @@ -24,11 +24,11 @@ import ( socks5 "github.com/armon/go-socks5" "github.com/blang/semver" "github.com/google/go-cmp/cmp" - "github.com/tebeka/selenium" - "github.com/tebeka/selenium/chrome" - "github.com/tebeka/selenium/firefox" - "github.com/tebeka/selenium/log" - "github.com/tebeka/selenium/sauce" + "github.com/x-Xymos/selenium" + "github.com/x-Xymos/selenium/chrome" + "github.com/x-Xymos/selenium/firefox" + "github.com/x-Xymos/selenium/log" + "github.com/x-Xymos/selenium/sauce" ) type Config struct { diff --git a/remote.go b/remote.go index 929a801..e530738 100644 --- a/remote.go +++ b/remote.go @@ -18,8 +18,8 @@ import ( "time" "github.com/blang/semver" - "github.com/tebeka/selenium/firefox" - "github.com/tebeka/selenium/log" + "github.com/x-Xymos/selenium/firefox" + "github.com/x-Xymos/selenium/log" ) // Errors returned by Selenium server. diff --git a/sauce_test.go b/sauce_test.go index 784fb8a..4e5be92 100644 --- a/sauce_test.go +++ b/sauce_test.go @@ -7,9 +7,9 @@ import ( "testing" "github.com/blang/semver" - "github.com/tebeka/selenium" - "github.com/tebeka/selenium/internal/seleniumtest" - "github.com/tebeka/selenium/sauce" + "github.com/x-Xymos/selenium" + "github.com/x-Xymos/selenium/internal/seleniumtest" + "github.com/x-Xymos/selenium/sauce" ) var ( diff --git a/selenium.go b/selenium.go index 43cef0d..10c83de 100644 --- a/selenium.go +++ b/selenium.go @@ -3,9 +3,9 @@ package selenium import ( "time" - "github.com/tebeka/selenium/chrome" - "github.com/tebeka/selenium/firefox" - "github.com/tebeka/selenium/log" + "github.com/x-Xymos/selenium/chrome" + "github.com/x-Xymos/selenium/firefox" + "github.com/x-Xymos/selenium/log" ) // TODO(minusnine): make an enum type called FindMethod. diff --git a/selenium_test.go b/selenium_test.go index 949ae05..1171c69 100644 --- a/selenium_test.go +++ b/selenium_test.go @@ -14,8 +14,8 @@ import ( "github.com/blang/semver" "github.com/golang/glog" - "github.com/tebeka/selenium" - "github.com/tebeka/selenium/internal/seleniumtest" + "github.com/x-Xymos/selenium" + "github.com/x-Xymos/selenium/internal/seleniumtest" ) var ( @@ -230,7 +230,7 @@ func TestHTMLUnit(t *testing.T) { // HTMLUnit-Driver currently does not support the sameSite attribute // See: https://github.com/SeleniumHQ/htmlunit-driver/issues/97 SameSiteUnsupported: true, - } + } port, err := pickUnusedPort() if err != nil { From efa105ccbcae668a707efa9658c7317a2250ea1b Mon Sep 17 00:00:00 2001 From: Xymos Date: Thu, 6 May 2021 15:11:26 +0100 Subject: [PATCH 04/25] . --- go.mod | 4 ++-- go.sum | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 11284df..a7dadad 100644 --- a/go.mod +++ b/go.mod @@ -8,8 +8,8 @@ require ( github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 github.com/blang/semver v3.5.1+incompatible github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b - github.com/golang/protobuf v1.3.4 - github.com/google/go-cmp v0.3.0 + github.com/golang/protobuf v1.5.2 + github.com/google/go-cmp v0.5.5 github.com/google/go-github/v27 v27.0.4 github.com/mediabuyerbot/go-crx3 v1.3.1 google.golang.org/api v0.7.0 diff --git a/go.sum b/go.sum index 28a9333..d507e39 100644 --- a/go.sum +++ b/go.sum @@ -50,11 +50,16 @@ github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.4 h1:87PNWwrRvUSnqS4dlcBU/ftvOIBep4sYuBLlh6rX2wk= github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-github/v27 v27.0.4 h1:N/EEqsvJLgqTbepTiMBz+12KhwLovv6YvwpRezd+4Fg= github.com/google/go-github/v27 v27.0.4/go.mod h1:/0Gr8pJ55COkmv+S/yPKCczSkUPIM/LnFyubufRNIS0= github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= @@ -199,6 +204,8 @@ golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBn golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190624190245-7f2218787638/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0 h1:9sdfJOzWlkqPltHAuzT2Cp+yrBeY1KRVYgms8soxMwM= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= @@ -219,6 +226,9 @@ google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiq google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/grpc v1.21.1 h1:j6XxA85m/6txkUCHvzlV5f+HBNl/1r5cZ2A/3IEFOO8= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From 4d0f8423af1141abbe3119f854d33e4230a38c49 Mon Sep 17 00:00:00 2001 From: Xymos Date: Thu, 6 May 2021 15:33:09 +0100 Subject: [PATCH 05/25] . --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index a7dadad..2c9d1d3 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/x-Xymos/selenium +module github.com/x-Xymos/selenium/v1 go 1.12 From 05a19825cdfefeee9cef71ac89ab0e823842dcd2 Mon Sep 17 00:00:00 2001 From: Xymos Date: Thu, 6 May 2021 15:41:37 +0100 Subject: [PATCH 06/25] . --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 2c9d1d3..3acd0a7 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/x-Xymos/selenium/v1 +module github.com/x-Xymos/selenium/v1.0.2 go 1.12 From 29fc204eb24d0bce5398144889ad0aaf275f672e Mon Sep 17 00:00:00 2001 From: Xymos Date: Thu, 6 May 2021 15:44:51 +0100 Subject: [PATCH 07/25] . --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 3acd0a7..2c9d1d3 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/x-Xymos/selenium/v1.0.2 +module github.com/x-Xymos/selenium/v1 go 1.12 From 32a2bc81c9a687cebb209310a3e389ad18f8ff71 Mon Sep 17 00:00:00 2001 From: Xymos Date: Thu, 6 May 2021 15:47:08 +0100 Subject: [PATCH 08/25] . --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 2c9d1d3..f2ce58e 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/x-Xymos/selenium/v1 +module github.com/x-Xymos/selenium/v1.0.4 go 1.12 From 825942615d4667cfca52bfa6e7d0b5ccd4d90de3 Mon Sep 17 00:00:00 2001 From: Xymos Date: Thu, 6 May 2021 15:49:01 +0100 Subject: [PATCH 09/25] . --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index f2ce58e..2c9d1d3 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/x-Xymos/selenium/v1.0.4 +module github.com/x-Xymos/selenium/v1 go 1.12 From f018360e0187629dce7d16aa8ddf488b37756315 Mon Sep 17 00:00:00 2001 From: Xymos Date: Thu, 6 May 2021 15:50:32 +0100 Subject: [PATCH 10/25] . --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 2c9d1d3..9c7f3f1 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/x-Xymos/selenium/v1 +module github.com/x-Xymos/selenium/v1 v1.0.6 go 1.12 From 067d956597c3dccdf93ec4e0e12f4be0095bbdcb Mon Sep 17 00:00:00 2001 From: Xymos Date: Thu, 6 May 2021 15:55:31 +0100 Subject: [PATCH 11/25] . --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 9c7f3f1..2c9d1d3 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/x-Xymos/selenium/v1 v1.0.6 +module github.com/x-Xymos/selenium/v1 go 1.12 From e12e58da2dac4b1fc5ae1e6f5f9871a7c0086586 Mon Sep 17 00:00:00 2001 From: Xymos Date: Thu, 6 May 2021 15:57:14 +0100 Subject: [PATCH 12/25] . --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 2c9d1d3..d9e5e85 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/x-Xymos/selenium/v1 +module github.com/x-Xymos/selenium/v1 v1.0.7 go 1.12 From 64394f96893cfa3dcd2342b5d95397e1b76aa82e Mon Sep 17 00:00:00 2001 From: Xymos Date: Thu, 6 May 2021 16:05:44 +0100 Subject: [PATCH 13/25] . --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index d9e5e85..2c9d1d3 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/x-Xymos/selenium/v1 v1.0.7 +module github.com/x-Xymos/selenium/v1 go 1.12 From c21a0fe02d5db208a0f60c9bfca5dd81db31b04a Mon Sep 17 00:00:00 2001 From: Xymos Date: Thu, 6 May 2021 23:54:05 +0100 Subject: [PATCH 14/25] implemented actions --- go.mod | 1 + go.sum | 2 ++ remote.go | 70 ++++++++++++++++++++++++++++++++++------------- selenium.go | 78 ++++++++++++++++++++++++++++++++++++++++++++++++----- 4 files changed, 126 insertions(+), 25 deletions(-) diff --git a/go.mod b/go.mod index 2c9d1d3..544a177 100644 --- a/go.mod +++ b/go.mod @@ -12,5 +12,6 @@ require ( github.com/google/go-cmp v0.5.5 github.com/google/go-github/v27 v27.0.4 github.com/mediabuyerbot/go-crx3 v1.3.1 + github.com/x-Xymos/selenium v1.0.0 google.golang.org/api v0.7.0 ) diff --git a/go.sum b/go.sum index d507e39..68a250d 100644 --- a/go.sum +++ b/go.sum @@ -130,6 +130,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= +github.com/x-Xymos/selenium v1.0.0 h1:YdxU7V8PF4No8Opf8/E90xflYyZNt7WlKy8lgaEo/vo= +github.com/x-Xymos/selenium v1.0.0/go.mod h1:TnTHK4j2+rgi3Kwk3PY0wbXwn8/ZeCJQQmSDk5Zn+e8= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= diff --git a/remote.go b/remote.go index e530738..c58bbeb 100644 --- a/remote.go +++ b/remote.go @@ -47,9 +47,9 @@ var remoteErrors = map[int]string{ } type remoteWD struct { - id, urlPrefix string - capabilities Capabilities - + id, urlPrefix string + capabilities Capabilities + actions Actions w3cCompatible bool browser string browserVersion semver.Version @@ -1095,32 +1095,64 @@ func (wd *remoteWD) KeyUp(keys string) error { return wd.keyAction("keyUp", keys) } -func (wd *remoteWD) PointerDown(button int) map[string]interface{} { - return map[string]interface{}{ +func (wd *remoteWD) PointerMove(duration time.Duration, offset Point, origin PointerMoveOrigin) Action { + return Action{ + "type": "pointerMove", + "duration": uint(duration / time.Millisecond), + "origin": origin, + "x": offset.X, + "y": offset.Y, + } +} + +func (wd *remoteWD) PointerDown(button MouseButton) Action { + return Action{ "type": "pointerDown", "button": button, } } -func (wd *remoteWD) MovePointerTo(x, y, duration int) map[string]interface{} { - return map[string]interface{}{ - "type": "pointerMove", - "duration": duration, - "x": x, - "y": y, +func (wd *remoteWD) PointerUp(button MouseButton) Action { + return Action{ + "type": "pointerUp", + "button": button, } } -func (wd *remoteWD) PerformActions(actionType string, actions []map[string]interface{}) error { +func (wd *remoteWD) PauseAction(duration time.Duration) Action { + return Action{ + "type": "pause", + "duration": uint(duration / time.Millisecond), + } +} - return wd.voidCommand("/session/%s/actions", map[string]interface{}{ - "actions": []interface{}{ - map[string]interface{}{ - "type": actionType, - "id": "mouse1", - "actions": actions, - }}, +func (wd *remoteWD) StoreActions(inputId string, actionType ActionType, parameters ActionParameter, actions ...Action) { + + _actions := []Action{} + for _, action := range actions { + _actions = append(_actions, action) + } + + action := map[string]interface{}{ + "type": actionType, + "id": inputId, + "actions": _actions, + } + + //can I just add a nil ["parameters"] field without having to check it ? + if parameters != nil { + action["parameters"] = parameters + } + + wd.actions = append(wd.actions, action) +} + +func (wd *remoteWD) PerformActions() error { + err := wd.voidCommand("/session/%s/actions", map[string]interface{}{ + "actions": wd.actions, }) + wd.actions = nil + return err } func (wd *remoteWD) ReleaseActions() error { diff --git a/selenium.go b/selenium.go index 10c83de..ace0af3 100644 --- a/selenium.go +++ b/selenium.go @@ -22,9 +22,11 @@ const ( ByCSSSelector = "css selector" ) +type MouseButton int + // Mouse buttons. const ( - LeftButton = iota + LeftButton MouseButton = iota MiddleButton RightButton ) @@ -223,6 +225,50 @@ const ( SameSiteEmpty = "" ) +type PointerType string + +const ( + MousePointer PointerType = "mouse" + PenPointer = "pen" + TouchPointer = "touch" +) + +func PointerTypeParam(p PointerType) ActionParameter { + return ActionParameter{ + "pointerType": string(p), + } +} + +//controls how the offset for the pointer move action is calculated +// +// FromViewport: calculate the offset from the viewport at 0,0 +// +// FromPointer: calculate the offset from the current pointer position +type PointerMoveOrigin string + +//todo: add FromElement which calculates the +//offset from the provided element +const ( + FromViewport PointerMoveOrigin = "viewport" + FromPointer = "pointer" +) + +type ActionParameter map[string]interface{} + +type ActionType string + +const ( + PointerAction ActionType = "pointer" + KeyAction = "key" + NoneAction = "none" +) + +//Action +type Action map[string]interface{} + +//Actions holds a map of stored actions +type Actions []Action + // WebDriver defines methods supported by WebDriver drivers. type WebDriver interface { // Status returns various pieces of information about the server environment. @@ -330,15 +376,35 @@ type WebDriver interface { // ButtonUp causes the left mouse button to be released. ButtonUp() error - // MovePointerTo creates an action to move mouse to location x,y - MovePointerTo(x, y, duration int) map[string]interface{} + // PauseAction build an action which pauses for the supplied duration + PauseAction(duration time.Duration) Action + + // PointerMove build an action which moves the pointer + PointerMove(duration time.Duration, offset Point, origin PointerMoveOrigin) Action - PointerDown(button int) map[string]interface{} + // PointerDown build an action which presses and holds the specified + // pointer key until explicitly released by PointerUp or ReleaseActions + PointerDown(button MouseButton) Action + + // PointerUp build an action which releases the specified pointer key + PointerUp(button MouseButton) Action + + // StoreActions + // + // inputId: unique device identifier for the stored action + // + // actionType: accepts either PointerAction, KeyAction, or NoneAction + // + // parameters: optional map of parameters, currently only works with PointerTypeParam + // + //actions: any number of Actions + StoreActions(inputId string, actionType ActionType, parameters ActionParameter, actions ...Action) // PerformActions performs stored actions - PerformActions(actionType string, actions []map[string]interface{}) error + PerformActions() error - // ReleaseActions releases stored actions + // ReleaseActions releases keys and pointer buttons if they are pressed, + // triggering any events as if they were performed by a regular action ReleaseActions() error // SendModifier sends the modifier key to the active element. The modifier From c6befe8689d729e65f96d0935250aafa3f3ebb46 Mon Sep 17 00:00:00 2001 From: Xymos Date: Thu, 6 May 2021 23:55:47 +0100 Subject: [PATCH 15/25] testing --- remote.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remote.go b/remote.go index c58bbeb..302cb71 100644 --- a/remote.go +++ b/remote.go @@ -48,8 +48,8 @@ var remoteErrors = map[int]string{ type remoteWD struct { id, urlPrefix string - capabilities Capabilities actions Actions + capabilities Capabilities w3cCompatible bool browser string browserVersion semver.Version From c83b1bdc60e80e3e2d10af1338283398d274fcff Mon Sep 17 00:00:00 2001 From: Xymos Date: Fri, 7 May 2021 22:20:07 +0100 Subject: [PATCH 16/25] added key actions --- remote.go | 80 ++++++++++++++++++++++++++++++++++------------------- selenium.go | 68 +++++++++++++++++++++------------------------ 2 files changed, 83 insertions(+), 65 deletions(-) diff --git a/remote.go b/remote.go index 302cb71..ecea69e 100644 --- a/remote.go +++ b/remote.go @@ -1095,56 +1095,82 @@ func (wd *remoteWD) KeyUp(keys string) error { return wd.keyAction("keyUp", keys) } -func (wd *remoteWD) PointerMove(duration time.Duration, offset Point, origin PointerMoveOrigin) Action { - return Action{ - "type": "pointerMove", +func (wd *remoteWD) KeyPauseAction(duration time.Duration) KeyAction { + return KeyAction{ + "type": "pause", "duration": uint(duration / time.Millisecond), - "origin": origin, - "x": offset.X, - "y": offset.Y, } } -func (wd *remoteWD) PointerDown(button MouseButton) Action { - return Action{ - "type": "pointerDown", - "button": button, +func (wd *remoteWD) KeyUpAction(key string) KeyAction { + return KeyAction{ + "type": "keyUp", + "value": key, } } -func (wd *remoteWD) PointerUp(button MouseButton) Action { - return Action{ - "type": "pointerUp", - "button": button, +func (wd *remoteWD) KeyDownAction(key string) KeyAction { + return KeyAction{ + "type": "keyDown", + "value": key, } } -func (wd *remoteWD) PauseAction(duration time.Duration) Action { - return Action{ +func (wd *remoteWD) PointerPauseAction(duration time.Duration) PointerAction { + return PointerAction{ "type": "pause", "duration": uint(duration / time.Millisecond), } } -func (wd *remoteWD) StoreActions(inputId string, actionType ActionType, parameters ActionParameter, actions ...Action) { +func (wd *remoteWD) PointerMoveAction(duration time.Duration, offset Point, origin PointerMoveOrigin) PointerAction { + return PointerAction{ + "type": "pointerMove", + "duration": uint(duration / time.Millisecond), + "origin": origin, + "x": offset.X, + "y": offset.Y, + } +} - _actions := []Action{} +func (wd *remoteWD) PointerUpAction(button MouseButton) PointerAction { + return PointerAction{ + "type": "pointerUp", + "button": button, + } +} + +func (wd *remoteWD) PointerDownAction(button MouseButton) PointerAction { + return PointerAction{ + "type": "pointerDown", + "button": button, + } +} + +func (wd *remoteWD) StoreKeyActions(inputId string, actions ...KeyAction) { + _actions := []map[string]interface{}{} for _, action := range actions { _actions = append(_actions, action) } - - action := map[string]interface{}{ - "type": actionType, + wd.actions = append(wd.actions, map[string]interface{}{ + "type": "key", "id": inputId, "actions": _actions, - } + }) +} - //can I just add a nil ["parameters"] field without having to check it ? - if parameters != nil { - action["parameters"] = parameters +func (wd *remoteWD) StorePointerActions(inputId string, pointerType PointerType, actions ...PointerAction) { + _actions := []map[string]interface{}{} + for _, action := range actions { + _actions = append(_actions, action) } - wd.actions = append(wd.actions, action) + wd.actions = append(wd.actions, map[string]interface{}{ + "type": "pointer", + "id": inputId, + "parameters": map[string]string{"pointerType": string(pointerType)}, + "actions": _actions, + }) } func (wd *remoteWD) PerformActions() error { @@ -1159,8 +1185,6 @@ func (wd *remoteWD) ReleaseActions() error { return voidCommand("DELETE", wd.requestURL("/session/%s/actions", wd.id), nil) } -// TODO(minusnine): Implement PerformActions and ReleaseActions, for more -// direct access to the W3C specification. func (wd *remoteWD) DismissAlert() error { return wd.voidCommand("/session/%s/alert/dismiss", nil) } diff --git a/selenium.go b/selenium.go index ace0af3..4848bef 100644 --- a/selenium.go +++ b/selenium.go @@ -233,12 +233,6 @@ const ( TouchPointer = "touch" ) -func PointerTypeParam(p PointerType) ActionParameter { - return ActionParameter{ - "pointerType": string(p), - } -} - //controls how the offset for the pointer move action is calculated // // FromViewport: calculate the offset from the viewport at 0,0 @@ -253,21 +247,14 @@ const ( FromPointer = "pointer" ) -type ActionParameter map[string]interface{} +//KeyAction +type KeyAction map[string]interface{} -type ActionType string +//KeyAction +type PointerAction map[string]interface{} -const ( - PointerAction ActionType = "pointer" - KeyAction = "key" - NoneAction = "none" -) - -//Action -type Action map[string]interface{} - -//Actions holds a map of stored actions -type Actions []Action +// //Actions holds a map of stored KeyActions and PointerActions +type Actions []map[string]interface{} // WebDriver defines methods supported by WebDriver drivers. type WebDriver interface { @@ -376,33 +363,40 @@ type WebDriver interface { // ButtonUp causes the left mouse button to be released. ButtonUp() error - // PauseAction build an action which pauses for the supplied duration - PauseAction(duration time.Duration) Action - - // PointerMove build an action which moves the pointer - PointerMove(duration time.Duration, offset Point, origin PointerMoveOrigin) Action - - // PointerDown build an action which presses and holds the specified - // pointer key until explicitly released by PointerUp or ReleaseActions - PointerDown(button MouseButton) Action + // KeyPauseAction build a KeyAction which pauses for the supplied duration + KeyPauseAction(duration time.Duration) KeyAction + // KeyUpAction build a KeyAction press + KeyUpAction(key string) KeyAction + // KeyDownAction build a KeyAction which presses and holds the specified + // key until explicitly released by KeyUpAction or ReleaseActions + KeyDownAction(key string) KeyAction + // StoreKeyActions + // + // inputId: unique device identifier for the stored action + // + // actions: any number of KeyActions + StoreKeyActions(inputId string, actions ...KeyAction) + // PointerPause build a PointerAction which pauses for the supplied duration + PointerPauseAction(duration time.Duration) PointerAction + // PointerMove build a PointerAction which moves the pointer + PointerMoveAction(duration time.Duration, offset Point, origin PointerMoveOrigin) PointerAction // PointerUp build an action which releases the specified pointer key - PointerUp(button MouseButton) Action - - // StoreActions + PointerUpAction(button MouseButton) PointerAction + // PointerDown build a PointerAction which presses and holds the specified + // pointer key until explicitly released by PointerUp or ReleaseActions + PointerDownAction(button MouseButton) PointerAction + // StorePointerActions // // inputId: unique device identifier for the stored action // - // actionType: accepts either PointerAction, KeyAction, or NoneAction + // pointerType: type of pointer - accepts: MousePointer, TouchPointer, PenPointer // - // parameters: optional map of parameters, currently only works with PointerTypeParam - // - //actions: any number of Actions - StoreActions(inputId string, actionType ActionType, parameters ActionParameter, actions ...Action) + //actions: any number of PointerActions + StorePointerActions(inputId string, pointerType PointerType, actions ...PointerAction) // PerformActions performs stored actions PerformActions() error - // ReleaseActions releases keys and pointer buttons if they are pressed, // triggering any events as if they were performed by a regular action ReleaseActions() error From ee2e83ea9b4e4c457f0d4c494512d9480808c8d0 Mon Sep 17 00:00:00 2001 From: Xymos Date: Fri, 7 May 2021 22:32:08 +0100 Subject: [PATCH 17/25] added key actions --- go.mod | 2 ++ 1 file changed, 2 insertions(+) diff --git a/go.mod b/go.mod index 544a177..ca4288b 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,8 @@ module github.com/x-Xymos/selenium/v1 go 1.12 +//replace github.com/x-Xymos/selenium v1.0.0 => /home/xymos/go/src/selenium + require ( cloud.google.com/go v0.41.0 github.com/BurntSushi/xgbutil v0.0.0-20160919175755-f7c97cef3b4e From 6e51192c5ae1247d3babc39c802853fff1f5139a Mon Sep 17 00:00:00 2001 From: Xymos Date: Fri, 7 May 2021 23:11:12 +0100 Subject: [PATCH 18/25] added actions example --- example_test.go | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/example_test.go b/example_test.go index a669d2a..a740bbc 100644 --- a/example_test.go +++ b/example_test.go @@ -104,9 +104,50 @@ func Example() { } fmt.Printf("%s", strings.Replace(output, "\n\n", "\n", -1)) - // Example Output: // Hello WebDriver! // // Program exited. + + //Actions example + if err := wd.Get("http://play.golang.org/?simple=1"); err != nil { + panic(err) + } + time.Sleep(time.Second * 1) + + offset := selenium.Point{X: 100, Y: 100} + wd.StorePointerActions("mouse1", + selenium.MousePointer, + wd.PointerMoveAction(0, offset, selenium.FromViewport), + wd.PointerPauseAction(250), + wd.PointerDownAction(selenium.LeftButton), + wd.PointerPauseAction(250), + wd.PointerUpAction(selenium.LeftButton), + ) + + wd.StoreKeyActions("keyboard1", + wd.KeyDownAction(selenium.ControlKey), + wd.KeyPauseAction(50), + wd.KeyDownAction("a"), + wd.KeyPauseAction(50), + wd.KeyUpAction("a"), + wd.KeyUpAction(selenium.ControlKey), + wd.KeyDownAction("h"), + wd.KeyDownAction("e"), + wd.KeyDownAction("l"), + wd.KeyDownAction("l"), + wd.KeyDownAction("o"), + ) + + err = wd.PerformActions() + if err != nil { + panic(err) + } + + //calling ReleaseActions to release the KeyDownActions we've performed so we don't have to call KeyUpAction explicitly + err = wd.ReleaseActions() + if err != nil { + panic(err) + } + } From 221fe35a79dffc2a50eba104ff335ca7fde889f7 Mon Sep 17 00:00:00 2001 From: Xymos Date: Fri, 7 May 2021 23:14:00 +0100 Subject: [PATCH 19/25] reverted back package path --- chrome/capabilities.go | 2 +- example_test.go | 2 +- firefox/capabilities.go | 2 +- go.mod | 5 +---- internal/seleniumtest/seleniumtest.go | 10 +++++----- remote.go | 4 ++-- sauce_test.go | 6 +++--- selenium.go | 6 +++--- selenium_test.go | 4 ++-- 9 files changed, 19 insertions(+), 22 deletions(-) diff --git a/chrome/capabilities.go b/chrome/capabilities.go index 4beca57..f9ef726 100644 --- a/chrome/capabilities.go +++ b/chrome/capabilities.go @@ -16,7 +16,7 @@ import ( "github.com/golang/protobuf/proto" "github.com/mediabuyerbot/go-crx3/pb" - "github.com/x-Xymos/selenium/internal/zip" + "github.com/tebeka/selenium/internal/zip" ) // CapabilitiesKey is the key in the top-level Capabilities map under which diff --git a/example_test.go b/example_test.go index a740bbc..f66e172 100644 --- a/example_test.go +++ b/example_test.go @@ -6,7 +6,7 @@ import ( "strings" "time" - "github.com/x-Xymos/selenium" + "github.com/tebeka/selenium" ) // This example shows how to navigate to a http://play.golang.org page, input a diff --git a/firefox/capabilities.go b/firefox/capabilities.go index 8e1f69f..5eb23b0 100644 --- a/firefox/capabilities.go +++ b/firefox/capabilities.go @@ -5,7 +5,7 @@ import ( "bytes" "encoding/base64" - "github.com/x-Xymos/selenium/internal/zip" + "github.com/tebeka/selenium/internal/zip" ) // CapabilitiesKey is the name of the Firefox-specific key in the WebDriver diff --git a/go.mod b/go.mod index ca4288b..db9cc22 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,7 @@ -module github.com/x-Xymos/selenium/v1 +module github.com/tebeka/selenium go 1.12 -//replace github.com/x-Xymos/selenium v1.0.0 => /home/xymos/go/src/selenium - require ( cloud.google.com/go v0.41.0 github.com/BurntSushi/xgbutil v0.0.0-20160919175755-f7c97cef3b4e @@ -14,6 +12,5 @@ require ( github.com/google/go-cmp v0.5.5 github.com/google/go-github/v27 v27.0.4 github.com/mediabuyerbot/go-crx3 v1.3.1 - github.com/x-Xymos/selenium v1.0.0 google.golang.org/api v0.7.0 ) diff --git a/internal/seleniumtest/seleniumtest.go b/internal/seleniumtest/seleniumtest.go index 1c1d412..e225928 100644 --- a/internal/seleniumtest/seleniumtest.go +++ b/internal/seleniumtest/seleniumtest.go @@ -24,11 +24,11 @@ import ( socks5 "github.com/armon/go-socks5" "github.com/blang/semver" "github.com/google/go-cmp/cmp" - "github.com/x-Xymos/selenium" - "github.com/x-Xymos/selenium/chrome" - "github.com/x-Xymos/selenium/firefox" - "github.com/x-Xymos/selenium/log" - "github.com/x-Xymos/selenium/sauce" + "github.com/tebeka/selenium" + "github.com/tebeka/selenium/chrome" + "github.com/tebeka/selenium/firefox" + "github.com/tebeka/selenium/log" + "github.com/tebeka/selenium/sauce" ) type Config struct { diff --git a/remote.go b/remote.go index ecea69e..7fbf52d 100644 --- a/remote.go +++ b/remote.go @@ -18,8 +18,8 @@ import ( "time" "github.com/blang/semver" - "github.com/x-Xymos/selenium/firefox" - "github.com/x-Xymos/selenium/log" + "github.com/tebeka/selenium/firefox" + "github.com/tebeka/selenium/log" ) // Errors returned by Selenium server. diff --git a/sauce_test.go b/sauce_test.go index 4e5be92..784fb8a 100644 --- a/sauce_test.go +++ b/sauce_test.go @@ -7,9 +7,9 @@ import ( "testing" "github.com/blang/semver" - "github.com/x-Xymos/selenium" - "github.com/x-Xymos/selenium/internal/seleniumtest" - "github.com/x-Xymos/selenium/sauce" + "github.com/tebeka/selenium" + "github.com/tebeka/selenium/internal/seleniumtest" + "github.com/tebeka/selenium/sauce" ) var ( diff --git a/selenium.go b/selenium.go index 4848bef..8c2beb3 100644 --- a/selenium.go +++ b/selenium.go @@ -3,9 +3,9 @@ package selenium import ( "time" - "github.com/x-Xymos/selenium/chrome" - "github.com/x-Xymos/selenium/firefox" - "github.com/x-Xymos/selenium/log" + "github.com/tebeka/selenium/chrome" + "github.com/tebeka/selenium/firefox" + "github.com/tebeka/selenium/log" ) // TODO(minusnine): make an enum type called FindMethod. diff --git a/selenium_test.go b/selenium_test.go index 1171c69..2713d00 100644 --- a/selenium_test.go +++ b/selenium_test.go @@ -14,8 +14,8 @@ import ( "github.com/blang/semver" "github.com/golang/glog" - "github.com/x-Xymos/selenium" - "github.com/x-Xymos/selenium/internal/seleniumtest" + "github.com/tebeka/selenium" + "github.com/tebeka/selenium/internal/seleniumtest" ) var ( From 52924d9364b69e2b968906dbb82db520c3f631fb Mon Sep 17 00:00:00 2001 From: Xymos Date: Fri, 7 May 2021 23:15:28 +0100 Subject: [PATCH 20/25] reverted back package path --- go.mod | 6 +++--- go.sum | 12 ------------ 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index db9cc22..cbb519e 100644 --- a/go.mod +++ b/go.mod @@ -8,9 +8,9 @@ require ( github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 github.com/blang/semver v3.5.1+incompatible github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b - github.com/golang/protobuf v1.5.2 - github.com/google/go-cmp v0.5.5 + github.com/golang/protobuf v1.3.4 + github.com/google/go-cmp v0.3.0 github.com/google/go-github/v27 v27.0.4 github.com/mediabuyerbot/go-crx3 v1.3.1 google.golang.org/api v0.7.0 -) +) \ No newline at end of file diff --git a/go.sum b/go.sum index 68a250d..28a9333 100644 --- a/go.sum +++ b/go.sum @@ -50,16 +50,11 @@ github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.4 h1:87PNWwrRvUSnqS4dlcBU/ftvOIBep4sYuBLlh6rX2wk= github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-github/v27 v27.0.4 h1:N/EEqsvJLgqTbepTiMBz+12KhwLovv6YvwpRezd+4Fg= github.com/google/go-github/v27 v27.0.4/go.mod h1:/0Gr8pJ55COkmv+S/yPKCczSkUPIM/LnFyubufRNIS0= github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= @@ -130,8 +125,6 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= -github.com/x-Xymos/selenium v1.0.0 h1:YdxU7V8PF4No8Opf8/E90xflYyZNt7WlKy8lgaEo/vo= -github.com/x-Xymos/selenium v1.0.0/go.mod h1:TnTHK4j2+rgi3Kwk3PY0wbXwn8/ZeCJQQmSDk5Zn+e8= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= @@ -206,8 +199,6 @@ golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBn golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190624190245-7f2218787638/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0 h1:9sdfJOzWlkqPltHAuzT2Cp+yrBeY1KRVYgms8soxMwM= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= @@ -228,9 +219,6 @@ google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiq google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/grpc v1.21.1 h1:j6XxA85m/6txkUCHvzlV5f+HBNl/1r5cZ2A/3IEFOO8= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From 10126f67b2d15fb938b7bd7d1eb8059aaa828f4c Mon Sep 17 00:00:00 2001 From: Xymos Date: Mon, 10 May 2021 10:37:24 +0100 Subject: [PATCH 21/25] v2 --- chrome/capabilities.go | 2 +- example_test.go | 2 +- firefox/capabilities.go | 2 +- go.mod | 4 ++-- internal/seleniumtest/seleniumtest.go | 10 +++++----- remote.go | 4 ++-- sauce_test.go | 6 +++--- selenium.go | 6 +++--- selenium_test.go | 4 ++-- 9 files changed, 20 insertions(+), 20 deletions(-) diff --git a/chrome/capabilities.go b/chrome/capabilities.go index f9ef726..cb487a1 100644 --- a/chrome/capabilities.go +++ b/chrome/capabilities.go @@ -16,7 +16,7 @@ import ( "github.com/golang/protobuf/proto" "github.com/mediabuyerbot/go-crx3/pb" - "github.com/tebeka/selenium/internal/zip" + "github.com/x-Xymos/selenium/v2/internal/zip" ) // CapabilitiesKey is the key in the top-level Capabilities map under which diff --git a/example_test.go b/example_test.go index f66e172..c94fba4 100644 --- a/example_test.go +++ b/example_test.go @@ -6,7 +6,7 @@ import ( "strings" "time" - "github.com/tebeka/selenium" + "github.com/x-Xymos/selenium/v2" ) // This example shows how to navigate to a http://play.golang.org page, input a diff --git a/firefox/capabilities.go b/firefox/capabilities.go index 5eb23b0..2469c5e 100644 --- a/firefox/capabilities.go +++ b/firefox/capabilities.go @@ -5,7 +5,7 @@ import ( "bytes" "encoding/base64" - "github.com/tebeka/selenium/internal/zip" + "github.com/x-Xymos/selenium/v2/internal/zip" ) // CapabilitiesKey is the name of the Firefox-specific key in the WebDriver diff --git a/go.mod b/go.mod index cbb519e..52e3688 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/tebeka/selenium +module github.com/x-Xymos/selenium/v2 go 1.12 @@ -13,4 +13,4 @@ require ( github.com/google/go-github/v27 v27.0.4 github.com/mediabuyerbot/go-crx3 v1.3.1 google.golang.org/api v0.7.0 -) \ No newline at end of file +) diff --git a/internal/seleniumtest/seleniumtest.go b/internal/seleniumtest/seleniumtest.go index e225928..8eca253 100644 --- a/internal/seleniumtest/seleniumtest.go +++ b/internal/seleniumtest/seleniumtest.go @@ -24,11 +24,11 @@ import ( socks5 "github.com/armon/go-socks5" "github.com/blang/semver" "github.com/google/go-cmp/cmp" - "github.com/tebeka/selenium" - "github.com/tebeka/selenium/chrome" - "github.com/tebeka/selenium/firefox" - "github.com/tebeka/selenium/log" - "github.com/tebeka/selenium/sauce" + "github.com/x-Xymos/selenium/v2" + "github.com/x-Xymos/selenium/v2/chrome" + "github.com/x-Xymos/selenium/v2/firefox" + "github.com/x-Xymos/selenium/v2/log" + "github.com/x-Xymos/selenium/v2/sauce" ) type Config struct { diff --git a/remote.go b/remote.go index 7fbf52d..780c47d 100644 --- a/remote.go +++ b/remote.go @@ -18,8 +18,8 @@ import ( "time" "github.com/blang/semver" - "github.com/tebeka/selenium/firefox" - "github.com/tebeka/selenium/log" + "github.com/x-Xymos/selenium/v2/firefox" + "github.com/x-Xymos/selenium/v2/log" ) // Errors returned by Selenium server. diff --git a/sauce_test.go b/sauce_test.go index 784fb8a..444b07a 100644 --- a/sauce_test.go +++ b/sauce_test.go @@ -7,9 +7,9 @@ import ( "testing" "github.com/blang/semver" - "github.com/tebeka/selenium" - "github.com/tebeka/selenium/internal/seleniumtest" - "github.com/tebeka/selenium/sauce" + "github.com/x-Xymos/selenium/v2" + "github.com/x-Xymos/selenium/v2/internal/seleniumtest" + "github.com/x-Xymos/selenium/v2/sauce" ) var ( diff --git a/selenium.go b/selenium.go index 8c2beb3..3014b3e 100644 --- a/selenium.go +++ b/selenium.go @@ -3,9 +3,9 @@ package selenium import ( "time" - "github.com/tebeka/selenium/chrome" - "github.com/tebeka/selenium/firefox" - "github.com/tebeka/selenium/log" + "github.com/x-Xymos/selenium/v2/chrome" + "github.com/x-Xymos/selenium/v2/firefox" + "github.com/x-Xymos/selenium/v2/log" ) // TODO(minusnine): make an enum type called FindMethod. diff --git a/selenium_test.go b/selenium_test.go index 2713d00..aff75dd 100644 --- a/selenium_test.go +++ b/selenium_test.go @@ -14,8 +14,8 @@ import ( "github.com/blang/semver" "github.com/golang/glog" - "github.com/tebeka/selenium" - "github.com/tebeka/selenium/internal/seleniumtest" + "github.com/x-Xymos/selenium/v2" + "github.com/x-Xymos/selenium/v2/internal/seleniumtest" ) var ( From a2aaf4fc35f2000b48fae3f28a83cda80da5be29 Mon Sep 17 00:00:00 2001 From: x-Xymos <51156539+x-Xymos@users.noreply.github.com> Date: Wed, 12 May 2021 17:25:58 +0100 Subject: [PATCH 22/25] Update example_test.go --- example_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/example_test.go b/example_test.go index f66e172..6f21d13 100644 --- a/example_test.go +++ b/example_test.go @@ -119,17 +119,17 @@ func Example() { wd.StorePointerActions("mouse1", selenium.MousePointer, wd.PointerMoveAction(0, offset, selenium.FromViewport), - wd.PointerPauseAction(250), + wd.PointerPauseAction(250 * time.Millisecond), wd.PointerDownAction(selenium.LeftButton), - wd.PointerPauseAction(250), + wd.PointerPauseAction(250 * time.Millisecond), wd.PointerUpAction(selenium.LeftButton), ) wd.StoreKeyActions("keyboard1", wd.KeyDownAction(selenium.ControlKey), - wd.KeyPauseAction(50), + wd.KeyPauseAction(50 * time.Millisecond), wd.KeyDownAction("a"), - wd.KeyPauseAction(50), + wd.KeyPauseAction(50 * time.Millisecond), wd.KeyUpAction("a"), wd.KeyUpAction(selenium.ControlKey), wd.KeyDownAction("h"), From 70c34f46de3dbde68ff5a1b449e0c567a834bf92 Mon Sep 17 00:00:00 2001 From: Xymos Date: Wed, 13 Oct 2021 13:32:30 +0100 Subject: [PATCH 23/25] added review changes --- chrome/capabilities.go | 2 +- example_test.go | 72 +++++++++++++++++---------- firefox/capabilities.go | 2 +- go.mod | 4 +- internal/seleniumtest/seleniumtest.go | 10 ++-- remote.go | 72 +++++++++++++++++---------- sauce_test.go | 6 +-- selenium.go | 63 ++++++----------------- selenium_test.go | 4 +- 9 files changed, 122 insertions(+), 113 deletions(-) diff --git a/chrome/capabilities.go b/chrome/capabilities.go index cb487a1..f9ef726 100644 --- a/chrome/capabilities.go +++ b/chrome/capabilities.go @@ -16,7 +16,7 @@ import ( "github.com/golang/protobuf/proto" "github.com/mediabuyerbot/go-crx3/pb" - "github.com/x-Xymos/selenium/v2/internal/zip" + "github.com/tebeka/selenium/internal/zip" ) // CapabilitiesKey is the key in the top-level Capabilities map under which diff --git a/example_test.go b/example_test.go index c94fba4..e041a1c 100644 --- a/example_test.go +++ b/example_test.go @@ -6,7 +6,7 @@ import ( "strings" "time" - "github.com/x-Xymos/selenium/v2" + "github.com/tebeka/selenium" ) // This example shows how to navigate to a http://play.golang.org page, input a @@ -109,44 +109,64 @@ func Example() { // // Program exited. - //Actions example + // The following shows an example of using the Actions API. + // Please refer to the WC3 Actions spec for more detailed information. if err := wd.Get("http://play.golang.org/?simple=1"); err != nil { panic(err) } - time.Sleep(time.Second * 1) + // Create a point which will be used as an offset to click on the + // code editor text box element on the page. offset := selenium.Point{X: 100, Y: 100} - wd.StorePointerActions("mouse1", + + // Call StorePointerActions to store a number of Pointer actions which + // will be executed sequentially. + // "mouse1" is used as a unique virtual device identifier for this + // and future actions. + // selenium.MousePointer is used to identify the type of the pointer. + // The stored action chain will move the pointer and click on the code + // editor text box on the page. + selenium.StorePointerActions("mouse1", selenium.MousePointer, - wd.PointerMoveAction(0, offset, selenium.FromViewport), - wd.PointerPauseAction(250), - wd.PointerDownAction(selenium.LeftButton), - wd.PointerPauseAction(250), - wd.PointerUpAction(selenium.LeftButton), + // using selenium.FromViewport as the move origin + // which calculates the offset from 0,0. + // the other valid option is selenium.FromPointer. + selenium.PointerMoveAction(0, offset, selenium.FromViewport), + selenium.PointerPauseAction(250), + selenium.PointerDownAction(selenium.LeftButton), + selenium.PointerPauseAction(250), + selenium.PointerUpAction(selenium.LeftButton), ) - wd.StoreKeyActions("keyboard1", - wd.KeyDownAction(selenium.ControlKey), - wd.KeyPauseAction(50), - wd.KeyDownAction("a"), - wd.KeyPauseAction(50), - wd.KeyUpAction("a"), - wd.KeyUpAction(selenium.ControlKey), - wd.KeyDownAction("h"), - wd.KeyDownAction("e"), - wd.KeyDownAction("l"), - wd.KeyDownAction("l"), - wd.KeyDownAction("o"), + // Call StoreKeyActions to store a number of Key actions which + // will be executed sequentially. + // "keyboard1" is used as a unique virtual device identifier + // for this and future actions. + // The stored action chain will send keyboard inputs to the browser. + selenium.StoreKeyActions("keyboard1", + selenium.KeyDownAction(selenium.ControlKey), + selenium.KeyPauseAction(50), + selenium.KeyDownAction("a"), + selenium.KeyPauseAction(50), + selenium.KeyUpAction("a"), + selenium.KeyUpAction(selenium.ControlKey), + selenium.KeyDownAction("h"), + selenium.KeyDownAction("e"), + selenium.KeyDownAction("l"), + selenium.KeyDownAction("l"), + selenium.KeyDownAction("o"), ) - err = wd.PerformActions() - if err != nil { + // Call PerformActions to execute stored action - based on + // the order of the previous calls, PointerActions will be + // executed first and then KeyActions. + if err := wd.PerformActions(); err != nil { panic(err) } - //calling ReleaseActions to release the KeyDownActions we've performed so we don't have to call KeyUpAction explicitly - err = wd.ReleaseActions() - if err != nil { + // Call ReleaseActions to release any PointerDown or + // KeyDown Actions that haven't been released through an Action. + if err := wd.ReleaseActions(); err != nil { panic(err) } diff --git a/firefox/capabilities.go b/firefox/capabilities.go index 2469c5e..5eb23b0 100644 --- a/firefox/capabilities.go +++ b/firefox/capabilities.go @@ -5,7 +5,7 @@ import ( "bytes" "encoding/base64" - "github.com/x-Xymos/selenium/v2/internal/zip" + "github.com/tebeka/selenium/internal/zip" ) // CapabilitiesKey is the name of the Firefox-specific key in the WebDriver diff --git a/go.mod b/go.mod index 52e3688..cbb519e 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/x-Xymos/selenium/v2 +module github.com/tebeka/selenium go 1.12 @@ -13,4 +13,4 @@ require ( github.com/google/go-github/v27 v27.0.4 github.com/mediabuyerbot/go-crx3 v1.3.1 google.golang.org/api v0.7.0 -) +) \ No newline at end of file diff --git a/internal/seleniumtest/seleniumtest.go b/internal/seleniumtest/seleniumtest.go index 8eca253..e225928 100644 --- a/internal/seleniumtest/seleniumtest.go +++ b/internal/seleniumtest/seleniumtest.go @@ -24,11 +24,11 @@ import ( socks5 "github.com/armon/go-socks5" "github.com/blang/semver" "github.com/google/go-cmp/cmp" - "github.com/x-Xymos/selenium/v2" - "github.com/x-Xymos/selenium/v2/chrome" - "github.com/x-Xymos/selenium/v2/firefox" - "github.com/x-Xymos/selenium/v2/log" - "github.com/x-Xymos/selenium/v2/sauce" + "github.com/tebeka/selenium" + "github.com/tebeka/selenium/chrome" + "github.com/tebeka/selenium/firefox" + "github.com/tebeka/selenium/log" + "github.com/tebeka/selenium/sauce" ) type Config struct { diff --git a/remote.go b/remote.go index 780c47d..a5a5993 100644 --- a/remote.go +++ b/remote.go @@ -18,8 +18,8 @@ import ( "time" "github.com/blang/semver" - "github.com/x-Xymos/selenium/v2/firefox" - "github.com/x-Xymos/selenium/v2/log" + "github.com/tebeka/selenium/firefox" + "github.com/tebeka/selenium/log" ) // Errors returned by Selenium server. @@ -230,6 +230,7 @@ func NewRemote(capabilities Capabilities, urlPrefix string) (WebDriver, error) { if b := capabilities["browserName"]; b != nil { wd.browser = b.(string) } + if _, err := wd.NewSession(); err != nil { return nil, err } @@ -1095,35 +1096,41 @@ func (wd *remoteWD) KeyUp(keys string) error { return wd.keyAction("keyUp", keys) } -func (wd *remoteWD) KeyPauseAction(duration time.Duration) KeyAction { +// KeyPauseAction build a KeyAction which pauses for the supplied duration. +func KeyPauseAction(duration time.Duration) KeyAction { return KeyAction{ "type": "pause", "duration": uint(duration / time.Millisecond), } } -func (wd *remoteWD) KeyUpAction(key string) KeyAction { +// KeyUpAction build a KeyAction press. +func KeyUpAction(key string) KeyAction { return KeyAction{ "type": "keyUp", "value": key, } } -func (wd *remoteWD) KeyDownAction(key string) KeyAction { +// KeyDownAction build a KeyAction which presses and holds +// the specified key. +func KeyDownAction(key string) KeyAction { return KeyAction{ "type": "keyDown", "value": key, } } -func (wd *remoteWD) PointerPauseAction(duration time.Duration) PointerAction { +// PointerPause build a PointerAction which pauses for the supplied duration. +func PointerPauseAction(duration time.Duration) PointerAction { return PointerAction{ "type": "pause", "duration": uint(duration / time.Millisecond), } } -func (wd *remoteWD) PointerMoveAction(duration time.Duration, offset Point, origin PointerMoveOrigin) PointerAction { +// PointerMove build a PointerAction which moves the pointer. +func PointerMoveAction(duration time.Duration, offset Point, origin PointerMoveOrigin) PointerAction { return PointerAction{ "type": "pointerMove", "duration": uint(duration / time.Millisecond), @@ -1133,51 +1140,66 @@ func (wd *remoteWD) PointerMoveAction(duration time.Duration, offset Point, orig } } -func (wd *remoteWD) PointerUpAction(button MouseButton) PointerAction { +// PointerUp build an action which releases the specified pointer key. +func PointerUpAction(button MouseButton) PointerAction { return PointerAction{ "type": "pointerUp", "button": button, } } -func (wd *remoteWD) PointerDownAction(button MouseButton) PointerAction { +// PointerDown build a PointerAction which presses +// and holds the specified pointer key. +func PointerDownAction(button MouseButton) PointerAction { return PointerAction{ "type": "pointerDown", "button": button, } } -func (wd *remoteWD) StoreKeyActions(inputId string, actions ...KeyAction) { - _actions := []map[string]interface{}{} +// storedActions an array used to store KeyActions and PointerActions. +var storedActions Actions + +// StoreKeyActions store provided actions until they are executed +// by PerformActions or released by ReleaseActions. +// inputID is a string used as a unique virtual device identifier for this +// and future actions, the value can be set to any valid string +// and used to refer to this specific device in future calls. +func StoreKeyActions(inputID string, actions ...KeyAction) { + rawActions := []map[string]interface{}{} for _, action := range actions { - _actions = append(_actions, action) + rawActions = append(rawActions, action) } - wd.actions = append(wd.actions, map[string]interface{}{ + storedActions = append(storedActions, map[string]interface{}{ "type": "key", - "id": inputId, - "actions": _actions, + "id": inputID, + "actions": rawActions, }) } -func (wd *remoteWD) StorePointerActions(inputId string, pointerType PointerType, actions ...PointerAction) { - _actions := []map[string]interface{}{} +// StorePointerActions store provided actions until they are executed +// by PerformActions or released by ReleaseActions. +// inputID is a string used as a unique virtual device identifier for this +// and future actions, the value can be set to any valid string +// and used to refer to this specific device in future calls. +func StorePointerActions(inputID string, pointer PointerType, actions ...PointerAction) { + rawActions := []map[string]interface{}{} for _, action := range actions { - _actions = append(_actions, action) + rawActions = append(rawActions, action) } - - wd.actions = append(wd.actions, map[string]interface{}{ + storedActions = append(storedActions, map[string]interface{}{ "type": "pointer", - "id": inputId, - "parameters": map[string]string{"pointerType": string(pointerType)}, - "actions": _actions, + "id": inputID, + "parameters": map[string]string{"pointerType": string(pointer)}, + "actions": rawActions, }) } func (wd *remoteWD) PerformActions() error { err := wd.voidCommand("/session/%s/actions", map[string]interface{}{ - "actions": wd.actions, + "actions": storedActions, }) - wd.actions = nil + storedActions = nil return err } diff --git a/sauce_test.go b/sauce_test.go index 444b07a..784fb8a 100644 --- a/sauce_test.go +++ b/sauce_test.go @@ -7,9 +7,9 @@ import ( "testing" "github.com/blang/semver" - "github.com/x-Xymos/selenium/v2" - "github.com/x-Xymos/selenium/v2/internal/seleniumtest" - "github.com/x-Xymos/selenium/v2/sauce" + "github.com/tebeka/selenium" + "github.com/tebeka/selenium/internal/seleniumtest" + "github.com/tebeka/selenium/sauce" ) var ( diff --git a/selenium.go b/selenium.go index 3014b3e..3f649a9 100644 --- a/selenium.go +++ b/selenium.go @@ -3,9 +3,9 @@ package selenium import ( "time" - "github.com/x-Xymos/selenium/v2/chrome" - "github.com/x-Xymos/selenium/v2/firefox" - "github.com/x-Xymos/selenium/v2/log" + "github.com/tebeka/selenium/chrome" + "github.com/tebeka/selenium/firefox" + "github.com/tebeka/selenium/log" ) // TODO(minusnine): make an enum type called FindMethod. @@ -225,6 +225,8 @@ const ( SameSiteEmpty = "" ) +// PointerType type of pointer used by StorePointerActions. +// There are 3 different types according to the WC3 implementation. type PointerType string const ( @@ -233,27 +235,24 @@ const ( TouchPointer = "touch" ) -//controls how the offset for the pointer move action is calculated -// -// FromViewport: calculate the offset from the viewport at 0,0 -// -// FromPointer: calculate the offset from the current pointer position +// PointerMoveOrigin controls how the offset for +// the pointer move action is calculated. type PointerMoveOrigin string -//todo: add FromElement which calculates the -//offset from the provided element const ( + // FromViewport calculates the offset from the viewport at 0,0. FromViewport PointerMoveOrigin = "viewport" - FromPointer = "pointer" + // FromPointer calculates the offset from the current pointer position. + FromPointer = "pointer" ) -//KeyAction +// KeyAction type used to store key value pairs. type KeyAction map[string]interface{} -//KeyAction +// KeyAction type used to store key value pairs. type PointerAction map[string]interface{} -// //Actions holds a map of stored KeyActions and PointerActions +// Actions array type used to store KeyActions and PointerActions. type Actions []map[string]interface{} // WebDriver defines methods supported by WebDriver drivers. @@ -363,42 +362,10 @@ type WebDriver interface { // ButtonUp causes the left mouse button to be released. ButtonUp() error - // KeyPauseAction build a KeyAction which pauses for the supplied duration - KeyPauseAction(duration time.Duration) KeyAction - // KeyUpAction build a KeyAction press - KeyUpAction(key string) KeyAction - // KeyDownAction build a KeyAction which presses and holds the specified - // key until explicitly released by KeyUpAction or ReleaseActions - KeyDownAction(key string) KeyAction - // StoreKeyActions - // - // inputId: unique device identifier for the stored action - // - // actions: any number of KeyActions - StoreKeyActions(inputId string, actions ...KeyAction) - - // PointerPause build a PointerAction which pauses for the supplied duration - PointerPauseAction(duration time.Duration) PointerAction - // PointerMove build a PointerAction which moves the pointer - PointerMoveAction(duration time.Duration, offset Point, origin PointerMoveOrigin) PointerAction - // PointerUp build an action which releases the specified pointer key - PointerUpAction(button MouseButton) PointerAction - // PointerDown build a PointerAction which presses and holds the specified - // pointer key until explicitly released by PointerUp or ReleaseActions - PointerDownAction(button MouseButton) PointerAction - // StorePointerActions - // - // inputId: unique device identifier for the stored action - // - // pointerType: type of pointer - accepts: MousePointer, TouchPointer, PenPointer - // - //actions: any number of PointerActions - StorePointerActions(inputId string, pointerType PointerType, actions ...PointerAction) - - // PerformActions performs stored actions + // PerformActions executes stored actions. PerformActions() error // ReleaseActions releases keys and pointer buttons if they are pressed, - // triggering any events as if they were performed by a regular action + // triggering any events as if they were performed by a regular action. ReleaseActions() error // SendModifier sends the modifier key to the active element. The modifier diff --git a/selenium_test.go b/selenium_test.go index aff75dd..2713d00 100644 --- a/selenium_test.go +++ b/selenium_test.go @@ -14,8 +14,8 @@ import ( "github.com/blang/semver" "github.com/golang/glog" - "github.com/x-Xymos/selenium/v2" - "github.com/x-Xymos/selenium/v2/internal/seleniumtest" + "github.com/tebeka/selenium" + "github.com/tebeka/selenium/internal/seleniumtest" ) var ( From 2d01720a6f0af1669683026050e3c4bdcc686917 Mon Sep 17 00:00:00 2001 From: Xymos Date: Wed, 13 Oct 2021 13:40:11 +0100 Subject: [PATCH 24/25] remove actions from remoteWD struct --- remote.go | 1 - 1 file changed, 1 deletion(-) diff --git a/remote.go b/remote.go index a5a5993..51ace1c 100644 --- a/remote.go +++ b/remote.go @@ -48,7 +48,6 @@ var remoteErrors = map[int]string{ type remoteWD struct { id, urlPrefix string - actions Actions capabilities Capabilities w3cCompatible bool browser string From d65aeb3158ce171a9c3ca93f4ced6309ea2c8257 Mon Sep 17 00:00:00 2001 From: Xymos Date: Fri, 15 Oct 2021 16:25:25 +0100 Subject: [PATCH 25/25] review changes --- remote.go | 47 ++++++++++++++++++----------------------------- selenium.go | 24 +++++++++++++++++++----- 2 files changed, 37 insertions(+), 34 deletions(-) diff --git a/remote.go b/remote.go index 51ace1c..327219c 100644 --- a/remote.go +++ b/remote.go @@ -47,9 +47,11 @@ var remoteErrors = map[int]string{ } type remoteWD struct { - id, urlPrefix string - capabilities Capabilities - w3cCompatible bool + id, urlPrefix string + capabilities Capabilities + w3cCompatible bool + // storedActions stores KeyActions and PointerActions for later execution. + storedActions Actions browser string browserVersion semver.Version } @@ -1095,7 +1097,7 @@ func (wd *remoteWD) KeyUp(keys string) error { return wd.keyAction("keyUp", keys) } -// KeyPauseAction build a KeyAction which pauses for the supplied duration. +// KeyPauseAction builds a KeyAction which pauses for the supplied duration. func KeyPauseAction(duration time.Duration) KeyAction { return KeyAction{ "type": "pause", @@ -1103,7 +1105,7 @@ func KeyPauseAction(duration time.Duration) KeyAction { } } -// KeyUpAction build a KeyAction press. +// KeyUpAction builds a KeyAction press. func KeyUpAction(key string) KeyAction { return KeyAction{ "type": "keyUp", @@ -1111,7 +1113,7 @@ func KeyUpAction(key string) KeyAction { } } -// KeyDownAction build a KeyAction which presses and holds +// KeyDownAction builds a KeyAction which presses and holds // the specified key. func KeyDownAction(key string) KeyAction { return KeyAction{ @@ -1120,7 +1122,7 @@ func KeyDownAction(key string) KeyAction { } } -// PointerPause build a PointerAction which pauses for the supplied duration. +// PointerPause builds a PointerAction which pauses for the supplied duration. func PointerPauseAction(duration time.Duration) PointerAction { return PointerAction{ "type": "pause", @@ -1128,7 +1130,7 @@ func PointerPauseAction(duration time.Duration) PointerAction { } } -// PointerMove build a PointerAction which moves the pointer. +// PointerMove builds a PointerAction which moves the pointer. func PointerMoveAction(duration time.Duration, offset Point, origin PointerMoveOrigin) PointerAction { return PointerAction{ "type": "pointerMove", @@ -1139,7 +1141,7 @@ func PointerMoveAction(duration time.Duration, offset Point, origin PointerMoveO } } -// PointerUp build an action which releases the specified pointer key. +// PointerUp builds an action which releases the specified pointer key. func PointerUpAction(button MouseButton) PointerAction { return PointerAction{ "type": "pointerUp", @@ -1147,7 +1149,7 @@ func PointerUpAction(button MouseButton) PointerAction { } } -// PointerDown build a PointerAction which presses +// PointerDown builds a PointerAction which presses // and holds the specified pointer key. func PointerDownAction(button MouseButton) PointerAction { return PointerAction{ @@ -1156,37 +1158,24 @@ func PointerDownAction(button MouseButton) PointerAction { } } -// storedActions an array used to store KeyActions and PointerActions. -var storedActions Actions - -// StoreKeyActions store provided actions until they are executed -// by PerformActions or released by ReleaseActions. -// inputID is a string used as a unique virtual device identifier for this -// and future actions, the value can be set to any valid string -// and used to refer to this specific device in future calls. -func StoreKeyActions(inputID string, actions ...KeyAction) { +func (wd *remoteWD) StoreKeyActions(inputID string, actions ...KeyAction) { rawActions := []map[string]interface{}{} for _, action := range actions { rawActions = append(rawActions, action) } - storedActions = append(storedActions, map[string]interface{}{ + wd.storedActions = append(wd.storedActions, map[string]interface{}{ "type": "key", "id": inputID, "actions": rawActions, }) } -// StorePointerActions store provided actions until they are executed -// by PerformActions or released by ReleaseActions. -// inputID is a string used as a unique virtual device identifier for this -// and future actions, the value can be set to any valid string -// and used to refer to this specific device in future calls. -func StorePointerActions(inputID string, pointer PointerType, actions ...PointerAction) { +func (wd *remoteWD) StorePointerActions(inputID string, pointer PointerType, actions ...PointerAction) { rawActions := []map[string]interface{}{} for _, action := range actions { rawActions = append(rawActions, action) } - storedActions = append(storedActions, map[string]interface{}{ + wd.storedActions = append(wd.storedActions, map[string]interface{}{ "type": "pointer", "id": inputID, "parameters": map[string]string{"pointerType": string(pointer)}, @@ -1196,9 +1185,9 @@ func StorePointerActions(inputID string, pointer PointerType, actions ...Pointer func (wd *remoteWD) PerformActions() error { err := wd.voidCommand("/session/%s/actions", map[string]interface{}{ - "actions": storedActions, + "actions": wd.storedActions, }) - storedActions = nil + wd.storedActions = nil return err } diff --git a/selenium.go b/selenium.go index 3f649a9..1563231 100644 --- a/selenium.go +++ b/selenium.go @@ -225,7 +225,7 @@ const ( SameSiteEmpty = "" ) -// PointerType type of pointer used by StorePointerActions. +// PointerType is the type of pointer used by StorePointerActions. // There are 3 different types according to the WC3 implementation. type PointerType string @@ -246,13 +246,13 @@ const ( FromPointer = "pointer" ) -// KeyAction type used to store key value pairs. +// KeyAction represents an activity involving a keyboard key. type KeyAction map[string]interface{} -// KeyAction type used to store key value pairs. +// PointerAction represents an activity involving a pointer. type PointerAction map[string]interface{} -// Actions array type used to store KeyActions and PointerActions. +// Actions stores KeyActions and PointerActions for later execution. type Actions []map[string]interface{} // WebDriver defines methods supported by WebDriver drivers. @@ -362,7 +362,21 @@ type WebDriver interface { // ButtonUp causes the left mouse button to be released. ButtonUp() error - // PerformActions executes stored actions. + // StoreKeyActions store provided actions until they are executed + // by PerformActions or released by ReleaseActions. + // inputID is a string used as a unique virtual device identifier for this + // and future actions, the value can be set to any valid string + // and used to refer to this specific device in future calls. + StoreKeyActions(inputID string, actions ...KeyAction) + + // StorePointerActions store provided actions until they are executed + // by PerformActions or released by ReleaseActions. + // inputID is a string used as a unique virtual device identifier for this + // and future actions, the value can be set to any valid string + // and used to refer to this specific device in future calls. + StorePointerActions(inputID string, pointer PointerType, actions ...PointerAction) + + // PerformActions executes actions previously stored by calls to StorePointerActions and StoreKeyActions. PerformActions() error // ReleaseActions releases keys and pointer buttons if they are pressed, // triggering any events as if they were performed by a regular action.