apophis 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: 2c083648aea56d926aba4f20f65b54fa63852853
4
- data.tar.gz: 68ff4acc72d7de6b3fe84baa0f4f668eb79479f9
3
+ metadata.gz: 5328908f29d5a0aee3ae2c839f319d8b624c31d4
4
+ data.tar.gz: 02b4adda6130ae5e245851b94d4857094f32ff00
5
5
  SHA512:
6
- metadata.gz: 6f1930ff4b7a77b4c555a54e91329ff53cf7006a2c2fedcbed60c7ab6ba51caf4ddc4abb0013247a68596898ea7515227ed88259caa06e3c7a0ac074c556247f
7
- data.tar.gz: eded73ec96c9a0524dd15f6dc97f190cb8a22630328596df73a42124613a11a8b5b223e749a7a6d6a0b56b99d743275b829b5d9d8f5907040d0be371651de327
6
+ metadata.gz: be62a539b8bf2d0ce6f9022ba51324c0d5ca8e2dad47877172a0709e31774c9eb39735e84a14e7ed700df06c8a333fe1f00a8aec9da004761760b9fde85b4e0e
7
+ data.tar.gz: 180616985cebf8e883cbace2b936ea8848efb0b8f1e5930bbea7d3ff6aa3f36805b76b623d3e542a9b6e387cca51aabc3423ea959f66e74947ec35a2eba9e0e5
@@ -15,6 +15,7 @@ class AppiumRunner
15
15
  end
16
16
 
17
17
  def available?(port)
18
+ return false unless port
18
19
  !!find(port)
19
20
  end
20
21
 
@@ -35,9 +36,11 @@ class AppiumRunner
35
36
  appiums.find{|app| app[:url] =~ /:#{port}/}
36
37
  end
37
38
 
38
- def launch_and_wait(port=4500, timeout=20)
39
- port = find_available_port(port)
40
- Process.spawn("appium -p #{port} -bp #{port+1} > /dev/null 2>&1")
39
+ def launch_and_wait(port=nil, timeout=20)
40
+ port = port || find_available_port(4500)
41
+
42
+ #we'll use the env variable later to locate this process (`ps -p <PID> -wwwE`)
43
+ Process.spawn("APOPHIS_TAG=#{port} appium -p #{port} -bp #{port+1} > /dev/null 2>&1")
41
44
  DottyTimeout.timeout(timeout){ available?(port) }
42
45
 
43
46
  { port: port }
@@ -49,7 +52,7 @@ class AppiumRunner
49
52
  res = JSON.parse(open("#{ candidate }/status").read)
50
53
  !!res["value"]
51
54
  end
52
- rescue
55
+ rescue Exception => _
53
56
  false
54
57
  end
55
58
  end
@@ -16,33 +16,33 @@ module Apophis
16
16
  gm = GenymotionRunner.new
17
17
  gm.doctor!
18
18
 
19
- if caps[:runner] && caps[:runner][:genymotion] && gm.devices.empty?
19
+ caps[:runner] ||= {}
20
+ runner = caps[:runner]
21
+
22
+ if runner && runner[:genymotion] && gm.devices.empty?
20
23
  @log.info '---> no android device found, launching genymotion...'
21
- gm.launch(caps[:runner][:genymotion])
24
+ gm.launch(runner[:genymotion])
22
25
  @log.info '---> devices available:'
23
26
  @log.info gm.devices.join("\n")
24
27
  end
25
28
 
29
+ port = runner ? runner[:port] : nil
26
30
  ar = AppiumRunner.new
27
31
  ar.doctor!
28
32
 
29
- appiums = ar.appiums
30
- @log.info "appiums: #{appiums}"
31
- if appiums.size > 0
32
- @log.info '---> being a douch and killing all running appiums.'
33
- @log.info '---> improve me later to map caps->device->device uuid->appium->appium session.'
34
- appiums.each do |app|
35
- @log.info "---> killing appium #{ app }"
36
- ar.kill_and_wait(app[:port])
37
- end
33
+ if ar.available?(port)
34
+ @log.info "--> killing appium on port #{port}"
35
+ ar.kill_and_wait(port)
38
36
  end
39
37
 
40
- unless ar.any?
41
- @log.info '---> no appium found. launching...'
42
- launchinfo = ar.launch_and_wait
43
- caps[:appium_lib][:port] = launchinfo[:port]
44
- @log.info "---> done. wiring caps to appium #{launchinfo}"
45
- end
38
+ @log.info '---> launching a new appium...'
39
+ launchinfo = ar.launch_and_wait
40
+ # this is the magic: map the fresh appium port to this current test
41
+ caps[:appium_lib][:port] = launchinfo[:port]
42
+ caps[:runner][:port] = launchinfo[:port]
43
+
44
+ @log.info "---> done. wiring caps to appium #{launchinfo}"
45
+ @log.info caps
46
46
 
47
47
 
48
48
  @log.info "---> starting driver..."
@@ -57,8 +57,18 @@ module Apophis
57
57
  # #promote_appium_methods rely on. We'll have no
58
58
  # choice but chip-in on this nonsense when we
59
59
  # want to do cleanups etc.
60
- def cleanup
60
+ def cleanup(caps=nil)
61
61
  @log.info '---> cleaning up...'
62
+ if caps
63
+ port = caps[:runner][:port]
64
+ ar = AppiumRunner.new
65
+
66
+ if ar.available?(port)
67
+ @log.info "--> killing appium on port #{port}"
68
+ ar.kill_and_wait(port)
69
+ end
70
+ end
71
+
62
72
  $driver.driver_quit if $driver
63
73
  @log.info '---> done.'
64
74
  end
@@ -1,3 +1,3 @@
1
1
  module Apophis
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apophis
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
  - Dotan Nahum
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-17 00:00:00.000000000 Z
11
+ date: 2016-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appium_lib