webdriver 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/examples/find_and_click.rb +13 -0
- data/lib/webdriver/connection.rb +12 -7
- data/lib/webdriver/cookie.rb +50 -0
- data/lib/webdriver/element.rb +36 -2
- data/lib/webdriver/prefix_connection.rb +6 -4
- data/lib/webdriver/session.rb +114 -3
- data/lib/webdriver/version.rb +1 -1
- data/lib/webdriver/window.rb +3 -1
- data/lib/webdriver.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80278385c728ce0a053617fee79944dffaee727c10f5ae1df7b86ac0379c8391
|
4
|
+
data.tar.gz: 84e2890d9bbb1f942656b4678caf41fbaaf85ef45ad0ca11973b1b22ca7f74c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e0ee164e79d453e9d636b642bdc957536d214e22dd9e2fa0b6d9958989439a25ecda6733c2c226159ede39b57a13ed59ab4aac6b9e144d9b00d89fbac4d1ca0
|
7
|
+
data.tar.gz: 740e79f4d76ef3183208a20a5802ac67e7f0eee6c1e460611b553892aff38aebdb3f196f9528279a55ccaffbf2b96c811df545b02fa0b7413f5a8dfa3f72691d
|
data/Gemfile.lock
CHANGED
@@ -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!
|
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,15 @@ module Webdriver
|
|
45
47
|
else # everything else works like this
|
46
48
|
value
|
47
49
|
end
|
50
|
+
when 1..nil
|
51
|
+
error_message = value.dig("message")
|
52
|
+
pp [:err, value.dig("message")]
|
53
|
+
raise error_message
|
48
54
|
else
|
49
55
|
if method == :get && path == "/status"
|
50
56
|
value
|
51
57
|
else
|
52
|
-
|
53
|
-
raise "err"
|
58
|
+
raise value.dig("message")
|
54
59
|
end
|
55
60
|
end
|
56
61
|
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
|
data/lib/webdriver/element.rb
CHANGED
@@ -9,6 +9,36 @@ module Webdriver
|
|
9
9
|
@connection = Webdriver::PrefixConnection.new "element/#{@id}", connection
|
10
10
|
end
|
11
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
|
+
end
|
30
|
+
|
31
|
+
def value! value
|
32
|
+
value_string = value.to_s
|
33
|
+
if value_string == ""
|
34
|
+
clear!
|
35
|
+
else
|
36
|
+
@connection.post "value", {}, {
|
37
|
+
value: [value_string]
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
12
42
|
def text
|
13
43
|
@connection.get "text"
|
14
44
|
end
|
@@ -21,6 +51,10 @@ module Webdriver
|
|
21
51
|
@connection.get "name"
|
22
52
|
end
|
23
53
|
|
54
|
+
def css name
|
55
|
+
@connection.get File.join("css", name)
|
56
|
+
end
|
57
|
+
|
24
58
|
def property name
|
25
59
|
@connection.get File.join("property", name)
|
26
60
|
end
|
@@ -33,7 +67,7 @@ module Webdriver
|
|
33
67
|
@connection.post "click"
|
34
68
|
end
|
35
69
|
|
36
|
-
def element
|
70
|
+
def element using, value
|
37
71
|
el = @connection.post "element", {}, {
|
38
72
|
using: using,
|
39
73
|
value: value
|
@@ -41,7 +75,7 @@ module Webdriver
|
|
41
75
|
Webdriver::Element.new el["ELEMENT"], @session_connection
|
42
76
|
end
|
43
77
|
|
44
|
-
def elements
|
78
|
+
def elements using, value
|
45
79
|
resp = @connection.post "elements", {}, {
|
46
80
|
using: using,
|
47
81
|
value: value
|
@@ -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
|
+
session
|
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,32 +69,102 @@ 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
|
55
160
|
|
56
|
-
|
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
|
57
168
|
el = @connection.post "element", {}, {
|
58
169
|
using: using,
|
59
170
|
value: value
|
@@ -61,7 +172,7 @@ module Webdriver
|
|
61
172
|
Webdriver::Element.new el["ELEMENT"], @connection
|
62
173
|
end
|
63
174
|
|
64
|
-
def elements
|
175
|
+
def elements using, value
|
65
176
|
resp = @connection.post "elements", {}, {
|
66
177
|
using: using,
|
67
178
|
value: value
|
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
|
data/lib/webdriver.rb
CHANGED
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
|
+
version: 0.6.0
|
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-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -150,10 +150,12 @@ files:
|
|
150
150
|
- e2e/window.rb
|
151
151
|
- e2e/windows.rb
|
152
152
|
- examples/args.rb
|
153
|
+
- examples/find_and_click.rb
|
153
154
|
- examples/text_and_html.rb
|
154
155
|
- lib/webdriver.rb
|
155
156
|
- lib/webdriver/client.rb
|
156
157
|
- lib/webdriver/connection.rb
|
158
|
+
- lib/webdriver/cookie.rb
|
157
159
|
- lib/webdriver/element.rb
|
158
160
|
- lib/webdriver/prefix_connection.rb
|
159
161
|
- lib/webdriver/session.rb
|