Class: Scoutui::Commands::Highlight

Inherits:
Command
  • Object
show all
Defined in:
lib/scoutui/commands/highlight.rb

Instance Attribute Summary

Attributes inherited from Command

#bm, #cmd, #description, #drv, #enableAssert, #executed, #executed_result, #locator, #rc, #stanza

Instance Method Summary collapse

Methods inherited from Command

#assert?, #disableAssert, #disableAsserts, #enableAsserts, #executedResult, #getLocator, #initialize, #passed?, #result, #run, #setBenchmark, #setLocator, #setResult, #wasExecuted?

Constructor Details

This class inherits a constructor from Scoutui::Commands::Command

Instance Method Details

#_highlight(obj, e = nil) ⇒ Object



7
8
9
10
11
12
13
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
# File 'lib/scoutui/commands/highlight.rb', line 7

def _highlight(obj, e=nil)
  _rc=false

  Scoutui::Logger::LogMgr.instance.command.info __FILE__ + (__LINE__).to_s + " highlight => #{obj}"
  if !obj.nil?

    begin

      if e.is_a?(Hash) && e.has_key?('page') && e['page'].has_key?('style')
        style=e['page']['style']
        obj=Scoutui::Base::QBrowser.highlight(@drv, obj, style)

      elsif e.is_a?(Hash) && e.has_key?(:color)

        # TODO: refactor with q_browser.highlight
        if e[:color].match(/blue/i)
          _style={"color" => 'rgb(0, 0, 255)', "border" => 2}
        elsif e[:color].match(/red/i)
          _style={"color" => 'rgb(255, 0, 0)', "border" => 2}
        elsif e[:color].match(/yellow/i)
          _style={"color" => 'rgb(255, 255, 0)', "border" => 2}
        elsif e[:color].match(/green/i)
          _style={"color" => 'rgb(0, 255, 0)', "border" => 2}
        elsif e[:color].match(/gray/i)
          _style={"color" => 'rgb(128, 128, 128)', "border" => 2}
        end

        obj=Scoutui::Base::QBrowser.highlight(@drv, obj, _style)
      else
        obj=Scoutui::Base::QBrowser.highlight(@drv, obj)
      end

      _rc=true


    rescue => ex
      Scoutui::Logger::LogMgr.instance.warn __FILE__ + (__LINE__).to_s + " Error during processing: #{$!}"
      Scoutui::Logger::LogMgr.instance.warn "Backtrace:\n\t#{ex.backtrace.join("\n\t")}"
    end

  end

  _rc
end

#execute(drv, e = nil) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/scoutui/commands/highlight.rb', line 52

def execute(drv, e=nil)
  rc=true
  _color=nil
  _req = Scoutui::Utils::TestUtils.instance.getReq()

  Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Highlight.execute(#{@cmd}), req:#{_req}"

  @drv=drv if !drv.nil?

  begin

    locators=[]

    if @cmd.match(/highlight\s*\((.*)\)([(\.blue|\.gray|\.green|\.red|\.yellow)]*)/)
#       if @cmd.match(/highlight\s*\((.*)\)/)
      _m = @cmd.match(/highlight\s*\((.*)\)/)
      _m = @cmd.match(/highlight\s*\((.*)\)([(\.blue|\.gray|\.green|\.red|\.yellow)]*)/)
      locators << _m[1].to_s


      if !(_m[2].nil? || _m[2].empty?)
        _color=_m[2].to_s
      end

    elsif e.is_a?(Hash) && e.has_key?('page') && e['page'].has_key?('locators')
      locators = e['page']['locators']
    end

    Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " highlight.locators => #{locators}"

    locators.each do |elt|
      q=nil

      # TODO: _parsed = Scoutui::Base::QBrowser.parseLocator(elt)

      if elt.is_a?(String) && elt=='focused'
        obj=@drv.switch_to.active_element

      elsif elt.is_a?(String) && elt.match((/^\s*([(frame\([^\(]*?\)\.)]*)\.(locator\((.*)\))\s*$/))
        obj=Scoutui::Base::QBrowser.getElement(@drv, elt, Scoutui::Commands::Utils.instance.getFrameSearch(),  Scoutui::Commands::Utils.instance.getTimeout)
      else

        q=Scoutui::Base::Assertions.instance._parseFrameLocator(elt)

        if q.has_key?('frame')
          Scoutui::Commands::Utils.instance.setEnableFrameSearch(q['frame'])
          elt = q['locator']
        end


        _loc = Scoutui::Base::UserVars.instance.normalize(elt)

        obj = Scoutui::Base::QBrowser.findElement(@drv,
                                                  _loc,
                                                  Scoutui::Commands::Utils.instance.getFrameSearch(),
                                                  Scoutui::Commands::Utils.instance.getTimeout)
      end


      if !obj.is_a?(Selenium::WebDriver::Element)
        Scoutui::Logger::LogMgr.instance.warn __FILE__ + (__LINE__).to_s + " highlight : unable to find #{_loc}"
      end

      if _color.nil?
        _rc = _highlight(obj, e)
      else
        _rc = _highlight(obj, { :color => _color })
      end


      Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " highlight(#{e}) : #{_rc}"

      if q && q.has_key?('frame')
        @drv.switch_to.default_content
        Scoutui::Commands::Utils.instance.resetFrameSearch
      end

      rc = rc && _rc

      Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " ||| assert?  => #{assert?.to_s} : _rc:#{_rc}    rc:#{rc}"

      if assert?
        Testmgr::TestReport.instance.getReq(_req).testcase('highlight').add(!obj.nil?, "Verify object #{elt} to highlight exists : #{obj.class.to_s}")
        Testmgr::TestReport.instance.getReq(_req).testcase('highlight').add(_rc, "Verify highlight #{_rc} performed for #{elt}")
      else
        Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " highlight(#{elt} : #{obj.class.to_s}"
      end


      Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " highlight(#{elt.to_s} : #{_rc}"

    end

  rescue => ex
    Scoutui::Logger::LogMgr.instance.warn __FILE__ + (__LINE__).to_s + " Error during processing: #{$!}"
    Scoutui::Logger::LogMgr.instance.warn "Backtrace:\n\t#{ex.backtrace.join("\n\t")}"
  end

  Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " highlight.rc ==> #{rc}"
  setResult(rc)
end