Attention une mise à jour du serveur va être effectuée le lundi 17 mai entre 13h et 13h30. Cette mise à jour va générer une interruption du service de quelques minutes.

vidjil_browser.rb 9.63 KB
Newer Older
1 2 3 4 5
# coding: utf-8
require 'watir-webdriver'

class VidjilBrowser < Watir::Browser

6 7 8 9 10 11 12
  def initialize
    if ENV['WATIR_BROWSER_PATH']
      print "Using custom browser location " + ENV['WATIR_BROWSER_PATH'] + "\n"
      Selenium::WebDriver::Firefox.path = ENV['WATIR_BROWSER_PATH']
    end
    # :chrome or :safari
    super :firefox
13 14

    print "Running "+driver.capabilities.browser_name+" "+driver.capabilities.version+"\n"
15 16
  end

17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
  # Return the text field that allows to edit a clone name
  def clone_name_editor
    return text_field(:id => 'new_name')
  end

  # Buttons that allows to save a name change
  def clone_name_saver
    return a(:id => 'btnSave')
  end

  # Return the clone in the list
  def clone_in_list(id, extra={})
    return list.li(extra.merge(:id => id))
  end

  # Return the info on the clone in the list (one item of a list)
33
  # A hash with keys cluster, system, name, info, star, axis and size defined with
34 35 36
  # the corresponding elements in the list.
  def clone_info(id, extra={})
    clone = clone_in_list(id, extra)
Mikaël Salson's avatar
Mikaël Salson committed
37
    return {cluster: clone.element(:class => 'clusterBox'), system: clone.element(:class => "systemBox"),
38
            name: clone.element(:class => 'nameBox'), info: clone.element(:class => 'infoBox'),
39 40
            star: clone.element(:class => 'starBox'), size: clone.element(:class => 'sizeBox'),
            axis: clone.element(:class => 'axisBox')}
41
  end
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56

  # Return the clone cluster for clone ID
  def clone_cluster(id, extra = {})
    return clone_in_list(id, extra).element(:id => 'cluster'+id)
  end

  # Return the n-th clone in a cluster for clone ID
  # n: a str (starting at 1)
  def clone_in_cluster(id, n, extra = {})
    cluster = clone_cluster(id, extra).element(:id => '_'+n)
    return {object: cluster,
            name: cluster.element(:class => 'nameBox'), size: cluster.element(:class => 'sizeBox'),
            info: cluster.element(:class => 'infoBox'), delete: cluster.element(:class => 'delBox')}
  end

57
  # Return a hash with information on the sequence in the segmenter
58
  # A hash with keys name, star, axis and size defined with
59 60 61 62
  # the corresponding elements in the segmenter.
  def clone_info_segmenter(id, extra={})
    item = clone_in_segmenter(id, extra)
    return {name: item.element(:class => 'nameBox'), star: item.element(:class => 'starBox'),
63
            size: item.element(:class => 'sizeBox'), identity: item.element(:class => 'identityBox'),
64
            info: item.elements(:class => 'infoBox'), axis: item.element(:class => 'axisBox')
65
    }
66 67 68 69
  end


  # Return the clone on the scatterplot
70
  # Beware the id must be a string
71
  def clone_in_scatterplot(id, extra={})
72 73 74 75 76 77 78 79
    circle = element(extra.merge(:id => "circle"+id))
    if circle.exists? and not circle.visible?
      bar = element(extra.merge(:id => "bar"+id))
      if bar.exists? and bar.visible?
        return bar
      end
    end
    return circle
80 81 82
  end

  # Return the clone in the graph
83
  # Beware the id must be a string
84 85 86 87 88
  def clone_in_graph(id, extra={})
    return element(extra.merge(:id => "polyline"+id))
  end

  # Return the item of clone id in segmenter (may not exist…)
89
  # Beware the id must be a string
90 91 92 93
  def clone_in_segmenter(id, extra={})
    return element(extra.merge(:id => 'seq'+id))
  end

94 95 96 97 98
  # Change the coloration
  def color_by(dimension)
    menu_color.select_list.select dimension
  end

99 100 101 102 103 104 105
  # Return an associative array (keys name, and value) for the following external data
  def external_data(id)
    item = element(:id => 'data_'+id)
    return {name: item.element(:class => 'data_name').text,
            value: item.element(:class => 'data_value').text.to_f}
  end

106 107 108 109 110
  # Return the div of the graph component
  def graph(extra = {})
    return element(extra.merge(:class => 'graph', :id => 'visu2'))
  end

111 112 113 114 115
  # Return the x legend of the graph (id is a string from 0 to the number of samples - 1)
  def graph_x_legend(id, extra = {})
    return graph.element(extra.merge(:id => 'time'+id))
  end

116 117 118 119 120
  # Information on the currently displayed point
  def info_point
    return element(:id => 'info_point')
  end

121 122 123 124 125 126 127 128
  def info_segmented
    return element(:id => 'info_segmented').span(:index => 1)
  end

  def info_selected_locus
    return element(:id => 'info_selected_locus').span(:index => 1)
  end

129 130
  # Return the div containing the information (status bar)
  def infoline
131
    return div(:id => segmenter_id).div(:class => 'focus')
132 133
  end

134 135 136 137 138
  # Return the span of the locus
  def locus_topleft(locus)
       return span(:class => 'systemBoxNameMenu', :class => locus)
  end

139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
  def menu_patient
    return div(:id => 'db_menu')
  end

  def menu_import_export
    return div(:id => 'demo_file_menu')
  end

  def menu_cluster
    return div(:id => 'cluster_menu')
  end

  def menu_analysis
    return div(:id => 'analysis_menu')
  end

  def menu_color
    return div(:id => 'color_menu')
  end

  def menu_filter
    return div(:id => 'filter_menu')
  end
  
  def menu_settings
    return div(:id => 'settings_menu')
  end
166

167
  def menu_item_export(id)
168 169
    menu = menu_import_export
    menu.click
170 171 172 173 174
    return menu.a(:id => id)
  end

  def menu_item_export_fasta
    return menu_item_export('export_fasta')
175 176
  end

177 178 179 180 181 182 183 184
  def merge
    return element(:id => 'merge')
  end

  def select_tag(id, extra={})
    return element(extra.merge(:id => 'fastTag'+id))
  end

185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
  # Return the div of the scatterplot
  def scatterplot
    return element(:id => scatterplot_id)
  end

  def scatterplot_menu
    return scatterplot.element(:class => 'sp_menu')
  end

  # Select a preset in the scatterplot menu
  # (String or Regex)
  def scatterplot_select_preset(axis)
    scatterplot_menu.hover
    preset_selector.select axis
  end

201 202
  # Return the element corresponding to the x axis of the scatterplot
  def scatterplot_x
203
    return scatterplot_axis('x')
204 205 206 207 208 209 210
  end

  # Return the element corresponding to the legend of the x axis of the scatterplot
  def scatterplot_x_legend(index)
    return scatterplot_legend('x', index)
  end

211 212 213 214 215
  # Return the x axis label of the scatterplot
  def scatterplot_x_label
    return scatterplot_labels[0]
  end

216 217
  # Return the element corresponding to the x axis of the scatterplot
  def scatterplot_y
218
    return scatterplot_axis('y')
219 220 221 222 223 224 225
  end

  # Return the element corresponding to the legend of the y axis of the scatterplot
  def scatterplot_y_legend(index)
    return scatterplot_legend('y', index)
  end

226 227 228 229 230
  # Return the y axis label of the scatterplot
  def scatterplot_y_label
    return scatterplot_labels[1]
  end

231 232 233 234 235 236 237 238 239 240 241 242
  def segmenter_checkbox_aa
    return element(:id => 'segmenter_aa')
  end

  def segmenter_checkbox_imgt_cdr3
    return element(:id => 'imgt_cdr3_input_check')
  end

  def segmenter_checkbox_imgt_vdj
    return element(:id => 'imgt_vdj_input_check')
  end

243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
  # Return the span containing elements of the sequence in the scatterplot
  def sequence(id)
    return element(:id => 'm'+id)
  end

  # Return the V sequence of the clone id
  def sequence_V(id)
    return sequence(id).element(:class => 'V')
  end

  # Return the N1 sequence of the clone id
  def sequence_N1(id)
    return sequence(id).element(:class => 'N', :index => 0)
  end

  # Return the N2 sequence of the clone id
  def sequence_N2(id)
    return sequence(id).element(:class => 'N', :index => 1)
  end

  # Return the D sequence of the clone id
  def sequence_D(id)
    return sequence(id).element(:class => 'D')
  end

  # Return the J sequence of the clone id
  def sequence_J(id)
    return sequence(id).element(:class => 'J')
  end

  # Return the div containing stats information on selected clone(s)
  def statsline
275
    div(:id => segmenter_id).div(:class => 'stats')
276 277
  end

278 279
  # Return an item from a tag selector (the menu to select the tag
  # for a clone) split in a hash.
280 281 282 283 284 285 286 287
  # The hash contains the following keys:
  def tag_item(id)
    ts = tag_selector
    return {color: ts.span(:class => 'tagColor'+id),
            name: ts.span(:class => 'tagName'+id),
            edit: ts.li(:index => id.to_i).span(:class => 'edit_button')}
  end
  
288 289 290 291 292
  # Return the select containing the preset selector in the graph
  def preset_selector
    return select_list(:class => 'axis_select_preset_select')
  end

293 294
  # Return the div containing the tag selector
  def tag_selector
Marc Duez's avatar
Marc Duez committed
295
    return div(:class => 'tagSelector')
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
  end

  # Return the close button for tag selector
  def tag_selector_close
    return tag_selector.span(:class => 'closeButton')
  end

  # Return the field for editing tag name in the tag selector
  def tag_selector_edit_name
    return tag_selector.text_field(:id => 'new_tag_name')
  end

  # Return the field for editing tag name in the tag selector
  def tag_selector_edit_normalisation
    return tag_selector.text_field(:id => 'normalized_size')
  end

  # Return the button that validates the changes in the tag selector
  def tag_selector_name_validator
    return tag_selector.a(:id => 'btnSaveTag')
  end

  # Return the button that validates the changes in the tag selector
  def tag_selector_normalisation_validator
    return tag_selector.button(:text => 'ok')
  end

323
  # Unselect everything, both on clones, and move away from menus (as if we click on the back)
324
  def unselect
325
    $b.execute_script('m.unselectAll()')
326
    $b.execute_script('showSelector("x")')
327 328 329 330 331 332 333
  end
  
  # Return the div of the list of clones
  def list
    return div(:id => 'list_clones')
  end
  
334 335 336 337 338 339 340 341 342 343
  protected

  def scatterplot_id
    return 'visu_axis'
  end

  def segmenter_id
    return 'bot-container'
  end

344
  def scatterplot_axis(axis)
345
    return element(:id => scatterplot_id+'_'+axis+'_container')
346 347
  end

348 349 350 351
  def scatterplot_labels
    return element(:id => scatterplot_id+'_axis_container').elements(:class => 'sp_legend2')
  end

352
  def scatterplot_legend(axis, index)
353
    return scatterplot_axis(axis).element(:class => 'sp_legend', :index => index)
354 355 356 357
  end


end