Class: Webdrone::Ctxt

Inherits:
Object
  • Object
show all
Defined in:
lib/webdrone/ctxt.rb,
lib/webdrone/logg.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a0) ⇒ Ctxt

Returns a new instance of Ctxt.



13
14
15
16
# File 'lib/webdrone/ctxt.rb', line 13

def initialize(a0)
  @a0 = a0
  @framestack = []
end

Instance Attribute Details

#a0Object (readonly)

Returns the value of attribute a0.



11
12
13
# File 'lib/webdrone/ctxt.rb', line 11

def a0
  @a0
end

Instance Method Details

#close_tabObject



25
26
27
28
29
30
# File 'lib/webdrone/ctxt.rb', line 25

def close_tab
  @a0.driver.close
  @a0.driver.switch_to.window @a0.driver.window_handles.last
rescue StandardError => error
  Webdrone.report_error(@a0, error)
end

#create_tabObject



18
19
20
21
22
23
# File 'lib/webdrone/ctxt.rb', line 18

def create_tab
  @a0.exec.script "function a0_ctx_create_tab() { var w = window.open(); w.document.open(); w.document.write('A0 CTXT CREATE TAB'); w.document.close(); } a0_ctx_create_tab();"
  @a0.driver.switch_to.window @a0.driver.window_handles.last
rescue StandardError => error
  Webdrone.report_error(@a0, error)
end

#ignore_alertObject



64
65
66
67
68
# File 'lib/webdrone/ctxt.rb', line 64

def ignore_alert
  @a0.exec.script 'alert = function(message){return true;};'
rescue StandardError => error
  Webdrone.report_error(@a0, error)
end

#resetObject



49
50
51
52
53
54
# File 'lib/webdrone/ctxt.rb', line 49

def reset
  @a0.driver.switch_to.default_content
  @framestack = []
rescue StandardError => error
  Webdrone.report_error(@a0, error)
end

#with_alertObject



56
57
58
59
60
61
62
# File 'lib/webdrone/ctxt.rb', line 56

def with_alert
  @a0.wait.for do
    yield @a0.driver.switch_to.alert
  end
rescue StandardError => error
  Webdrone.report_error(@a0, error)
end

#with_conf(new_config) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/webdrone/ctxt.rb', line 70

def with_conf(new_config)
  current_config = {}

  new_config.each do |k, v|
    current_config[k] = @a0.conf.send k
    @a0.conf.send "#{k}=", v
  end

  yield
rescue StandardError => error
  Webdrone.report_error(@a0, error)
ensure
  current_config.each do |k, v|
    @a0.conf.send "#{k}=", v
  end
end

#with_frame(name) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/webdrone/ctxt.rb', line 32

def with_frame(name)
  @framestack << name
  @a0.driver.switch_to.frame name
  if block_given?
    begin
      yield
    ensure
      @framestack.pop
      @a0.driver.switch_to.default_content
      @framestack.each { |frame| @a0.driver.switch_to.frame frame }
    end
  end
  name
rescue StandardError => error
  Webdrone.report_error(@a0, error)
end