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, 2, 0)) ⇒ Array<String>

Returns list of supported languages.

Parameters:

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

    of server

Returns:

  • (Array<String>)

    list of supported languages



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb', line 232

def self.supported_languages(version = OnlyofficeDocumentserverTestingFramework::DocumentServerVersion.new(8, 2, 0))
  version_class = OnlyofficeDocumentserverTestingFramework::DocumentServerVersion
  version_mappings = [
    [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



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

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



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

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?



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

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

#file_uploaded?Boolean

Check if file uploaded

Returns:

  • (Boolean)


125
126
127
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb', line 125

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

#go_to_healthcheckNothing

Returns:

  • (Nothing)


221
222
223
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb', line 221

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

#healthcheckHealthcheckPage

Returns page of healthcheck.

Returns:



226
227
228
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb', line 226

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

#open_file_inObject

help-method to #open_file_in_editor and #open_file_in_viewer



130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb', line 130

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



145
146
147
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb', line 145

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



151
152
153
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb', line 151

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



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb', line 202

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



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

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



170
171
172
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb', line 170

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



175
176
177
178
179
180
181
182
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb', line 175

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)


112
113
114
115
116
117
118
119
120
121
# File 'lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb', line 112

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(@xpath_editor_scripts_step, 'class').include?('done')

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