onlyoffice_documentserver_testing_framework 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. checksums.yaml +7 -0
  2. data/lib/onlyoffice_documentserver_testing_framework.rb +5 -0
  3. data/lib/onlyoffice_documentserver_testing_framework/name.rb +10 -0
  4. data/lib/onlyoffice_documentserver_testing_framework/selenium_wrapper.rb +141 -0
  5. data/lib/onlyoffice_documentserver_testing_framework/selenium_wrapper/selenium_wrapper_exceptions.rb +7 -0
  6. data/lib/onlyoffice_documentserver_testing_framework/selenium_wrapper/selenium_wrapper_js_errors.rb +46 -0
  7. data/lib/onlyoffice_documentserver_testing_framework/selenium_wrapper/selenium_wrapper_js_errors/ignored_errors.list +28 -0
  8. data/lib/onlyoffice_documentserver_testing_framework/test_instance_docs.rb +64 -0
  9. data/lib/onlyoffice_documentserver_testing_framework/test_instance_docs/common_editor/editor_windows.rb +7 -0
  10. data/lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_editor.rb +23 -0
  11. data/lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_editor/doc_editor_top_toolbar.rb +17 -0
  12. data/lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_editor/doc_editor_top_toolbar/top_toolbar_users.rb +32 -0
  13. data/lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_editor/doc_editor_windows.rb +18 -0
  14. data/lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_editor/doc_editor_windows/txt_options.rb +116 -0
  15. data/lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_service_welcome.rb +35 -0
  16. data/lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions.rb +235 -0
  17. data/lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions/doc_test_file_list.rb +34 -0
  18. data/lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions/doc_test_file_list/doc_test_site_file_list_entry.rb +101 -0
  19. data/lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions/doc_test_site_server_helper.rb +25 -0
  20. data/lib/onlyoffice_documentserver_testing_framework/test_instance_docs/doc_test_site_functions/healthcheck_page.rb +15 -0
  21. data/lib/onlyoffice_documentserver_testing_framework/test_instance_docs/management.rb +206 -0
  22. data/lib/onlyoffice_documentserver_testing_framework/test_instance_docs/management/loader_helper.rb +50 -0
  23. data/lib/onlyoffice_documentserver_testing_framework/test_instance_docs/presentation_editor.rb +7 -0
  24. data/lib/onlyoffice_documentserver_testing_framework/test_instance_docs/spreadsheet_editor.rb +13 -0
  25. data/lib/onlyoffice_documentserver_testing_framework/test_instance_docs/spreadsheet_editor/spreadsheet_windows.rb +18 -0
  26. data/lib/onlyoffice_documentserver_testing_framework/test_instance_docs/spreadsheet_editor/spreadsheet_windows/csv_option.rb +58 -0
  27. data/lib/onlyoffice_documentserver_testing_framework/version.rb +9 -0
  28. metadata +229 -0
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Class for describing Welcome page of test example
4
+ # https://cloud.githubusercontent.com/assets/668524/15577518/891848c8-2365-11e6-8a2a-af98618067b5.png
5
+ class DocServiceWelcome
6
+ def initialize(instance)
7
+ @instance = instance
8
+ @xpath_test_example = '//a[contains(@href, "/example")]'
9
+ end
10
+
11
+ # Waiting for load of page
12
+ # @return [Nothing]
13
+ def wait_load
14
+ @instance.webdriver.wait_until do
15
+ opened?
16
+ end
17
+ sleep 1 # Additional wait for load
18
+ end
19
+
20
+ # @return [True, False] is welcome page opened
21
+ def opened?
22
+ result = @instance.selenium.element_present?(@xpath_test_example)
23
+ OnlyofficeLoggerHelper.log("Current server is a Doc Service Welcome: #{result}")
24
+ result
25
+ end
26
+
27
+ # Go to Test Example
28
+ # @return [Nothing]
29
+ def go_to_example
30
+ wait_load
31
+ @instance.selenium.click_on_locator(@xpath_test_example)
32
+ OnlyofficeLoggerHelper.log('Go to test example')
33
+ @instance.doc_test_functions.wait_load
34
+ end
35
+ end
@@ -0,0 +1,235 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'doc_test_site_functions/healthcheck_page'
4
+ require_relative 'doc_test_site_functions/doc_test_file_list'
5
+ require_relative 'doc_test_site_functions/doc_test_site_server_helper'
6
+ # Class to work with test examples
7
+ class DocTestSiteFunctions
8
+ extend DocTestSiteServerHelper
9
+ include PageObject
10
+
11
+ # @return [Array<String>] list of supported languages
12
+ SUPPORTED_LANGUAGES = %w[English
13
+ Bulgarian
14
+ Chinese
15
+ Czech
16
+ Dutch
17
+ French
18
+ German
19
+ Hungarian
20
+ Italian
21
+ Japanese
22
+ Korean
23
+ Latvian
24
+ Polish
25
+ Portuguese
26
+ Russian
27
+ Slovak
28
+ Slovenian
29
+ Spanish
30
+ Turkish
31
+ Ukrainian
32
+ Vietnamese].freeze
33
+ select_list(:user_list, xpath: '//*[@id="user"]')
34
+ select_list(:language_list, xpath: '//*[@id="language"]')
35
+
36
+ def initialize(instance)
37
+ super(instance.webdriver.driver)
38
+ @instance = instance
39
+ @xpath_begin_view = '//*[@id="beginView"]'
40
+ @xpath_file_loading_step = '//*[@id="step1"]'
41
+ @xpath_conversion_step = '//*[@id="step2"]'
42
+ @xpath_editor_scripts_step = '//*[@id="step3"]'
43
+ @xpath_file_entry = '//*[@class="stored-list"]/table/tbody/tr'
44
+ end
45
+
46
+ # Waiting for load of page
47
+ # @return [Nothing]
48
+ def wait_load
49
+ @instance.webdriver.wait_until do
50
+ doc_test_site?
51
+ end
52
+ end
53
+
54
+ # reload the page
55
+ # @return [Nothing]
56
+ def reload
57
+ @instance.webdriver.refresh
58
+ wait_load
59
+ end
60
+
61
+ # Check if current site is DocTestSite
62
+ # @return [true, false] result of checking
63
+ def doc_test_site?
64
+ sleep(1) # TODO: remove after update to Chromedriver 80
65
+ result = @instance.selenium.element_present?(@xpath_begin_view)
66
+ OnlyofficeLoggerHelper.log("Current server is a doc_test_site: #{result}")
67
+ result
68
+ end
69
+
70
+ # Upload file to portal
71
+ # @param [String] file_path like as '/mnt/data_share/Files/DOCX/empty.docx'
72
+ def upload_file(file_path)
73
+ file_path_absolute = file_path.gsub('~', ENV['HOME'])
74
+ @instance.selenium.type_to_locator('//*[@id="fileupload"]', file_path_absolute, false, false, false, true)
75
+ wait_loading_file
76
+ wait_conversion
77
+ wait_loading_scripts
78
+ true
79
+ end
80
+
81
+ # Check for any error in loading process and raise it
82
+ # @return [Nothing]
83
+ def check_error
84
+ error_message = @instance.selenium.get_text('//*[@class="error-message"]/span', false)
85
+
86
+ return if error_message.empty?
87
+
88
+ @instance.selenium.webdriver_error('Error while uploading document. '\
89
+ "Error message: #{error_message}")
90
+ end
91
+
92
+ # Waits until file converts
93
+ # @return [Nothing]
94
+ def wait_loading_file
95
+ 100.times do |current_time|
96
+ OnlyofficeLoggerHelper.log("Waiting for file loading for #{current_time} seconds")
97
+ return true if @instance.selenium.get_attribute(@xpath_file_loading_step, 'class').include?('done')
98
+
99
+ sleep 1
100
+ check_error
101
+ end
102
+ @instance.selenium.webdriver_error('File not finished for loading scripts for 100 seconds')
103
+ end
104
+
105
+ # Waits until file converts
106
+ # @return [Nothing]
107
+ def wait_conversion
108
+ 100.times do |current_time|
109
+ OnlyofficeLoggerHelper.log("Waiting for file conversion for #{current_time} seconds")
110
+ return true if @instance.selenium.get_attribute(@xpath_conversion_step, 'class').include?('done')
111
+
112
+ sleep 1
113
+ check_error
114
+ end
115
+ @instance.selenium.webdriver_error('File not finished for conversion for 100 seconds')
116
+ end
117
+
118
+ # Waits until scripts loads
119
+ # @return [Nothing]
120
+ def wait_loading_scripts
121
+ 100.times do |current_time|
122
+ OnlyofficeLoggerHelper.log("Waiting for editors scripts load for #{current_time} seconds")
123
+ return true if @instance.selenium.get_attribute(@xpath_editor_scripts_step, 'class').include?('done')
124
+
125
+ sleep 1
126
+ check_error
127
+ end
128
+ @instance.selenium.webdriver_error('File not finished for loading scripts for 100 seconds')
129
+ end
130
+
131
+ # Check if file uploaded
132
+ # @return [Boolean]
133
+ def file_uploaded?
134
+ @instance.selenium.element_visible?(@xpath_begin_view)
135
+ end
136
+
137
+ # help-method to #open_file_in_editor and #open_file_in_viewer
138
+ def open_file_in
139
+ result = 'Unknown'
140
+ if file_uploaded?
141
+ yield
142
+ sleep 5
143
+ @instance.selenium.close_tab
144
+ @instance.selenium.switch_to_main_tab
145
+ result = @instance.management.wait_for_operation_with_round_status_canvas
146
+ sleep 3 # just for sure
147
+ end
148
+ result
149
+ end
150
+
151
+ # Click on Edit Button and wait opening Editor
152
+ # Return result of the opening Editor
153
+ def open_file_in_editor
154
+ open_file_in { @instance.selenium.click_on_locator('//*[@id="beginEdit"]') }
155
+ end
156
+
157
+ # Click on View Button and wait opening Viewer
158
+ # Return result of the opening Viewer
159
+ def open_file_in_viewer
160
+ open_file_in { @instance.selenium.click_on_locator(@xpath_begin_view) }
161
+ end
162
+
163
+ # Get url of document which opened in editor
164
+ # @return [String] url
165
+ def current_document_storage_url
166
+ page_source = @instance.selenium.get_page_source
167
+ url_line = page_source.scan(/"?url"?: ".*$/).first
168
+ url_line.delete('"').gsub('url: ', '').chop
169
+ end
170
+
171
+ # @return [True, False] is on file list page now?
172
+ def file_list_opened?
173
+ @instance.selenium.element_visible?('//*[contains(@class, "try-editor document")]')
174
+ end
175
+
176
+ # @return [Integer] count of uploaded files
177
+ def uploaded_file_count
178
+ @instance.selenium.get_element_count(@xpath_file_entry)
179
+ end
180
+
181
+ # @return [DocTestFileLIst] get file list
182
+ def uploaded_file_list
183
+ file_list = []
184
+ (0...uploaded_file_count).each do |current_file_number|
185
+ file_list << DocTestSiteFileListEntry.new(@instance, "#{@xpath_file_entry}[#{current_file_number + 1}]")
186
+ end
187
+ DocTestFileList.new(file_list)
188
+ end
189
+
190
+ # @return [Checkbox] save in original format checkbox
191
+ def save_in_original_format
192
+ checkbox = CheckBox.new(@instance)
193
+ checkbox.xpath = '//*[@id="checkOriginalFormat"]'
194
+ checkbox.count_of_frame = 0
195
+ checkbox
196
+ end
197
+
198
+ # @return [Checkbox] Create a file filled with sample content
199
+ def create_a_file_with_sample
200
+ checkbox = CheckBox.new(@instance)
201
+ checkbox.xpath = '//*[@id="createSample"]'
202
+ checkbox.count_of_frame = 0
203
+ checkbox
204
+ end
205
+
206
+ # Perform creating sample document
207
+ # @return [String] result of opening
208
+ def open_sample_document(format = :document, wait_to_load: true)
209
+ case format
210
+ when :document
211
+ @instance.selenium.click_on_locator('//*[contains(@class, "try-editor document")]')
212
+ when :spreadsheet
213
+ @instance.selenium.click_on_locator('//*[contains(@class, "try-editor spreadsheet")]')
214
+ when :presentation
215
+ @instance.selenium.click_on_locator('//*[contains(@class, "try-editor presentation")]')
216
+ else
217
+ @instance.webdriver.webdriver_error("Unknown file type for open_sample_document(#{format})")
218
+ end
219
+ return unless wait_to_load
220
+
221
+ @instance.selenium.close_tab
222
+ @instance.selenium.switch_to_main_tab
223
+ @instance.management.wait_for_operation_with_round_status_canvas
224
+ end
225
+
226
+ # @return [Nothing]
227
+ def go_to_healthcheck
228
+ @instance.webdriver.open("#{@instance.user_data.portal}/healthcheck")
229
+ end
230
+
231
+ # @return [HealthcheckPage] page of healthcheck
232
+ def healthcheck
233
+ @healthcheck = HealthcheckPage.new(@instance)
234
+ end
235
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'doc_test_file_list/doc_test_site_file_list_entry'
4
+ # Class for storing list of test example files
5
+ # https://cloud.githubusercontent.com/assets/668524/13947979/935506a6-f02e-11e5-86f4-6903dfd6119e.png
6
+ class DocTestFileList
7
+ attr_accessor :file_list
8
+
9
+ def initialize(file_list = [])
10
+ @file_list = file_list
11
+ end
12
+
13
+ # Access file in list like array
14
+ # @param key [String] name of file
15
+ # @return [DocTestSiteFileListEntry]
16
+ def [](key)
17
+ @file_list[key]
18
+ end
19
+
20
+ # Get diff between two file list
21
+ # @param other [DocTestFileList] diff with other list
22
+ # @return [Hash] diff
23
+ def -(other)
24
+ diff_items = []
25
+ @file_list.each do |current_item|
26
+ found = false
27
+ other.file_list.each do |other_item|
28
+ found = true if current_item == other_item
29
+ end
30
+ diff_items << current_item unless found
31
+ end
32
+ diff_items
33
+ end
34
+ end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Class for single entry of file in doc test site
4
+ # https://cloud.githubusercontent.com/assets/668524/13947979/935506a6-f02e-11e5-86f4-6903dfd6119e.png
5
+ class DocTestSiteFileListEntry
6
+ # @return [String] name of file
7
+ attr_accessor :file_name
8
+ # @return [String] url of embedded mode
9
+ attr_accessor :embedded_url
10
+ # @return [String] Review mode url
11
+ attr_accessor :review_mode_url
12
+ # @return [String] Comment mode url
13
+ attr_accessor :comment_mode_url
14
+ # @return [String] Fill forms mode url
15
+ attr_reader :fill_forms_mode_url
16
+ # @return [String] Only fill forms mode url
17
+ attr_reader :only_fill_forms_mode_url
18
+ # @return [String] View mode url
19
+ attr_accessor :view_mode_url
20
+
21
+ def initialize(instance, xpath)
22
+ @instance = instance
23
+ @xpath_line = xpath
24
+ @file_name = fetch_file_name
25
+ @embedded_url = fetch_embedded_url
26
+ @review_mode_url = fetch_review_mode_url
27
+ @comment_mode_url = fetch_comment_mode_url
28
+ @fill_forms_mode_url = fetch_fill_forms_mode_url
29
+ @view_mode_url = fetch_view_mode_url
30
+ end
31
+
32
+ # Compare two DocTestSiteFileListEntry
33
+ # @return [True, False] is entries are the same
34
+ def ==(other)
35
+ @file_name == other.file_name
36
+ end
37
+
38
+ # @return [String] name of file
39
+ def fetch_file_name
40
+ text = @instance.selenium.get_text("#{@xpath_line}/td/a[1]/span")
41
+ OnlyofficeLoggerHelper.log("Got filename #{@xpath_line} name: #{text}")
42
+ text
43
+ end
44
+
45
+ # @return [String] url on review mode
46
+ def fetch_review_mode_url
47
+ xpath_review = "#{@xpath_line}/td[4]/a"
48
+ return nil unless @instance.selenium.element_present?(xpath_review)
49
+
50
+ url = @instance.selenium.get_attribute(xpath_review, 'href')
51
+ OnlyofficeLoggerHelper.log("Got review mode #{@xpath_line} url: #{url}")
52
+ url
53
+ end
54
+
55
+ # @return [String] url on review mode
56
+ def fetch_comment_mode_url
57
+ xpath_comment = "#{@xpath_line}/td[5]/a"
58
+ return nil unless @instance.selenium.element_present?(xpath_comment)
59
+
60
+ url = @instance.selenium.get_attribute(xpath_comment, 'href')
61
+ OnlyofficeLoggerHelper.log("Got comment mode #{@xpath_line} url: #{url}")
62
+ url
63
+ end
64
+
65
+ # @return [String] url on fill forms mode
66
+ def fetch_fill_forms_mode_url
67
+ xpath_comment = "#{@xpath_line}/td[6]/a"
68
+ return nil unless @instance.selenium.element_present?(xpath_comment)
69
+
70
+ url = @instance.selenium.get_attribute(xpath_comment, 'href')
71
+ OnlyofficeLoggerHelper.log("Got fill forms mode #{@xpath_line} url: #{url}")
72
+ url
73
+ end
74
+
75
+ # @return [String] url on fill forms mode
76
+ def fetch_only_fill_forms_mode_url
77
+ link_xpath = "#{@xpath_line}/td[7]/a"
78
+ return nil unless @instance.selenium.element_present?(link_xpath)
79
+
80
+ url = @instance.selenium.get_attribute(link_xpath, 'href')
81
+ OnlyofficeLoggerHelper.log("Got only fill forms mode #{@xpath_line} url: #{url}")
82
+ url
83
+ end
84
+
85
+ # @return [String] url on viewer mode
86
+ def fetch_view_mode_url
87
+ xpath_comments = "#{@xpath_line}/td[8]/a"
88
+ return nil unless @instance.selenium.element_present?(xpath_comments)
89
+
90
+ url = @instance.selenium.get_attribute(xpath_comments, 'href')
91
+ OnlyofficeLoggerHelper.log("Got view mode #{@xpath_line} url: #{url}")
92
+ url
93
+ end
94
+
95
+ # @return [String] url on embedded file
96
+ def fetch_embedded_url
97
+ url = @instance.selenium.get_attribute("#{@xpath_line}/td[10]/a", 'href')
98
+ OnlyofficeLoggerHelper.log("Got embedded #{@xpath_line} url: #{url}")
99
+ url
100
+ end
101
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Helper method to fetch server url
4
+ module DocTestSiteServerHelper
5
+ # @return [String] url of docserver
6
+ def fetch_docserverserver_url(example_url)
7
+ page_data = URI.parse(example_url).open.read
8
+ html_doc = Nokogiri::HTML(page_data)
9
+ load_scripts_data = html_doc.xpath('//*[@id="loadScripts"]')
10
+ return nil if load_scripts_data.empty?
11
+
12
+ script_html = load_scripts_data.attr('data-docs')
13
+ server_from_cache_script_html(script_html)
14
+ rescue RuntimeError => e
15
+ OnlyofficeLoggerHelper.log("Failed to fetch_docserverserver_url with #{e}")
16
+ nil
17
+ end
18
+
19
+ private
20
+
21
+ def server_from_cache_script_html(url)
22
+ uri = URI(url)
23
+ "#{uri.scheme}://#{uri.host}:#{uri.port}"
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Page for describing healthcheck page
4
+ class HealthcheckPage
5
+ def initialize(instance)
6
+ @instance = instance
7
+ end
8
+
9
+ # @return [String] status of healthcheck on page
10
+ def status
11
+ current_status = @instance.webdriver.get_text('//body')
12
+ OnlyofficeLoggerHelper.log("Current status of healthcheck is: #{current_status}")
13
+ current_status
14
+ end
15
+ end