Class: AttachPageTools
- Inherits:
-
Object
- Object
- AttachPageTools
- Defined in:
- lib/sakai-cle-test-api/app_functions.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
AnnouncementsAttach, AssignmentAttachments, AttachFileFormImport, DropBox, EventAttach, ForumsAddAttachments, GlossaryAttach, LessonAddAttachment, MessagesAttachment, PortfolioAttachFiles, Resources, StylesAddAttachment, SyllabusAttach
Constant Summary collapse
- @@classes =
{ :this=>"Superclassdummy", :parent=>"Superclassdummy" }
Instance Method Summary collapse
-
#access_level(filename) ⇒ Object
Gets the value of the access level cell for the specified file.
-
#add ⇒ Object
Clicks the Add button next to the URL field.
-
#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 then decides which page class to instantiate based on the page that appears.
-
#create_subfolders_in(folder_name) ⇒ Object
Clicks the Create Folders menu item in the Add menu of the specified folder.
- #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.
-
#move ⇒ Object
Clicks the Move button.
-
#open_folder(foldername) ⇒ Object
Clicks on the specified folder image, which will open the folder tree and remain on the page.
-
#remove ⇒ Object
Clicks the Remove button.
-
#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.
-
#show_other_sites ⇒ Object
Clicks the Show Other Sites link.
-
#upload_file(filename) ⇒ 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_file_to_folder(folder_name) ⇒ Object
Clicks the Add Menu for the specified folder, then selects the Upload Files command in the menu that appears.
-
#upload_files_to_folder(folder_name) ⇒ Object
Clicks the Add Menu for the specified folder, then selects the Upload Files command in the menu that appears.
-
#upload_local_file(filename) ⇒ 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) ⇒ 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.
-
#what_is_parent? ⇒ Boolean
Use this for debugging purposes only…
Instance Method Details
#access_level(filename) ⇒ Object
Gets the value of the access level cell for the specified file.
544 545 546 |
# File 'lib/sakai-cle-test-api/app_functions.rb', line 544 def access_level(filename) frm.table(:class=>/listHier lines/).row(:text=>/#{Regexp.escape(filename)}/)[6].text end |
#add ⇒ Object
Clicks the Add button next to the URL field.
538 539 540 |
# File 'lib/sakai-cle-test-api/app_functions.rb', line 538 def add frm.(:value=>"Add").click 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.
612 613 614 615 616 617 618 619 |
# File 'lib/sakai-cle-test-api/app_functions.rb', line 612 def attach_a_copy(file_name) frm.table(:class=>/listHier lines/).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 instantiate_class(:this) end |
#continue ⇒ Object
Clicks the Continue button then decides which page class to instantiate based on the page that appears. This is going to need to be fixed.
661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 |
# File 'lib/sakai-cle-test-api/app_functions.rb', line 661 def continue frm.div(:class=>"highlightPanel").span(:id=>"submitnotifxxx").wait_while_present frm.(:value=>"Continue").click page_title = @browser.div(:class=>"title").text case(page_title) when "Lessons" instantiate_class(:parent) when "Assignments" if frm.div(:class=>"portletBody").h3.text=~/In progress/ || frm.div(:class=>"portletBody").h3.text == "Select supporting files" instantiate_class(:second) elsif frm.div(:class=>"portletBody").h3.text=~/edit/i || frm.div(:class=>"portletBody").h3.text=~/add/i instantiate_class(:parent) elsif frm.form(:id=>"gradeForm").exist? instantiate_class(:third) end when "Forums" if frm.div(:class=>"portletBody").h3.text == "Forum Settings" instantiate_class(:second) else instantiate_class(:parent) end when "Messages" if frm.div(:class=>/breadCrumb/).text =~ /Reply to Message/ instantiate_class(:second) else instantiate_class(:parent) end when "Calendar" frm.frame(:id, "description___Frame").td(:id, "xEditingArea").frame(:index=>0).wait_until_present instantiate_class(:parent) when "Portfolio Templates" if frm.div(:class=>"portletBody").h3.text=="Select supporting files" instantiate_class(:second) else instantiate_class(:parent) end else instantiate_class(:parent) end end |
#create_subfolders_in(folder_name) ⇒ Object
Clicks the Create Folders menu item in the Add menu of the specified folder.
556 557 558 559 560 |
# File 'lib/sakai-cle-test-api/app_functions.rb', line 556 def create_subfolders_in(folder_name) frm.table(:class=>/listHier lines/).row(:text=>/#{Regexp.escape(folder_name)}/).link(:text=>"Start Add Menu").fire_event("onfocus") frm.table(:class=>/listHier lines/).row(:text=>/#{Regexp.escape(folder_name)}/).link(:text=>"Create Folders").click instantiate_class(:create_folders) end |
#edit_details(name) ⇒ Object
548 549 550 551 552 |
# File 'lib/sakai-cle-test-api/app_functions.rb', line 548 def edit_details(name) frm.table(:class=>/listHier lines/).row(:text=>/#{Regexp.escape(name)}/).li(:text=>/Action/, :class=>"menuOpen").fire_event("onclick") frm.table(:class=>/listHier lines/).row(:text=>/#{Regexp.escape(name)}/).link(:text=>"Edit Details").click instantiate_class(:file_details) end |
#file_names ⇒ Object
Returns an array of the file names currently listed on the page.
It excludes folder names.
485 486 487 488 489 490 491 492 493 |
# File 'lib/sakai-cle-test-api/app_functions.rb', line 485 def file_names names = [] frm.table(:class=>/listHier lines/).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 return names end |
#folder_names ⇒ Object
Returns an array of the displayed folder names.
471 472 473 474 475 476 477 478 479 |
# File 'lib/sakai-cle-test-api/app_functions.rb', line 471 def folder_names names = [] frm.table(:class=>/listHier lines/).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 return names end |
#go_to_folder(foldername) ⇒ Object
Clicks on the specified folder name, which should open the folder contents on a refreshed page.
528 529 530 |
# File 'lib/sakai-cle-test-api/app_functions.rb', line 528 def go_to_folder(foldername) frm.link(:text=>foldername).click end |
#move ⇒ Object
Clicks the Move button.
511 512 513 |
# File 'lib/sakai-cle-test-api/app_functions.rb', line 511 def move frm.(:value=>"Move").click end |
#open_folder(foldername) ⇒ Object
Clicks on the specified folder image, which will open the folder tree and remain on the page.
522 523 524 |
# File 'lib/sakai-cle-test-api/app_functions.rb', line 522 def open_folder(foldername) frm.table(:class=>/listHier lines/).row(:text=>/#{Regexp.escape(foldername)}/).link(:title=>"Open this folder").click end |
#remove ⇒ Object
Clicks the Remove button.
501 502 503 |
# File 'lib/sakai-cle-test-api/app_functions.rb', line 501 def remove frm.(:value=>"Remove").click end |
#remove_item(file_name) ⇒ Object
Clicks the remove link for the specified item in the attachment list.
506 507 508 |
# File 'lib/sakai-cle-test-api/app_functions.rb', line 506 def remove_item(file_name) frm.table(:class=>/listHier/).row(:text=>/#{Regexp.escape(file_name)}/).link(:href=>/doRemoveitem/).click end |
#select_file(filename) ⇒ Object
Clicks the Select button next to the specified file.
496 497 498 |
# File 'lib/sakai-cle-test-api/app_functions.rb', line 496 def select_file(filename) frm.table(:class=>/listHier lines/).row(:text, /#{Regexp.escape(filename)}/).link(:text=>"Select").click end |
#show_other_sites ⇒ Object
Clicks the Show Other Sites link.
516 517 518 |
# File 'lib/sakai-cle-test-api/app_functions.rb', line 516 def show_other_sites frm.link(:text=>"Show other sites").click end |
#upload_file(filename) ⇒ 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)
Does NOT instantiate any class, so use only when no page refresh occurs.
566 567 568 569 570 571 572 |
# File 'lib/sakai-cle-test-api/app_functions.rb', line 566 def upload_file(filename) frm.file_field(:id=>"upload").set(File.(File.dirname(__FILE__)) + "/../../data/sakai-cle-test-api/" + filename) if frm.div(:class=>"alertMessage").exist? sleep 2 upload_file(filename) end end |
#upload_file_to_folder(folder_name) ⇒ Object
Clicks the Add Menu for the specified folder, then selects the Upload Files command in the menu that appears.
591 592 593 |
# File 'lib/sakai-cle-test-api/app_functions.rb', line 591 def upload_file_to_folder(folder_name) upload_files_to_folder(folder_name) end |
#upload_files_to_folder(folder_name) ⇒ Object
Clicks the Add Menu for the specified folder, then selects the Upload Files command in the menu that appears.
598 599 600 601 602 603 604 605 606 |
# File 'lib/sakai-cle-test-api/app_functions.rb', line 598 def upload_files_to_folder(folder_name) if frm.li(:text=>/A/, :class=>"menuOpen").exist? frm.table(:class=>/listHier lines/).row(:text=>/#{Regexp.escape(folder_name)}/).li(:text=>/A/, :class=>"menuOpen").fire_event("onclick") else frm.table(:class=>/listHier lines/).row(:text=>/#{Regexp.escape(folder_name)}/).link(:text=>"Start Add Menu").fire_event("onfocus") end frm.table(:class=>/listHier lines/).row(:text=>/#{Regexp.escape(folder_name)}/).link(:text=>"Upload Files").click instantiate_class(:upload_files) end |
#upload_local_file(filename) ⇒ 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.
579 580 581 582 583 584 585 586 |
# File 'lib/sakai-cle-test-api/app_functions.rb', line 579 def upload_local_file(filename) frm.file_field(:id=>"upload").set(File.(File.dirname(__FILE__)) + "/../../data/sakai-cle-test-api/" + filename) if frm.div(:class=>"alertMessage").exist? sleep 2 upload_local_file(filename) end instantiate_class(:this) end |
#upload_multiple_files_to_folder(folder, file_array) ⇒ 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 AnnouncementsAttach page class.
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 |
# File 'lib/sakai-cle-test-api/app_functions.rb', line 635 def upload_multiple_files_to_folder(folder, file_array) upload = upload_files_to_folder folder file_array.each do |file| upload.file_to_upload=file 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 resources = upload_files.upload_files_now end end instantiate_class(:this) end |
#url=(url_string) ⇒ Object
Sets the URL field to the specified value.
533 534 535 |
# File 'lib/sakai-cle-test-api/app_functions.rb', line 533 def url=(url_string) frm.text_field(:id=>"url").set(url_string) end |
#what_is_parent? ⇒ Boolean
Use this for debugging purposes only…
466 467 468 |
# File 'lib/sakai-cle-test-api/app_functions.rb', line 466 def what_is_parent? puts @@classes[:parent] end |