async-webdriver 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb124e522f9bb2e4f525b56b1f2633a396844c1ec033de92bcb863ba5a202d76
4
- data.tar.gz: d4d70538d5ce3e4c41883be74169c71dcfda403f1e3e24c28cc9ca28d2614509
3
+ metadata.gz: 10af3bfaf7f567c54aaa67fc66865b60e8797756762fb13b3e7f32701d234de5
4
+ data.tar.gz: 91a457bdbc9343cd41eb4c3ba9d63a9f81b571c1f91ffc5c315b81130c0c1d76
5
5
  SHA512:
6
- metadata.gz: 329f215f5e863a1a8b01a12bf5595e5603ebd7754779ec386ba11bff7b7afd537ac5e57d73cf10c08cc760b11d1455b1344e4d34024b2ee6075a6fc8ec75d59a
7
- data.tar.gz: 848396d5cf080dc1e07fcb83368263463aab0dc4151b6fee5b683408d865b14422aad77e46c5132eeeca3ab5e1d436f48f05229c5cd4ff04390e11ed1380a098
6
+ metadata.gz: 226ca38936a96df93d97b55ed583316a7651b528f70ac9a246e3af784959d6df1137e077903b92e94b0613a792a58ed80800f31c9cd7f4dbd518c211ff099adb
7
+ data.tar.gz: b1db3afdbaaaef09eb54c495a4d31bcb80a80dfe88bd25d12f6dfae68b4c3dffadc1d24f934f76dc5c643cb3b4d2e225962a91e34a2bfbd8a7eaef46fe3325fb
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- async-webdriver (0.1.0)
4
+ async-webdriver (0.1.1)
5
5
  async-http
6
6
  selenium-webdriver
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- async (1.12.0)
11
+ async (1.13.1)
12
12
  nio4r (~> 2.3)
13
13
  timers (~> 4.1)
14
14
  async-http (0.37.7)
@@ -3,12 +3,13 @@ require "async/queue"
3
3
  module Async
4
4
  module Webdriver
5
5
  class Client
6
- def initialize(endpoint:)
6
+ def initialize(endpoint:, desired_capabilities: {})
7
7
  @connection = Connection.new endpoint: endpoint
8
+ @desired_capabilities = desired_capabilities
8
9
  end
9
10
 
10
11
  def session
11
- SessionCreator.new connection: @connection
12
+ SessionCreator.new connection: @connection, desired_capabilities: @desired_capabilities
12
13
  end
13
14
 
14
15
  def status
@@ -12,6 +12,20 @@ module Async
12
12
  end
13
13
 
14
14
  def call(method:, path:nil, headers:[], body:nil)
15
+ task = begin
16
+ Async::Task.current.async { async_call(method: method, path: path, headers: headers, body: body) }
17
+ rescue RuntimeError => e
18
+ raise unless e.message == "No async task available!"
19
+
20
+ Async.run { async_call(method: method, path: path, headers: headers, body: body) }
21
+ end
22
+
23
+ task.wait
24
+ end
25
+
26
+ private
27
+
28
+ def async_call(method:, path:, headers:, body:nil)
15
29
  body_array = case body
16
30
  when Hash
17
31
  [body.to_json]
@@ -23,36 +37,32 @@ module Async
23
37
  @url
24
38
  end
25
39
 
26
- task = Async.run do |t|
27
- r = @internet.call method, path_or_url, headers, body_array
40
+ r = @internet.call method.upcase, path_or_url, headers, body_array
28
41
 
29
- body = begin
30
- JSON.parse r.read
31
- rescue JSON::ParserError => ex
32
- p ex
33
- exit 1
34
- end
42
+ body = begin
43
+ JSON.parse r.read
44
+ rescue JSON::ParserError => ex
45
+ p ex
46
+ exit 1
47
+ end
48
+
49
+ @internet.close
35
50
 
36
- @internet.close
37
-
38
- status = body.dig "status"
39
- if status == 0
40
- # POST /session has different response structure than other calls
41
- if method == "post" && path == "session"
42
- {
43
- "id" => body.dig("sessionId"),
44
- "capabilities" => body.dig("value")
45
- }
46
- else # everything else works like this
47
- body.dig "value"
48
- end
49
- else
50
- p body
51
- raise "Error: #{status} - #{body.dig("value", "message")}"
51
+ status = body.dig "status"
52
+ if status == 0
53
+ # POST /session has different response structure than other calls
54
+ if method == "post" && path == "session"
55
+ {
56
+ "id" => body.dig("sessionId"),
57
+ "capabilities" => body.dig("value")
58
+ }
59
+ else # everything else works like this
60
+ body.dig "value"
52
61
  end
62
+ else
63
+ p body
64
+ raise "Error: #{status} - #{body.dig("value", "message")}"
53
65
  end
54
-
55
- task.wait
56
66
  end
57
67
  end
58
68
  end
@@ -3,14 +3,17 @@ require "async/queue"
3
3
  module Async
4
4
  module Webdriver
5
5
  class SessionCreator
6
- def initialize(connection:)
6
+ def initialize(connection:, desired_capabilities: {})
7
7
  @connection = connection
8
+ @desired_capabilities = desired_capabilities
8
9
  end
9
10
 
10
11
  def create!
11
- value = @connection.call method: "post", path: "session", body: {
12
- desiredCapabilities: {}
13
- }
12
+ value = @connection.call(
13
+ method: "post",
14
+ path: "session",
15
+ body: { desiredCapabilities: @desired_capabilities }
16
+ )
14
17
 
15
18
  Session.new json: value, connection: @connection
16
19
  end
@@ -1,5 +1,5 @@
1
1
  module Async
2
2
  module Webdriver
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-webdriver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matti Paksula
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-02 00:00:00.000000000 Z
11
+ date: 2019-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async-http