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
17
# File 'lib/webdrone/ctxt.rb', line 13

def initialize(a0)
  @a0 = a0
  @framestack = []
  @parent_stack = []
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



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

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



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

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



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

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

#parent_popObject



107
108
109
# File 'lib/webdrone/ctxt.rb', line 107

def parent_pop
  @a0.conf.parent = @parent_stack.pop
end

#resetObject



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

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

#with_alertObject



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

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



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

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



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

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