wda_client 0.1.0 → 0.2.0

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
  SHA1:
3
- metadata.gz: d4abac08512d83a44f16c7934a55524eec72f11c
4
- data.tar.gz: 8c047fd2801d429f47d153fc4dca8b4c407ffd9a
3
+ metadata.gz: 1bb55bd2a43a1c14108e3d9ef93118456d7c2963
4
+ data.tar.gz: 690b308c23c327077f2c95ddcf30eb2118567b0b
5
5
  SHA512:
6
- metadata.gz: 8bc2ae1693e6421236edbcbefbecc82e3ee0fc69e95df77dbec6b2eb14d2f857420a3772ea97ae878a494645cbd4dc1a515c13308534570e3a72061dc3409bb9
7
- data.tar.gz: 3013553a9cd9b2c74d7c1355705fdde3e2cdb087c26899693fa970ec3c4d2b19e7ec03cf93fd199c43828092732c61bbdfc872c9756c7c4fe4851fc061cc5b0a
6
+ metadata.gz: 5c04b017723c7fb5d5f3a9e0487fff5ee0b1b7a395902233da268a94f5fa58b4a3cb1f9944b3f0ef6c61eeb3ddac1a29894cb9b15b6b4738b0b93b8cb529e5b8
7
+ data.tar.gz: 418597e40bdaa173d692a6aaff3fcb014a9672223164d6cdd5fb7c2171017d061c645d107a81292fab144fd22524df1071b8d1a396bf3a6d23796229d5e19833
@@ -0,0 +1,14 @@
1
+ # v0.1.1
2
+ - Add support API
3
+ - get session
4
+ - close session
5
+
6
+ # v0.1.0
7
+ Helper client to handle WebDriverAgent via ruby.
8
+
9
+ - Support
10
+ - get status
11
+ - get source
12
+ - go to homescreen
13
+ - take screenshot
14
+ - install app and get session id
data/README.md CHANGED
@@ -33,9 +33,10 @@ Or install it yourself as:
33
33
  $ pry
34
34
  > require 'wda_client'
35
35
  > client = WdaClient.new desired_capabilities: "{\"desiredCapabilities\":{\"bundleId\": \"com.my.app\"}}"
36
- > client.get_status # get https://github.com/facebook/WebDriverAgent/wiki/Queries#checking-service-status
36
+ > client.get_status # https://github.com/facebook/WebDriverAgent/wiki/Queries#checking-service-status
37
37
  > client.take_screenshot # https://github.com/facebook/WebDriverAgent/wiki/Queries#get-a-screenshot
38
- > client.get_source # https://github.com/facebook/WebDriverAgent/wiki/Queries#source-aka-tree
38
+ > client.get_source # https://github.com/facebook/WebDriverAgent/wiki/Queries#source-aka-tree
39
+ > client.close # close session
39
40
  ```
40
41
 
41
42
  ## Advanced
@@ -55,7 +56,13 @@ client = WdaClient.new desired_capabilities: "{\"desiredCapabilities\":{\"bundle
55
56
 
56
57
  ## Current Status
57
58
 
58
- - Get Status / Get source / go to homescreen / Take Screenshot / install app and get session id
59
+ - Get Status
60
+ - Get source
61
+ - go to homescreen
62
+ - Take Screenshot
63
+ - install app and get session id
64
+ - get current session id
65
+ - close current session
59
66
 
60
67
  ## Contributing
61
68
 
@@ -15,28 +15,27 @@ class WdaClient
15
15
  include ::WdaClient::Source
16
16
  include ::WdaClient::Homescreen
17
17
 
18
- attr_accessor :session_id, :capabilities, :desired_capabilities
18
+ attr_accessor :session_id, :capabilities, :desired_capabilities, :status
19
19
  attr_reader :base_url
20
20
 
21
21
  BASE_URL = 'http://localhost:8100'
22
22
 
23
23
  def initialize(desired_capabilities:, base_url: BASE_URL)
24
24
  @desired_capabilities = parse(desired_capabilities)
25
- @base_url = base_url
25
+ @base_url = URI.parse(base_url)
26
26
  @capabilities = nil
27
27
  @session_id = nil
28
- end
29
-
30
- def generate_uri(url_path:)
31
- URI.parse(@base_url + url_path)
28
+ @status = 0
32
29
  end
33
30
 
34
31
  def generate_base_req(method:, url_path:)
35
32
  req = case method
36
- when 'get'
33
+ when :get
37
34
  Net::HTTP::Get.new(url_path)
38
- when 'post'
35
+ when :post
39
36
  Net::HTTP::Post.new(url_path)
37
+ when :delete
38
+ Net::HTTP::Delete.new(url_path)
40
39
  else
41
40
  # no method
42
41
  end
@@ -3,11 +3,10 @@ require 'json'
3
3
  class WdaClient
4
4
  module Homescreen
5
5
  def homescreen
6
- uri = generate_uri(url_path: '/homescreen')
7
- req = generate_base_req(method: 'post', url_path: '/homescreen')
6
+ req = generate_base_req(method: :post, url_path: '/homescreen')
8
7
  req.body = ""
9
8
 
10
- res = Net::HTTP.start(uri.host, uri.port) { |http| http.request(req) }
9
+ res = Net::HTTP.start(@base_url.host, @base_url.port) { |http| http.request(req) }
11
10
 
12
11
  JSON.parse(res.body)
13
12
  end
@@ -4,10 +4,9 @@ require 'base64'
4
4
  class WdaClient
5
5
  module Screenshot
6
6
  def take_screenshot(to_file: './snapshot.png')
7
- uri = generate_uri(url_path: '/screenshot')
8
- req = generate_base_req(method: 'get', url_path: '/screenshot')
7
+ req = generate_base_req(method: :get, url_path: '/screenshot')
9
8
 
10
- res = Net::HTTP.start(uri.host, uri.port) { |http| http.request(req) }
9
+ res = Net::HTTP.start(@base_url.host, @base_url.port) { |http| http.request(req) }
11
10
 
12
11
  parsed_result = JSON.parse res.body
13
12
 
@@ -3,17 +3,53 @@ require 'json'
3
3
  class WdaClient
4
4
  module Sessions
5
5
  def install
6
- uri = generate_uri(url_path: '/session')
7
- req = generate_base_req(method: 'post', url_path: '/session')
8
- req.body = @desired_capabilities
6
+ req = generate_base_req(method: :post, url_path: '/session')
7
+ req.body = @desired_capabilities.to_json
9
8
 
10
- res = Net::HTTP.start(uri.host, uri.port) { |http| http.request(req) }
9
+ res = Net::HTTP.start(@base_url.host, @base_url.port) { |http| http.request(req) }
11
10
 
12
11
  result = JSON.parse(res.body)
13
- @session_id = result['sessionId'] || result['value']['sessionId']
12
+ @session_id = result['sessionId']
14
13
  @capabilities = result['value']['capabilities']
14
+ @status = result['status']
15
15
 
16
16
  result
17
17
  end
18
+
19
+ def close
20
+ session_id = parse_session_id @session_id
21
+ req = generate_base_req(method: :delete, url_path: "/session/#{session_id}")
22
+
23
+ res = Net::HTTP.start(@base_url.host, @base_url.port) { |http| http.request(req) }
24
+
25
+ result = JSON.parse(res.body)
26
+ @session_id = result['sessionId']
27
+ @status = result['status']
28
+
29
+ result
30
+ end
31
+
32
+ def get_current_session
33
+ session_id = parse_session_id @session_id
34
+ req = generate_base_req(method: :get, url_path: "/session/#{session_id}")
35
+
36
+ res = Net::HTTP.start(@base_url.host, @base_url.port) { |http| http.request(req) }
37
+
38
+ result = JSON.parse(res.body)
39
+ @session_id = result['sessionId']
40
+ @status = result['status']
41
+
42
+ result
43
+ end
44
+
45
+ private
46
+
47
+ def parse_session_id(session_id)
48
+ if @session_id.nil?
49
+ ""
50
+ else
51
+ @session_id
52
+ end
53
+ end
18
54
  end
19
55
  end
@@ -3,10 +3,9 @@ require 'json'
3
3
  class WdaClient
4
4
  module Source
5
5
  def get_source
6
- uri = generate_uri(url_path: '/source')
7
- req = generate_base_req(method: 'get', url_path: '/source')
6
+ req = generate_base_req(method: :get, url_path: '/source')
8
7
 
9
- res = Net::HTTP.start(uri.host, uri.port) { |http| http.request(req) }
8
+ res = Net::HTTP.start(@base_url.host, @base_url.port) { |http| http.request(req) }
10
9
 
11
10
  JSON.parse res.body
12
11
  end
@@ -3,12 +3,14 @@ require 'json'
3
3
  class WdaClient
4
4
  module Status
5
5
  def get_status
6
- uri = generate_uri(url_path: '/status')
7
- req = generate_base_req(method: 'get', url_path: '/status')
6
+ req = generate_base_req(method: :get, url_path: '/status')
8
7
 
9
- res = Net::HTTP.start(uri.host, uri.port) { |http| http.request(req) }
8
+ res = Net::HTTP.start(@base_url.host, @base_url.port) { |http| http.request(req) }
10
9
 
11
- JSON.parse res.body
10
+ result = JSON.parse res.body
11
+ @status = result['status']
12
+
13
+ result
12
14
  end
13
15
  end
14
16
  end
@@ -1,3 +1,3 @@
1
1
  class WdaClient
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wda_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuaki MATSUO
@@ -75,6 +75,7 @@ extra_rdoc_files: []
75
75
  files:
76
76
  - ".gitignore"
77
77
  - ".travis.yml"
78
+ - CHANGELOG.md
78
79
  - CODE_OF_CONDUCT.md
79
80
  - Gemfile
80
81
  - LICENSE.txt