Class: OnlyofficeDocumentserverTestingFramework::Management
- Inherits:
-
Object
- Object
- OnlyofficeDocumentserverTestingFramework::Management
- 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
-
#password ⇒ Object
Set file password.
-
#to_update ⇒ Object
Set if should update links.
-
#xpath_iframe ⇒ String
Xpath to single iframe.
-
#xpath_iframe_count ⇒ Integer
Count of iframes to go into.
Instance Method Summary collapse
-
#add_error_handler ⇒ nil
Add js code to handle JS errors.
-
#canvas_editor? ⇒ true, false
Check if opened editor is canvas editor.
-
#document_name(with_extension: true) ⇒ String
Get name of currently opened document.
-
#editor_type ⇒ Symbol
Editor typo of opened document.
-
#frame_loaded? ⇒ Boolean
Check if frame with editor is loaded.
-
#initialize(instance) ⇒ Management
constructor
A new instance of Management.
-
#loading_blocking_modal_dialog? ⇒ True, False
Is there is loading blocking modals dialog.
-
#loading_present? ⇒ Boolean
Check if loader present.
- #main_frame_mobile_element_visible? ⇒ Boolean
-
#status_save?(name = nil) ⇒ Boolean
Check if document has not be saved until now.
-
#viewer? ⇒ true, false
Check if opened document is in viewer.
-
#wait_for_mobile_loading ⇒ True, False
Check if mobile loading is in progress.
-
#wait_for_operation_with_round_status_canvas(timeout_in_seconds = 300, options = {}) ⇒ Object
Wait for operation with round status in canvas editor.
-
#wait_for_round_loading_to_start ⇒ Object
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.
-
#wait_loading_present(timeout = 15) ⇒ Object
Wait until loader is present.
-
#wait_until_frame_loaded ⇒ Void
Wait until iframe have some content.
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
#password ⇒ Object
Set file password
21 22 23 |
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/management.rb', line 21 def password @password end |
#to_update ⇒ Object
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_iframe ⇒ String
Returns 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_count ⇒ Integer
Returns 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_handler ⇒ nil
Add js code to handle JS errors
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
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
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...document_name doc_name.chop! if status_save?(doc_name) doc_name = File.basename(doc_name, '.*') unless with_extension doc_name end |
#editor_type ⇒ Symbol
Returns 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.
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.
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.
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
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
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...document_name name[-1] == '*' end |
#viewer? ⇒ true, false
Check if opened document is in viewer
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..home_tab.present? result = canvas_loaded && !tabs_present OnlyofficeLoggerHelper.log("viewer?: #{result}") result end |
#wait_for_mobile_loading ⇒ True, False
Check if mobile loading is 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
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, = {}) 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.. = 'Unicode (UTF-8)' @instance.spreadsheet_editor.windows.csv_option. = check_2_5_version_error (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 @instance.selenium.webdriver_error('There is not enough access rights for document') end @instance.selenium.webdriver_error('The required file was not found') if 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(.fetch(:additional_wait, 0)) result end |
#wait_for_round_loading_to_start ⇒ Object
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
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_loaded ⇒ Void
Returns 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 |