webdriver 0.4.0 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/Gemfile.lock +1 -1
- data/e2e/all.rb +1 -0
- data/e2e/element.rb +9 -0
- data/examples/args.rb +1 -2
- data/examples/find_and_click.rb +13 -0
- data/examples/text_and_html.rb +12 -0
- data/lib/webdriver.rb +2 -0
- data/lib/webdriver/connection.rb +13 -7
- data/lib/webdriver/cookie.rb +50 -0
- data/lib/webdriver/element.rb +87 -0
- data/lib/webdriver/prefix_connection.rb +6 -4
- data/lib/webdriver/session.rb +128 -1
- data/lib/webdriver/version.rb +1 -1
- data/lib/webdriver/window.rb +3 -1
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9d1de554c15665df74da24e943ca9e50d9db27622723ab7e8229464ca19ef5c
|
4
|
+
data.tar.gz: c753336a3fe63b440f34a8a7d259bb0a28da054050c084647a27e28daf691a0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b261d00f5c46ca37743120b5ed1689aaaebb786c67a0568442af7fca4094b455ddd4721542948e36a328b85ce13bc9c1bf807f2953c277169115c42901f5084c
|
7
|
+
data.tar.gz: 456140e014ff199b04d6bbd7f55a8932f47c1f6a2bc60376a4f3e140b450b9e871eed3234aefacbba5364e73828f53639025e59ec815315de3b581ff5eb47c74
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.6.
|
1
|
+
2.6.5
|
data/Gemfile.lock
CHANGED
data/e2e/all.rb
CHANGED
data/e2e/element.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
session = $client.session!
|
2
|
+
|
3
|
+
e = session.element "css selector", "html"
|
4
|
+
raise "text" unless e.text == ""
|
5
|
+
raise "property" unless e.property("innerHTML") == "<head></head><body></body>"
|
6
|
+
raise "attribute" unless e.attribute("innerHTML") == "<head></head><body></body>"
|
7
|
+
raise "tag" unless e.tag == "html"
|
8
|
+
|
9
|
+
raise "child" unless e.element("css selector", "body").tag == "body"
|
data/examples/args.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require_relative "../lib/webdriver"
|
2
|
-
|
2
|
+
|
3
3
|
capabilities = {
|
4
4
|
chromeOptions: {
|
5
5
|
args: [
|
@@ -13,5 +13,4 @@ wd = Webdriver::Client.new "http://localhost:9515/wd/hub", capabilities
|
|
13
13
|
s = wd.session!
|
14
14
|
w = s.windows.first
|
15
15
|
|
16
|
-
binding.pry
|
17
16
|
s.delete!
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative "../lib/webdriver"
|
2
|
+
|
3
|
+
s = (Webdriver::Client.new "http://localhost:9515/").session!
|
4
|
+
|
5
|
+
s.url! "https://example.com"
|
6
|
+
|
7
|
+
3.times do |i|
|
8
|
+
all_a_els = s.elements "css selector", "a"
|
9
|
+
all_a_els&.first.click!
|
10
|
+
sleep 1
|
11
|
+
end
|
12
|
+
|
13
|
+
s.delete!
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require_relative "../lib/webdriver"
|
2
|
+
|
3
|
+
s = (Webdriver::Client.new "http://localhost:9515/").session!
|
4
|
+
|
5
|
+
s.url! "https://example.com"
|
6
|
+
html_el = s.element "css selector", "html"
|
7
|
+
|
8
|
+
puts html_el.text
|
9
|
+
puts "-- 8< -----------------------"
|
10
|
+
puts html_el.property "innerHTML"
|
11
|
+
|
12
|
+
s.delete!
|
data/lib/webdriver.rb
CHANGED
data/lib/webdriver/connection.rb
CHANGED
@@ -1,21 +1,23 @@
|
|
1
1
|
module Webdriver
|
2
2
|
class Connection
|
3
|
-
def initialize
|
3
|
+
def initialize endpoint
|
4
4
|
uri = URI(endpoint)
|
5
5
|
@http = Net::HTTP.new uri.hostname, uri.port
|
6
6
|
end
|
7
7
|
|
8
|
-
def get
|
8
|
+
def get path, headers={}
|
9
9
|
call :get, path, headers
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
|
+
def post path, headers={}, body=nil
|
12
13
|
call :post, path, headers, body
|
13
14
|
end
|
14
|
-
|
15
|
+
|
16
|
+
def post path, headers={}, body=nil
|
15
17
|
call :post, path, headers, body
|
16
18
|
end
|
17
19
|
|
18
|
-
def call
|
20
|
+
def call method, path, headers={}, body={}
|
19
21
|
path = "/#{path}"
|
20
22
|
body_json = body.to_json if body
|
21
23
|
Webdriver.debug [method, path, headers, body_json]
|
@@ -45,12 +47,16 @@ module Webdriver
|
|
45
47
|
else # everything else works like this
|
46
48
|
value
|
47
49
|
end
|
50
|
+
when 1..nil
|
51
|
+
# 10: stale element reference: element is not attached to the page document
|
52
|
+
# 11: element not interactable
|
53
|
+
error_message = value.dig("message")
|
54
|
+
raise "#{status}: #{error_message}"
|
48
55
|
else
|
49
56
|
if method == :get && path == "/status"
|
50
57
|
value
|
51
58
|
else
|
52
|
-
|
53
|
-
raise "err"
|
59
|
+
raise [:unknown, response_body]
|
54
60
|
end
|
55
61
|
end
|
56
62
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Webdriver
|
2
|
+
class Cookie
|
3
|
+
attr_reader :name
|
4
|
+
|
5
|
+
def initialize(name, connection)
|
6
|
+
@name = name
|
7
|
+
@session_connection = connection
|
8
|
+
@connection = Webdriver::PrefixConnection.new "cookie/#{@name}", connection
|
9
|
+
end
|
10
|
+
|
11
|
+
def delete!
|
12
|
+
@connection.delete
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
def domain
|
17
|
+
__refresh["domain"]
|
18
|
+
end
|
19
|
+
|
20
|
+
def expiry
|
21
|
+
__refresh["expiry"]
|
22
|
+
end
|
23
|
+
|
24
|
+
def http_only
|
25
|
+
__refresh["httpOnly"]
|
26
|
+
end
|
27
|
+
|
28
|
+
def path
|
29
|
+
__refresh["path"]
|
30
|
+
end
|
31
|
+
|
32
|
+
def same_site
|
33
|
+
__refresh["sameSite"]
|
34
|
+
end
|
35
|
+
|
36
|
+
def secure
|
37
|
+
__refresh["secure"]
|
38
|
+
end
|
39
|
+
|
40
|
+
def value
|
41
|
+
__refresh["value"]
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def __refresh
|
47
|
+
@connection.get
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module Webdriver
|
2
|
+
class Element
|
3
|
+
attr_reader :id
|
4
|
+
|
5
|
+
def initialize(id, connection)
|
6
|
+
@id = id
|
7
|
+
|
8
|
+
@session_connection = connection
|
9
|
+
@connection = Webdriver::PrefixConnection.new "element/#{@id}", connection
|
10
|
+
end
|
11
|
+
|
12
|
+
def screenshot
|
13
|
+
@connection.get "screenshot"
|
14
|
+
end
|
15
|
+
|
16
|
+
# checkbox
|
17
|
+
def selected?
|
18
|
+
@connection.get "selected"
|
19
|
+
end
|
20
|
+
|
21
|
+
# form control enabled
|
22
|
+
def enabled?
|
23
|
+
@connection.get "enabled"
|
24
|
+
end
|
25
|
+
|
26
|
+
def clear!
|
27
|
+
@connection.post "clear"
|
28
|
+
click!
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def value! value
|
33
|
+
value_string = value.to_s
|
34
|
+
if value_string == ""
|
35
|
+
clear!
|
36
|
+
else
|
37
|
+
@connection.post "value", {}, {
|
38
|
+
value: [value_string]
|
39
|
+
}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def text
|
44
|
+
@connection.get "text"
|
45
|
+
end
|
46
|
+
|
47
|
+
def rect
|
48
|
+
@connection.get "rect"
|
49
|
+
end
|
50
|
+
|
51
|
+
def tag
|
52
|
+
@connection.get "name"
|
53
|
+
end
|
54
|
+
|
55
|
+
def css name
|
56
|
+
@connection.get File.join("css", name)
|
57
|
+
end
|
58
|
+
|
59
|
+
def property name
|
60
|
+
@connection.get File.join("property", name)
|
61
|
+
end
|
62
|
+
|
63
|
+
def attribute name
|
64
|
+
@connection.get File.join("attribute", name)
|
65
|
+
end
|
66
|
+
|
67
|
+
def click!
|
68
|
+
@connection.post "click"
|
69
|
+
end
|
70
|
+
|
71
|
+
def element using, value
|
72
|
+
el = @connection.post "element", {}, {
|
73
|
+
using: using,
|
74
|
+
value: value
|
75
|
+
}
|
76
|
+
Webdriver::Element.new el["ELEMENT"], @session_connection
|
77
|
+
end
|
78
|
+
|
79
|
+
def elements using, value
|
80
|
+
resp = @connection.post "elements", {}, {
|
81
|
+
using: using,
|
82
|
+
value: value
|
83
|
+
}
|
84
|
+
resp.map { |el| Webdriver::Element.new el["ELEMENT"], @session_connection }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -5,17 +5,19 @@ module Webdriver
|
|
5
5
|
@connection = connection
|
6
6
|
end
|
7
7
|
|
8
|
-
def get
|
8
|
+
def get path=nil, headers={}
|
9
9
|
call :get, path, headers
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
|
+
def post path=nil, headers={}, body=nil
|
12
13
|
call :post, path, headers, body
|
13
14
|
end
|
14
|
-
|
15
|
+
|
16
|
+
def delete path=nil, headers={}, body=nil
|
15
17
|
call :delete, path, headers, body
|
16
18
|
end
|
17
19
|
|
18
|
-
def call
|
20
|
+
def call method, path=nil, headers={}, body=nil
|
19
21
|
prefixed_path = if path
|
20
22
|
"#{@prefix}/#{path}"
|
21
23
|
else
|
data/lib/webdriver/session.rb
CHANGED
@@ -9,6 +9,7 @@ module Webdriver
|
|
9
9
|
|
10
10
|
def delete!
|
11
11
|
@connection.delete
|
12
|
+
self
|
12
13
|
end
|
13
14
|
|
14
15
|
def windows
|
@@ -16,10 +17,50 @@ module Webdriver
|
|
16
17
|
value.map { |id| Webdriver::Window.new id, @connection }
|
17
18
|
end
|
18
19
|
|
20
|
+
# not implemented in chromedriver
|
21
|
+
# def source
|
22
|
+
# @connection.post "source"
|
23
|
+
# end
|
24
|
+
|
25
|
+
def dismiss_alert!
|
26
|
+
@connection.post "alert/dismiss"
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
def accept_alert!
|
31
|
+
@connection.post "alert/accept"
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
def alert_text
|
36
|
+
@connection.get "alert/text"
|
37
|
+
end
|
38
|
+
|
39
|
+
# TODO: Does not work with prompt
|
40
|
+
# def alert_text! text
|
41
|
+
# @connection.post "alert/text", {}, {
|
42
|
+
# text: text
|
43
|
+
# }
|
44
|
+
# end
|
45
|
+
|
46
|
+
# iframe id
|
47
|
+
def frame! name
|
48
|
+
@connection.post "frame", {}, {
|
49
|
+
id: name
|
50
|
+
}
|
51
|
+
self
|
52
|
+
end
|
53
|
+
|
54
|
+
def parent_frame!
|
55
|
+
@connection.post "frame/parent", {}, {}
|
56
|
+
self
|
57
|
+
end
|
58
|
+
|
19
59
|
def url! url
|
20
60
|
@connection.post "url", {}, {
|
21
61
|
url: url
|
22
62
|
}
|
63
|
+
self
|
23
64
|
end
|
24
65
|
|
25
66
|
def url
|
@@ -28,29 +69,115 @@ module Webdriver
|
|
28
69
|
|
29
70
|
def back!
|
30
71
|
@connection.post "back"
|
72
|
+
self
|
31
73
|
end
|
32
74
|
|
33
75
|
def forward!
|
34
76
|
@connection.post "forward"
|
77
|
+
self
|
35
78
|
end
|
36
79
|
|
37
80
|
def refresh!
|
38
81
|
@connection.post "refresh"
|
82
|
+
self
|
39
83
|
end
|
40
84
|
|
41
85
|
def title
|
42
86
|
@connection.get "title"
|
43
87
|
end
|
44
88
|
|
89
|
+
def cookies
|
90
|
+
resp = @connection.get "cookie"
|
91
|
+
|
92
|
+
resp.map { |el| Webdriver::Cookie.new el["name"], @connection }
|
93
|
+
end
|
94
|
+
|
95
|
+
def cookies_delete!
|
96
|
+
@connection.delete "cookie"
|
97
|
+
self
|
98
|
+
end
|
99
|
+
|
100
|
+
def cookie name
|
101
|
+
resp = @connection.get File.join("cookie",name)
|
102
|
+
Webdriver::Element.new resp["name"], @connection
|
103
|
+
end
|
104
|
+
|
105
|
+
#TODO: ??
|
106
|
+
# def cookie_add(name, value)
|
107
|
+
# @connection.post "cookie", {}, {
|
108
|
+
# name: name,
|
109
|
+
# args: {
|
110
|
+
# cookie: value,
|
111
|
+
# },
|
112
|
+
# }
|
113
|
+
# end
|
114
|
+
|
115
|
+
# TODO: hangs
|
116
|
+
# def execute_async! script, args=[]
|
117
|
+
# @connection.post "execute/async", {}, {
|
118
|
+
# script: script,
|
119
|
+
# args: args
|
120
|
+
# }
|
121
|
+
# end
|
122
|
+
|
45
123
|
def execute_sync! script, args=[]
|
46
|
-
@connection.post "execute/sync", {}, {
|
124
|
+
resp = @connection.post "execute/sync", {}, {
|
47
125
|
script: script,
|
48
126
|
args: args
|
49
127
|
}
|
128
|
+
|
129
|
+
value = if resp.is_a?(Hash) && resp["ELEMENT"]
|
130
|
+
begin
|
131
|
+
el = Webdriver::Element.new resp["ELEMENT"], @connection
|
132
|
+
el.tag
|
133
|
+
el
|
134
|
+
rescue
|
135
|
+
resp
|
136
|
+
end
|
137
|
+
elsif resp.is_a?(Array)
|
138
|
+
begin
|
139
|
+
resp.map do |r|
|
140
|
+
el = Webdriver::Element.new r["ELEMENT"], @connection
|
141
|
+
el.tag
|
142
|
+
el
|
143
|
+
end
|
144
|
+
rescue
|
145
|
+
resp
|
146
|
+
end
|
147
|
+
else
|
148
|
+
resp
|
149
|
+
end
|
50
150
|
end
|
51
151
|
|
152
|
+
# not implemented in chromedriver
|
153
|
+
# def print!
|
154
|
+
# @connection.post "print"
|
155
|
+
# end
|
156
|
+
|
52
157
|
def screenshot
|
53
158
|
@connection.get "screenshot"
|
54
159
|
end
|
160
|
+
|
161
|
+
# when moving with tab, or clicked
|
162
|
+
def active_element
|
163
|
+
el = @connection.get "element/active"
|
164
|
+
Webdriver::Element.new el["ELEMENT"], @connection
|
165
|
+
end
|
166
|
+
|
167
|
+
def element using, value
|
168
|
+
el = @connection.post "element", {}, {
|
169
|
+
using: using,
|
170
|
+
value: value
|
171
|
+
}
|
172
|
+
Webdriver::Element.new el["ELEMENT"], @connection
|
173
|
+
end
|
174
|
+
|
175
|
+
def elements using, value
|
176
|
+
resp = @connection.post "elements", {}, {
|
177
|
+
using: using,
|
178
|
+
value: value
|
179
|
+
}
|
180
|
+
resp.map { |el| Webdriver::Element.new el["ELEMENT"], @connection }
|
181
|
+
end
|
55
182
|
end
|
56
183
|
end
|
data/lib/webdriver/version.rb
CHANGED
data/lib/webdriver/window.rb
CHANGED
@@ -23,7 +23,7 @@ module Webdriver
|
|
23
23
|
x: x,
|
24
24
|
y: y
|
25
25
|
})
|
26
|
-
|
26
|
+
self
|
27
27
|
end
|
28
28
|
|
29
29
|
def rect
|
@@ -32,10 +32,12 @@ module Webdriver
|
|
32
32
|
|
33
33
|
def fullscreen!
|
34
34
|
@connection.post "fullscreen"
|
35
|
+
self
|
35
36
|
end
|
36
37
|
|
37
38
|
def close!
|
38
39
|
@connection.delete
|
40
|
+
self
|
39
41
|
end
|
40
42
|
end
|
41
43
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webdriver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4
|
4
|
+
version: 0.6.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matti Paksula
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -143,15 +143,20 @@ files:
|
|
143
143
|
- bin/console
|
144
144
|
- bin/setup
|
145
145
|
- e2e/all.rb
|
146
|
+
- e2e/element.rb
|
146
147
|
- e2e/session.rb
|
147
148
|
- e2e/sessions.rb
|
148
149
|
- e2e/status.rb
|
149
150
|
- e2e/window.rb
|
150
151
|
- e2e/windows.rb
|
151
152
|
- examples/args.rb
|
153
|
+
- examples/find_and_click.rb
|
154
|
+
- examples/text_and_html.rb
|
152
155
|
- lib/webdriver.rb
|
153
156
|
- lib/webdriver/client.rb
|
154
157
|
- lib/webdriver/connection.rb
|
158
|
+
- lib/webdriver/cookie.rb
|
159
|
+
- lib/webdriver/element.rb
|
155
160
|
- lib/webdriver/prefix_connection.rb
|
156
161
|
- lib/webdriver/session.rb
|
157
162
|
- lib/webdriver/version.rb
|
@@ -176,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
176
181
|
- !ruby/object:Gem::Version
|
177
182
|
version: '0'
|
178
183
|
requirements: []
|
179
|
-
rubygems_version: 3.0.
|
184
|
+
rubygems_version: 3.0.6
|
180
185
|
signing_key:
|
181
186
|
specification_version: 4
|
182
187
|
summary: webdriver
|