Class: DocTestSiteFunctions

Inherits:
Object
  • Object
show all
Extended by:
DocTestSiteServerHelper
Includes:
OnlyofficeDocumentserverTestingFramework::FileReopenHelper, OnlyofficeDocumentserverTestingFramework::PasswordProtectedConversionHelper, PageObject
Defined in:
lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb

Overview

Class to work with test examples

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DocTestSiteServerHelper

fetch_docserverserver_url

Methods included from OnlyofficeDocumentserverTestingFramework::PasswordProtectedConversionHelper

#handle_password_protection, #incorrect_password_shown?, #wait_to_check_password, #xpath_enter_password, #xpath_input_password, #xpath_password_error

Methods included from OnlyofficeDocumentserverTestingFramework::FileReopenHelper

#reopen_after_autosave

Constructor Details

#initialize(instance, edit_modes_indexes = default_modes_indexes) ⇒ DocTestSiteFunctions

Returns a new instance of DocTestSiteFunctions.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb', line 18

def initialize(instance, edit_modes_indexes = default_modes_indexes)
  super(instance.webdriver.driver)
  @instance = instance
  @xpath_begin_view = '//*[@id="beginView"]'
  @xpath_file_loading_step = '//*[@id="step1"]'
  @xpath_conversion_step = '//*[@id="step2"]'
  @xpath_editor_scripts_step = '//*[@id="step3"]'
  @xpath_file_entry = '//*[@class="stored-list"]//table/tbody/tr'
  @xpath_create_doc = '//*[contains(@class, "try-editor document")]|' \
                      '//*[contains(@class, "try-editor word")]'
  @xpath_create_workbook = '//*[contains(@class, "try-editor spreadsheet")]|' \
                           '//*[contains(@class, "try-editor cell")]'
  @xpath_create_presentation = '//*[contains(@class, "try-editor presentation")]|' \
                               '//*[contains(@class, "try-editor slide")]'
  @edit_modes_indexes = edit_modes_indexes
end

Class Method Details

.supported_languages(version = OnlyofficeDocumentserverTestingFramework::DocumentServerVersion.new(8, 3, 0)) ⇒ Array<String>

Returns list of supported languages.

Parameters:

  • version (DocumentServerVersion) (defaults to: OnlyofficeDocumentserverTestingFramework::DocumentServerVersion.new(8, 3, 0))

    of server

Returns:

  • (Array<String>)

    list of supported languages



240
241
242
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
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb', line 240

def self.supported_languages(version = OnlyofficeDocumentserverTestingFramework::DocumentServerVersion.new(8, 3, 0))
  version_class = OnlyofficeDocumentserverTestingFramework::DocumentServerVersion
  version_mappings = [
    [version_class.new(8, 2), 'doc_test_site_languages_after_8_3.list'],
    [version_class.new(8, 2), 'doc_test_site_languages_after_8_2.list'],
    [version_class.new(8, 1), 'doc_test_site_languages_after_8_1.list'],
    [version_class.new(8, 0), 'doc_test_site_languages_after_8_0.list'],
    [version_class.new(7, 4), 'doc_test_site_languages_after_7_4.list'],
    [version_class.new(7, 3), 'doc_test_site_languages_after_7_3.list'],
    [version_class.new(7, 2), 'doc_test_site_languages_after_7_2.list'],
    [version_class.new(7, 1), 'doc_test_site_languages_after_7_1.list'],
    [version_class.new(6, 2), 'doc_test_site_languages_after_6_2.list']
  ]

  file = 'doc_test_site_languages_before_6_2.list'

  version_mappings.each do |ver, file_name|
    if version >= ver
      file = file_name
      break
    end
  end

  File.readlines("#{File.expand_path('..', __dir__)}" \
                 '/test_instance_docs/doc_test_site_functions/' \
                 "languages_list/#{file}")
      .map(&:strip)
end

Instance Method Details

#check_errorNothing

Check for any error in loading process and raise it

Returns:

  • (Nothing)


72
73
74
75
76
77
78
79
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb', line 72

def check_error
  error_message = @instance.selenium.get_text('//*[@class="error-message"]/span', false)

  return if error_message.empty?

  @instance.selenium.webdriver_error('Error while uploading document. ' \
                                     "Error message: #{error_message}")
end

#create_a_file_with_sampleCheckbox

Returns Create a file filled with sample content.

Returns:

  • (Checkbox)

    Create a file filled with sample content



201
202
203
204
205
206
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb', line 201

def create_a_file_with_sample
  checkbox = CheckBox.new(@instance)
  checkbox.xpath = '//*[@id="createSample"]'
  checkbox.count_of_frame = 0
  checkbox
end

#current_document_storage_urlString

Get url of document which opened in editor

Returns:

  • (String)

    url



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

def current_document_storage_url
  page_source = @instance.selenium.page_source
  url_line = page_source.scan(/"?url"?: ".*$/).first
  pretty_url = url_line.delete('"').gsub('url: ', '').chop
  pretty_url.gsub(/&useraddress=.*/, '')
end

#doc_test_site?true, false

Check if current site is DocTestSite

Returns:

  • (true, false)

    result of checking



52
53
54
55
56
57
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb', line 52

def doc_test_site?
  sleep(1) # TODO: remove after update to Chromedriver 80
  result = @instance.selenium.element_present?(@xpath_begin_view)
  OnlyofficeLoggerHelper.log("Current server is a doc_test_site: #{result}")
  result
end

#file_list_opened?True, False

Returns is on file list page now?.

Returns:

  • (True, False)

    is on file list page now?



173
174
175
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb', line 173

def file_list_opened?
  @instance.selenium.element_visible?(@xpath_create_doc)
end

#file_uploaded?Boolean

Check if file uploaded

Returns:

  • (Boolean)


133
134
135
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb', line 133

def file_uploaded?
  @instance.selenium.element_visible?(@xpath_begin_view)
end

#final_loading_step_xpathNothing

Checks if Loading editor scripts step of file upload is present

Returns:

  • (Nothing)


112
113
114
115
116
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb', line 112

def final_loading_step_xpath
  return @xpath_editor_scripts_step if @instance.selenium.element_visible?(@xpath_editor_scripts_step)

  @xpath_conversion_step
end

#go_to_healthcheckNothing

Returns:

  • (Nothing)


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

def go_to_healthcheck
  @instance.webdriver.open("#{@instance.user_data.portal}healthcheck")
end

#healthcheckHealthcheckPage

Returns page of healthcheck.

Returns:



234
235
236
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb', line 234

def healthcheck
  @healthcheck = HealthcheckPage.new(@instance)
end

#open_file_inObject

help-method to #open_file_in_editor and #open_file_in_viewer



138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb', line 138

def open_file_in
  result = 'Unknown'
  if file_uploaded?
    yield
    sleep 5
    @instance.selenium.close_tab
    @instance.selenium.switch_to_main_tab
    result = @instance.management.wait_for_operation_with_round_status_canvas
    sleep 3 # just for sure
  end
  result
end

#open_file_in_editorObject

Click on Edit Button and wait opening Editor Return result of the opening Editor



153
154
155
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb', line 153

def open_file_in_editor
  open_file_in { @instance.selenium.click_on_locator('//*[@id="beginEdit"]') }
end

#open_file_in_viewerObject

Click on View Button and wait opening Viewer Return result of the opening Viewer



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

def open_file_in_viewer
  open_file_in { @instance.selenium.click_on_locator(@xpath_begin_view) }
end

#open_sample_document(format = :document, wait_to_load: true) ⇒ String

Perform creating sample document

Returns:

  • (String)

    result of opening



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb', line 210

def open_sample_document(format = :document, wait_to_load: true)
  case format
  when :document
    @instance.selenium.click_on_locator(@xpath_create_doc)
  when :spreadsheet
    @instance.selenium.click_on_locator(@xpath_create_workbook)
  when :presentation
    @instance.selenium.click_on_locator(@xpath_create_presentation)
  else
    @instance.webdriver.webdriver_error("Unknown file type for open_sample_document(#{format})")
  end
  return unless wait_to_load

  @instance.selenium.close_tab
  @instance.selenium.switch_to_main_tab
  @instance.management.wait_for_operation_with_round_status_canvas
end

#reloadNothing

reload the page

Returns:

  • (Nothing)


45
46
47
48
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb', line 45

def reload
  @instance.webdriver.refresh
  wait_load
end

#save_in_original_formatCheckbox

Returns save in original format checkbox.

Returns:

  • (Checkbox)

    save in original format checkbox



193
194
195
196
197
198
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb', line 193

def save_in_original_format
  checkbox = CheckBox.new(@instance)
  checkbox.xpath = '//*[@id="checkOriginalFormat"]'
  checkbox.count_of_frame = 0
  checkbox
end

#upload_file(file_path) ⇒ Object

Upload file to portal

Parameters:

  • file_path (String)

    like as ‘/mnt/data_share/Files/DOCX/empty.docx’



61
62
63
64
65
66
67
68
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb', line 61

def upload_file(file_path)
  file_path_absolute = file_path.gsub('~', Dir.home)
  @instance.selenium.type_to_locator('//*[@id="fileupload"]', file_path_absolute, false, false, false, true)
  wait_loading_file
  wait_conversion
  wait_loading_scripts
  true
end

#uploaded_file_countInteger

Returns count of uploaded files.

Returns:

  • (Integer)

    count of uploaded files



178
179
180
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb', line 178

def uploaded_file_count
  @instance.selenium.get_element_count(@xpath_file_entry)
end

#uploaded_file_listDocTestFileLIst

Returns get file list.

Returns:

  • (DocTestFileLIst)

    get file list



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

def uploaded_file_list
  file_list = (0...uploaded_file_count).map do |current_file_number|
    DocTestSiteFileListEntry.new(@instance,
                                 "#{@xpath_file_entry}[#{current_file_number + 1}]",
                                 @edit_modes_indexes)
  end
  DocTestFileList.new(file_list)
end

#wait_conversionNothing

Waits until file converts

Returns:

  • (Nothing)


96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb', line 96

def wait_conversion
  100.times do |current_time|
    OnlyofficeLoggerHelper.log("Waiting for file conversion for #{current_time} seconds")
    return true if @instance.selenium.get_attribute(@xpath_conversion_step, 'class').include?('done')

    if @instance.selenium.element_visible?(xpath_input_password)
      handle_password_protection(@instance.management.password)
    end
    sleep 1
    check_error
  end
  @instance.selenium.webdriver_error('File not finished for conversion for 100 seconds')
end

#wait_loadNothing

Waiting for load of page

Returns:

  • (Nothing)


37
38
39
40
41
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb', line 37

def wait_load
  @instance.webdriver.wait_until do
    doc_test_site?
  end
end

#wait_loading_fileNothing

Waits until file converts

Returns:

  • (Nothing)


83
84
85
86
87
88
89
90
91
92
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb', line 83

def wait_loading_file
  100.times do |current_time|
    OnlyofficeLoggerHelper.log("Waiting for file loading for #{current_time} seconds")
    return true if @instance.selenium.get_attribute(@xpath_file_loading_step, 'class').include?('done')

    sleep 1
    check_error
  end
  @instance.selenium.webdriver_error('File not finished for loading scripts for 100 seconds')
end

#wait_loading_scriptsNothing

Waits until scripts loads

Returns:

  • (Nothing)


120
121
122
123
124
125
126
127
128
129
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb', line 120

def wait_loading_scripts
  100.times do |current_time|
    OnlyofficeLoggerHelper.log("Waiting for editors scripts load for #{current_time} seconds")
    return true if @instance.selenium.get_attribute(final_loading_step_xpath, 'class').include?('done')

    sleep 1
    check_error
  end
  @instance.selenium.webdriver_error('File not finished for loading scripts for 100 seconds')
end