Class: Apophis::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/apophis/runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(log = nil) ⇒ Runner

Returns a new instance of Runner.


3
4
5
6
7
8
9
10
11
12
# File 'lib/apophis/runner.rb', line 3

def initialize(log=nil)
  @log = log
  unless log
    @log = Logger.new($stdout)
    @log.formatter = proc do |severity, datetime, progname, msg|
        date_format = datetime.strftime("%Y-%m-%d %H:%M:%S")
        "[#{date_format}] #{severity}: #{msg}\n"
    end
  end
end

Instance Method Details

#cleanup(caps = nil) ⇒ Object

note: Appium::Driver.new(..).start_driver is sucky in that it populates $driver, which #promote_appium_methods rely on. We’ll have no choice but chip-in on this nonsense when we want to do cleanups etc.


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/apophis/runner.rb', line 60

def cleanup(caps=nil)
  @log.info '---> cleaning up...'
  if caps
    port = caps[:runner][:port]
    ar = AppiumRunner.new

    if ar.available?(port)
      @log.info "--> killing appium on port #{port}"
      ar.kill_and_wait(port)
    end
  end

  $driver.driver_quit if $driver
  @log.info '---> done.'
end

#start(caps) ⇒ Object


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/apophis/runner.rb', line 14

def start(caps)
  @log.info "\n#{Apophis::BANNER}\n"
  gm = GenymotionRunner.new
  gm.doctor!

  caps[:runner] ||= {}
  runner = caps[:runner]

  if runner && runner[:genymotion] && gm.devices.empty?
    @log.info '---> no android device found, launching genymotion...'
    gm.launch(runner[:genymotion])
    @log.info '---> devices available:'
    @log.info gm.devices.join("\n")
  end

  port = runner ? runner[:port] : nil
  ar = AppiumRunner.new
  ar.doctor!

  if ar.available?(port)
    @log.info "--> killing appium on port #{port}"
    ar.kill_and_wait(port)
  end

  @log.info '---> launching a new appium...'
  launchinfo = ar.launch_and_wait
  # this is the magic: map the fresh appium port to this current test
  caps[:appium_lib][:port] = launchinfo[:port]
  caps[:runner][:port] = launchinfo[:port]

  @log.info "---> done. wiring caps to appium #{launchinfo}"
  @log.info caps


  @log.info "---> starting driver..."
  Appium::Driver.new(caps).start_driver
  Appium.promote_appium_methods Minitest::Spec
  @log.info "---> done"
end