Class: OnlyofficeDocumentserverTestingFramework::Management

Inherits:
Object
  • Object
show all
Includes:
LoaderHelper, ManagerMessagesChecker, PasswordProtectedHelper, SeleniumWrapper, UpdateLinksHelper
Defined in:
lib/onlyoffice_documentserver_testing_framework/test_instance_docs/management.rb

Overview

Class for management main methods

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from UpdateLinksHelper

#handle_update_links_message, #update_links_message_xpath, #xpath_do_not_update_button, #xpath_update_button

Methods included from PasswordProtectedHelper

#handle_password_protection, #incorrect_password_shown?, #xpath_input_password, #xpath_ok_password

Methods included from LoaderHelper

#check_2_5_version_error, #error_message_alert, #handle_alert_dialog, #handle_error

Methods included from ManagerMessagesChecker

#file_not_found_message?, #permission_denied_message?

Methods included from SeleniumWrapper

#button_disabled?, #button_menu_active?, #button_menu_open?, #button_pressed?, #click_on_button, #click_on_displayed_button, #click_on_of_several_by_display_button, #frame_count_addition, #get_attribute, #line_checked?, #line_enabled?, #menu_disabled?, #remove_element, #select_frame, #selenium_functions, #visible?

Methods included from SeleniumWrapperJsErrors

#console_errors, #error_ignored?, #fail_if_console_error, #ignored_errors

Constructor Details

#initialize(instance) ⇒ Management

Returns a new instance of Management.



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/management.rb', line 25

def initialize(instance)
  @instance = instance
  @xpath_iframe_count = 1
  # Don't mixup iframe with help
  @xpath_iframe = '//iframe[not(contains(@src, "/help/")) and ' \
                  'not(contains(@id, "fileFrame"))]'
  @alert_dialog_xpath = '//div[@role="alertdialog"]'
  @alert_dialog_span_xpath = "#{@alert_dialog_xpath}/div/div/div/span"
  @xpath_window_modal = "//div[contains(@class, 'asc-window modal')]"
  @xpath_anonymous_user_name_input = '//div[@id="id-dlg-username-caption"]'
  @to_update = false
end

Instance Attribute Details

#passwordObject

Set file password



21
22
23
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/management.rb', line 21

def password
  @password
end

#to_updateObject

Set if should update links



23
24
25
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/management.rb', line 23

def to_update
  @to_update
end

#xpath_iframeString

Returns xpath to single iframe.

Returns:

  • (String)

    xpath to single iframe



19
20
21
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/management.rb', line 19

def xpath_iframe
  @xpath_iframe
end

#xpath_iframe_countInteger

Returns count of iframes to go into.

Returns:

  • (Integer)

    count of iframes to go into



17
18
19
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/management.rb', line 17

def xpath_iframe_count
  @xpath_iframe_count
end

Instance Method Details

#add_error_handlernil

Add js code to handle JS errors

Returns:

  • (nil)


182
183
184
185
186
187
188
189
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/management.rb', line 182

def add_error_handler
  js_handler = 'window.jsErrors = [];' \
               'window.onerror = function(errorMessage) ' \
               '{window.jsErrors[window.jsErrors.length] = errorMessage;}'
  @instance.selenium.select_frame @instance.management.xpath_iframe
  @instance.selenium.execute_javascript(js_handler)
  @instance.selenium.select_top_frame
end

#canvas_editor?true, false

Check if opened editor is canvas editor

Returns:

  • (true, false)

    true if canvas, false if not canvas



245
246
247
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/management.rb', line 245

def canvas_editor?
  visible?('//*[@id="id_viewer"]') || visible?('//*[@id="ws-canvas"]')
end

#document_name(with_extension: true) ⇒ String

Get name of currently opened document

Parameters:

  • with_extension (Boolean) (defaults to: true)
    • should extension be included

Returns:

  • (String)


218
219
220
221
222
223
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/management.rb', line 218

def document_name(with_extension: true)
  doc_name = @instance.doc_editor.top_toolbar.top_toolbar.document_name
  doc_name.chop! if status_save?(doc_name)
  doc_name = File.basename(doc_name, '.*') unless with_extension
  doc_name
end

#editor_typeSymbol

Returns editor typo of opened document.

Returns:

  • (Symbol)

    editor typo of opened document



192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/management.rb', line 192

def editor_type
  @instance.selenium.select_top_frame
  url = selenium_functions(:current_url)
  case url
  when /documenteditor/
    :document
  when /spreadsheeteditor/
    :spreadsheet
  when /presentationeditor/
    :presentation
  else
    @instance.selenium.webdriver_error "Unknown editor type for url: #{url}"
  end
end

#frame_loaded?Boolean

Returns check if frame with editor is loaded.

Returns:

  • (Boolean)

    check if frame with editor is loaded



165
166
167
168
169
170
171
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/management.rb', line 165

def frame_loaded?
  @instance.selenium.select_frame(@xpath_iframe, @xpath_iframe_count)
  loaded = @instance.selenium.element_visible?('//*[@id="viewport"]') ||
           @instance.selenium.element_visible?('//*[@id="editor_sdk"]')
  @instance.selenium.select_top_frame
  loaded
end

#loading_blocking_modal_dialog?True, False

Returns is there is loading blocking modals dialog.

Returns:

  • (True, False)

    is there is loading blocking modals dialog



208
209
210
211
212
213
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/management.rb', line 208

def loading_blocking_modal_dialog?
  return false unless @instance.selenium.element_visible?(@xpath_window_modal)
  return false if @instance.selenium.element_visible?(@xpath_anonymous_user_name_input)

  true
end

#loading_present?Boolean

Returns check if loader present.

Returns:

  • (Boolean)

    check if loader present



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/management.rb', line 39

def loading_present?
  if @instance.webdriver.alert_exists?
    raise 'Service Unavailable. There is alert while loading docs: ' \
          "\"#{@instance.webdriver.alert_text}\""
  end

  @instance.selenium.select_frame(@xpath_iframe, @xpath_iframe_count)
  mobile_loader = false
  loader1 = @instance.selenium.element_visible?('//div[contains(@id,"cmdloadmask")]')
  loader2 = @instance.selenium.element_visible?('//*[contains(@class,"loadmask")]')
  loader3 = @instance.selenium.element_visible?('//*[@class="asc-loadmask-body "]')
  loader4 = @instance.selenium.element_present?('//*[@id="loading-text"]')
  loader5 = @instance.selenium.element_visible?('//*[@id="loading-mask"]')
  loader6 = @instance.selenium.element_visible?('//*[@class="modals-mask"]')
  loader7 = @instance.selenium.element_visible?('//*[@class="asc-loadmask"]')
  loader8 = loading_blocking_modal_dialog?
  mobile_loader = wait_for_mobile_loading if main_frame_mobile_element_visible?
  @instance.selenium.select_top_frame
  loading = loader1 || loader2 || loader3 ||
            loader4 || loader5 || loader6 || loader7 ||
            loader8 || mobile_loader
  OnlyofficeLoggerHelper.log("Loading Present: #{loading}")
  loading
end

#main_frame_mobile_element_visible?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/management.rb', line 64

def main_frame_mobile_element_visible?
  @instance.selenium.element_visible?('//*[contains(@class,"framework7-root")]')
end

#status_save?(name = nil) ⇒ Boolean

Check if document has not be saved until now

Parameters:

  • name (String) (defaults to: nil)

    of document

Returns:

  • (Boolean)

    result of that check



228
229
230
231
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/management.rb', line 228

def status_save?(name = nil)
  name ||= @instance.doc_editor.top_toolbar.top_toolbar.document_name
  name[-1] == '*'
end

#viewer?true, false

Check if opened document is in viewer

Returns:

  • (true, false)

    true if viewer, false if editor



235
236
237
238
239
240
241
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/management.rb', line 235

def viewer?
  canvas_loaded = canvas_editor?
  tabs_present = @instance.doc_editor.top_toolbar.home_tab.present?
  result = canvas_loaded && !tabs_present
  OnlyofficeLoggerHelper.log("viewer?: #{result}")
  result
end

#wait_for_mobile_loadingTrue, False

Check if mobile loading is in progress

Returns:

  • (True, False)

    is loading in progress



70
71
72
73
74
75
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/management.rb', line 70

def wait_for_mobile_loading
  @instance.selenium.element_visible?('//*[contains(@class,"modal-preloader")]') ||
    @instance.selenium.element_visible?('//*[contains(@class,"loader-page")]') ||
    @instance.selenium.element_visible?('//div[contains(@class, "dialog-preloader")]') ||
    @instance.selenium.get_element('//*[contains(@class,"iScrollVerticalScrollbar")]').nil?
end

#wait_for_operation_with_round_status_canvas(timeout_in_seconds = 300, options = {}) ⇒ Object

Wait for operation with round status in canvas editor

Parameters:

  • timeout_in_seconds (Integer) (defaults to: 300)

    count of seconds to wait

  • options (Hash) (defaults to: {})

    additional options

Options Hash (options):

  • :additional_wait (Integer)

    additional after file open. 0 by default



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
153
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/management.rb', line 96

def wait_for_operation_with_round_status_canvas(timeout_in_seconds = 300, options = {})
  result = true
  OnlyofficeLoggerHelper.log('Start waiting for Round Status')

  current_wait_time = 0
  wait_until_frame_loaded
  wait_for_round_loading_to_start
  while loading_present?
    sleep(1)
    current_wait_time += 1
    OnlyofficeLoggerHelper.log('Waiting for Round Status for ' \
                               "#{current_wait_time} of " \
                               "#{timeout_in_seconds} timeout")
    @instance.doc_editor.windows.txt_options.txt_options = 'Unicode (UTF-8)'
    @instance.spreadsheet_editor.windows.csv_option.csv_options = options

    check_2_5_version_error
    handle_update_links_message(to_update)
    handle_error

    # Close 'Select Encoding' dialog if present
    if current_wait_time > timeout_in_seconds
      @instance.selenium.select_top_frame
      @instance.selenium.webdriver_error('Timeout for render file')
    end
    handle_alert_dialog
    handle_password_protection(password)
    @instance.selenium.select_top_frame
    if permission_denied_message?
      @instance.selenium.webdriver_error('There is not enough access rights for document')
    end
    @instance.selenium.webdriver_error('The required file was not found') if file_not_found_message?
  end

  @instance.selenium.select_frame(@xpath_iframe, @xpath_iframe_count)
  if @instance.selenium.element_visible?(@alert_dialog_span_xpath)
    alert_text = @instance.selenium.get_text(@alert_dialog_span_xpath).tr("\n", ' ')
    result = "Server Alert: #{alert_text}"
    if result.include?('charts and images will be lost')
      style_left = @instance.selenium.get_style_parameter(@alert_dialog_xpath,
                                                          'left')
                            .gsub!('px', '').to_i
      result = true if style_left.negative?
    end
    @instance.selenium.select_top_frame
    return result
  elsif @instance.selenium.element_visible?(@xpath_error_window)
    result = "Server Error: #{@instance.selenium.get_text(@xpath_error_window_text).tr("\n", ' ')}"
    @instance.selenium.select_top_frame
    @instance.selenium.webdriver_error(result)
  end

  @instance.selenium.execute_javascript('window.onbeforeunload = null') # OFF POPUP WINDOW
  @instance.selenium.select_top_frame
  add_error_handler
  sleep(options.fetch(:additional_wait, 0))
  result
end

#wait_for_round_loading_to_startObject

Since v6.0.0 of DocumentServer round loading mask start to appear not instantly but after some timeout specified in github.com/ONLYOFFICE/web-apps/commit/a7988dc7ec1f1151ef2c204677d1746a65e39132#diff-eee9ef38f1b712adf8bcc94c29de431aR127



159
160
161
162
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/management.rb', line 159

def wait_for_round_loading_to_start
  appear_timeout = 0.5
  sleep(appear_timeout * 4) # quad just in case, double is not enough
end

#wait_loading_present(timeout = 15) ⇒ Object

Wait until loader is present

Parameters:

  • timeout (Integer) (defaults to: 15)

    wait for loading to be present



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/management.rb', line 79

def wait_loading_present(timeout = 15)
  timer = 0
  while timer < timeout && !loading_present?
    sleep 1
    timer += 1
    OnlyofficeLoggerHelper.log('Waiting for start loading of documents. ' \
                               "Waiting for #{timer} seconds of #{timeout}")
  end
  return unless timer == timeout

  @instance.webdriver.webdriver_error("Waiting for start loading failed for #{timeout} seconds")
end

#wait_until_frame_loadedVoid

Returns wait until iframe have some content.

Returns:

  • (Void)

    wait until iframe have some content



174
175
176
177
178
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/management.rb', line 174

def wait_until_frame_loaded
  @instance.webdriver.wait_until do
    frame_loaded?
  end
end