Class: ResourcesBase
- Defined in:
- lib/sakai-cle-test-api/page_objects/resources.rb
Overview
This class consolidates the code that can be shared among all the File Upload and Attachment pages.
Not every method in this class will be appropriate for every attachment page.
Direct Known Subclasses
CreateFolders, EditFileDetails, EditHTMLPageProperties, Resources, ResourcesUploadFiles, StylesUploadFiles
Instance Method Summary collapse
-
#access_level(filename) ⇒ Object
Gets the value of the access level cell for the specified file.
-
#attach_a_copy(file_name) ⇒ Object
Clicks the “Attach a copy” link for the specified file, then reinstantiates the Class.
-
#continue ⇒ Object
Clicks the Continue button.
- #create_html_page_in(folder_name) ⇒ Object
-
#create_subfolders_in(folder_name) ⇒ Object
Clicks the Create Folders menu item in the Add menu of the specified folder.
- #edit_content(html_page_name) ⇒ Object
- #edit_details(name) ⇒ Object
-
#file_names ⇒ Object
Returns an array of the file names currently listed on the page.
-
#folder_names ⇒ Object
Returns an array of the displayed folder names.
-
#go_to_folder(foldername) ⇒ Object
Clicks on the specified folder name, which should open the folder contents on a refreshed page.
- #href(item) ⇒ Object
-
#item(name) ⇒ Object
Use this as a means of checking if the file is visible or not.
- #open_actions_menu(name) ⇒ Object
- #open_add_menu(folder_name) ⇒ Object
-
#open_folder(foldername) ⇒ Object
Clicks on the specified folder image, which will open the folder tree and remain on the page.
-
#remove_item(file_name) ⇒ Object
Clicks the remove link for the specified item in the attachment list.
-
#select_file(filename) ⇒ Object
Clicks the Select button next to the specified file.
-
#upload_file(filename, filepath = "") ⇒ Object
Enters the specified file into the file field name (assuming it’s in the data/sakai-cle-test-api folder or a subfolder therein).
-
#upload_files_to_folder(folder_name) ⇒ Object
(also: #upload_file_to_folder)
Clicks the Add Menu for the specified folder, then selects the Upload Files command in the menu that appears.
-
#upload_local_file(filename, filepath = "") ⇒ Object
Enters the specified file into the file field name (assuming it’s in the data/sakai-cle-test-api folder or a subfolder therein).
-
#upload_multiple_files_to_folder(folder, file_array, file_path = "") ⇒ Object
Takes the specified array object containing pointers to local file resources, then uploads those files to the folder specified, checks if they all uploaded properly and if not, re-tries the ones that failed the first time.
-
#url=(url_string) ⇒ Object
Sets the URL field to the specified value.
Methods inherited from BasePage
basic_page_elements, frame_element
Methods inherited from PageMaker
element, expected_element, expected_title, #initialize, #method_missing, page_url
Constructor Details
This class inherits a constructor from PageMaker
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class PageMaker
Instance Method Details
#access_level(filename) ⇒ Object
Gets the value of the access level cell for the specified file.
90 91 92 |
# File 'lib/sakai-cle-test-api/page_objects/resources.rb', line 90 def access_level(filename) files_table.row(:text=>/#{Regexp.escape(filename)}/)[6].text end |
#attach_a_copy(file_name) ⇒ Object
Clicks the “Attach a copy” link for the specified file, then reinstantiates the Class. If an alert box appears, the method will call itself again. Note that this can lead to an infinite loop. Will need to fix later.
159 160 161 162 163 164 165 |
# File 'lib/sakai-cle-test-api/page_objects/resources.rb', line 159 def attach_a_copy(file_name) files_table.row(:text=>/#{Regexp.escape(file_name)}/).link(:href=>/doAttachitem/).click if frm.div(:class=>"alertMessage").exist? sleep 1 attach_a_copy(file_name) # TODO - This can loop infinitely end end |
#continue ⇒ Object
Clicks the Continue button
197 198 199 200 |
# File 'lib/sakai-cle-test-api/page_objects/resources.rb', line 197 def continue frm.div(:class=>"highlightPanel").span(:id=>"submitnotifxxx").wait_while_present frm.(:value=>"Continue").click end |
#create_html_page_in(folder_name) ⇒ Object
111 112 113 114 |
# File 'lib/sakai-cle-test-api/page_objects/resources.rb', line 111 def create_html_page_in(folder_name) (folder_name) files_table.row(:text=>/#{Regexp.escape(folder_name)}/).link(:text=>"Create HTML Page").click end |
#create_subfolders_in(folder_name) ⇒ Object
Clicks the Create Folders menu item in the Add menu of the specified folder.
106 107 108 109 |
# File 'lib/sakai-cle-test-api/page_objects/resources.rb', line 106 def create_subfolders_in(folder_name) (folder_name) files_table.row(:text=>/#{Regexp.escape(folder_name)}/).link(:text=>"Create Folders").click end |
#edit_content(html_page_name) ⇒ Object
99 100 101 102 |
# File 'lib/sakai-cle-test-api/page_objects/resources.rb', line 99 def edit_content(html_page_name) (html_page_name) files_table.row(:text=>/#{Regexp.escape(html_page_name)}/).link(:text=>"Edit Content").click end |
#edit_details(name) ⇒ Object
94 95 96 97 |
# File 'lib/sakai-cle-test-api/page_objects/resources.rb', line 94 def edit_details(name) (name) files_table.row(:text=>/#{Regexp.escape(name)}/).link(:text=>"Edit Details").click end |
#file_names ⇒ Object
Returns an array of the file names currently listed on the page.
It excludes folder names.
30 31 32 33 34 35 36 37 38 |
# File 'lib/sakai-cle-test-api/page_objects/resources.rb', line 30 def file_names names = [] files_table.rows.each do |row| next if row.td(:class=>"specialLink").exist? == false next if row.td(:class=>"specialLink").link(:title=>"Folder").exist? names << row.td(:class=>"specialLink").link(:href=>/access.content/, :index=>1).text end names end |
#folder_names ⇒ Object
Returns an array of the displayed folder names.
16 17 18 19 20 21 22 23 24 |
# File 'lib/sakai-cle-test-api/page_objects/resources.rb', line 16 def folder_names names = [] files_table.rows.each do |row| next if row.td(:class=>"specialLink").exist? == false next if row.td(:class=>"specialLink").link(:title=>"Folder").exist? == false names << row.td(:class=>"specialLink").link(:title=>"Folder").text end names end |
#go_to_folder(foldername) ⇒ Object
Clicks on the specified folder name, which should open the folder contents on a refreshed page.
76 77 78 |
# File 'lib/sakai-cle-test-api/page_objects/resources.rb', line 76 def go_to_folder(foldername) frm.link(:text=>foldername).click end |
#href(item) ⇒ Object
64 65 66 |
# File 'lib/sakai-cle-test-api/page_objects/resources.rb', line 64 def href(item) frm.link(:text=>item).href end |
#item(name) ⇒ Object
Use this as a means of checking if the file is visible or not
41 42 43 |
# File 'lib/sakai-cle-test-api/page_objects/resources.rb', line 41 def item(name) frm.link(:text=>name) end |
#open_actions_menu(name) ⇒ Object
206 207 208 |
# File 'lib/sakai-cle-test-api/page_objects/resources.rb', line 206 def (name) files_table.row(:text=>/#{Regexp.escape(name)}/).li(:text=>/Action/, :class=>"menuOpen").fire_event("onclick") end |
#open_add_menu(folder_name) ⇒ Object
202 203 204 |
# File 'lib/sakai-cle-test-api/page_objects/resources.rb', line 202 def (folder_name) files_table.row(:text=>/#{Regexp.escape(folder_name)}/).link(:text=>"Start Add Menu").fire_event("onfocus") end |
#open_folder(foldername) ⇒ Object
Clicks on the specified folder image, which will open the folder tree and remain on the page.
70 71 72 |
# File 'lib/sakai-cle-test-api/page_objects/resources.rb', line 70 def open_folder(foldername) files_table.row(:text=>/#{Regexp.escape(foldername)}/).link(:title=>"Open this folder").click end |
#remove_item(file_name) ⇒ Object
Clicks the remove link for the specified item in the attachment list.
54 55 56 |
# File 'lib/sakai-cle-test-api/page_objects/resources.rb', line 54 def remove_item(file_name) files_table.row(:text=>/#{Regexp.escape(file_name)}/).link(:href=>/doRemoveitem/).click end |
#select_file(filename) ⇒ Object
Clicks the Select button next to the specified file.
46 47 48 |
# File 'lib/sakai-cle-test-api/page_objects/resources.rb', line 46 def select_file(filename) files_table.row(:text, /#{Regexp.escape(filename)}/).link(:text=>"Select").click end |
#upload_file(filename, filepath = "") ⇒ Object
Enters the specified file into the file field name (assuming it’s in the data/sakai-cle-test-api folder or a subfolder therein)
121 122 123 124 125 126 127 |
# File 'lib/sakai-cle-test-api/page_objects/resources.rb', line 121 def upload_file(filename, filepath="") upload_file_field.set(filepath + filename) if frm.div(:class=>"alertMessage").exist? sleep 2 upload_file(filename) end end |
#upload_files_to_folder(folder_name) ⇒ Object Also known as: upload_file_to_folder
Clicks the Add Menu for the specified folder, then selects the Upload Files command in the menu that appears.
145 146 147 148 149 150 151 152 |
# File 'lib/sakai-cle-test-api/page_objects/resources.rb', line 145 def upload_files_to_folder(folder_name) if frm.li(:text=>/A/, :class=>"menuOpen").exist? files_table.row(:text=>/#{Regexp.escape(folder_name)}/).li(:text=>/A/, :class=>"menuOpen").fire_event("onclick") else files_table.row(:text=>/#{Regexp.escape(folder_name)}/).link(:text=>"Start Add Menu").fire_event("onfocus") end files_table.row(:text=>/#{Regexp.escape(folder_name)}/).link(:text=>"Upload Files").click end |
#upload_local_file(filename, filepath = "") ⇒ Object
Enters the specified file into the file field name (assuming it’s in the data/sakai-cle-test-api folder or a subfolder therein)
Use this method ONLY for instances where there’s a file field on the page with an “upload” id.
134 135 136 137 138 139 140 |
# File 'lib/sakai-cle-test-api/page_objects/resources.rb', line 134 def upload_local_file(filename, filepath="") upload_file_field.set(filepath + filename) if frm.div(:class=>"alertMessage").exist? sleep 2 upload_local_file(filename) end end |
#upload_multiple_files_to_folder(folder, file_array, file_path = "") ⇒ Object
Takes the specified array object containing pointers to local file resources, then uploads those files to the folder specified, checks if they all uploaded properly and if not, re-tries the ones that failed the first time.
Finally, it re-instantiates the appropriate page class. Note that it expects all files to be located in the same folder (can be in subfolders of that folder).
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/sakai-cle-test-api/page_objects/resources.rb', line 174 def upload_multiple_files_to_folder(folder, file_array, file_path="") upload = upload_files_to_folder folder file_array.each do |file| upload.file_to_upload(file, file_path) upload.add_another_file end resources = upload.upload_files_now file_array.each do |file| file =~ /(?<=\/).+/ # puts $~.to_s # For debugging purposes unless resources.file_names.include?($~.to_s) upload_files = resources.upload_files_to_folder(folder) upload_files.file_to_upload(file, file_path) upload_files.upload_files_now end end end |
#url=(url_string) ⇒ Object
Sets the URL field to the specified value.
81 82 83 |
# File 'lib/sakai-cle-test-api/page_objects/resources.rb', line 81 def url=(url_string) frm.text_field(:id=>"url").set(url_string) end |