sakai-cle-test-api 0.0.75 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. data/lib/sakai-cle-test-api.rb +4 -5
  2. data/lib/sakai-cle-test-api/base_page.rb +20 -0
  3. data/lib/sakai-cle-test-api/core-ext.rb +90 -0
  4. data/lib/sakai-cle-test-api/data_objects/announcement.rb +81 -0
  5. data/lib/sakai-cle-test-api/data_objects/assessment.rb +32 -0
  6. data/lib/sakai-cle-test-api/data_objects/assignment.rb +90 -0
  7. data/lib/sakai-cle-test-api/data_objects/event.rb +89 -0
  8. data/lib/sakai-cle-test-api/data_objects/lesson.rb +185 -0
  9. data/lib/sakai-cle-test-api/data_objects/resource.rb +209 -0
  10. data/lib/sakai-cle-test-api/data_objects/site.rb +208 -0
  11. data/lib/sakai-cle-test-api/data_objects/syllabus.rb +39 -0
  12. data/lib/sakai-cle-test-api/data_objects/web_content_tool.rb +51 -0
  13. data/lib/sakai-cle-test-api/data_objects/wiki.rb +53 -0
  14. data/lib/sakai-cle-test-api/gem_ext.rb +23 -0
  15. data/lib/sakai-cle-test-api/page_helper.rb +22 -0
  16. data/lib/sakai-cle-test-api/page_maker.rb +48 -0
  17. data/lib/sakai-cle-test-api/page_objects/account.rb +111 -0
  18. data/lib/sakai-cle-test-api/page_objects/aliases.rb +43 -0
  19. data/lib/sakai-cle-test-api/page_objects/announcements.rb +190 -0
  20. data/lib/sakai-cle-test-api/page_objects/assessments.rb +874 -0
  21. data/lib/sakai-cle-test-api/page_objects/assignments.rb +771 -0
  22. data/lib/sakai-cle-test-api/page_objects/basic_lti.rb +6 -0
  23. data/lib/sakai-cle-test-api/page_objects/blogger.rb +205 -0
  24. data/lib/sakai-cle-test-api/page_objects/blogs.rb +60 -0
  25. data/lib/sakai-cle-test-api/page_objects/calendar.rb +431 -0
  26. data/lib/sakai-cle-test-api/page_objects/calendar_summary.rb +1 -0
  27. data/lib/sakai-cle-test-api/page_objects/chat_room.rb +12 -0
  28. data/lib/sakai-cle-test-api/page_objects/drop_box.rb +9 -0
  29. data/lib/sakai-cle-test-api/page_objects/email_archive.rb +22 -0
  30. data/lib/sakai-cle-test-api/page_objects/evaluations.rb +158 -0
  31. data/lib/sakai-cle-test-api/page_objects/feedback.rb +36 -0
  32. data/lib/sakai-cle-test-api/page_objects/forms.rb +120 -0
  33. data/lib/sakai-cle-test-api/page_objects/forums.rb +289 -0
  34. data/lib/sakai-cle-test-api/page_objects/glossary.rb +117 -0
  35. data/lib/sakai-cle-test-api/page_objects/gradebook.rb +29 -0
  36. data/lib/sakai-cle-test-api/page_objects/gradebook2.rb +17 -0
  37. data/lib/sakai-cle-test-api/page_objects/home.rb +36 -0
  38. data/lib/sakai-cle-test-api/page_objects/jforums.rb +444 -0
  39. data/lib/sakai-cle-test-api/page_objects/job_scheduler.rb +121 -0
  40. data/lib/sakai-cle-test-api/page_objects/lessons.rb +360 -0
  41. data/lib/sakai-cle-test-api/page_objects/login.rb +28 -0
  42. data/lib/sakai-cle-test-api/page_objects/matrix.rb +241 -0
  43. data/lib/sakai-cle-test-api/page_objects/media_gallery.rb +13 -0
  44. data/lib/sakai-cle-test-api/page_objects/messages.rb +622 -0
  45. data/lib/sakai-cle-test-api/page_objects/my_workspace.rb +44 -0
  46. data/lib/sakai-cle-test-api/page_objects/news.rb +8 -0
  47. data/lib/sakai-cle-test-api/page_objects/podcasts.rb +27 -0
  48. data/lib/sakai-cle-test-api/page_objects/polls.rb +69 -0
  49. data/lib/sakai-cle-test-api/page_objects/portfolio_templates.rb +161 -0
  50. data/lib/sakai-cle-test-api/page_objects/portfolios.rb +162 -0
  51. data/lib/sakai-cle-test-api/page_objects/post_em.rb +1 -0
  52. data/lib/sakai-cle-test-api/page_objects/profile.rb +51 -0
  53. data/lib/sakai-cle-test-api/page_objects/profile2.rb +344 -0
  54. data/lib/sakai-cle-test-api/page_objects/public_search.rb +61 -0
  55. data/lib/sakai-cle-test-api/page_objects/realms.rb +19 -0
  56. data/lib/sakai-cle-test-api/page_objects/resources.rb +326 -0
  57. data/lib/sakai-cle-test-api/{resources_roster.rb → page_objects/resources_roster.rb} +0 -0
  58. data/lib/sakai-cle-test-api/page_objects/rosters.rb +70 -0
  59. data/lib/sakai-cle-test-api/page_objects/rwiki.rb +34 -0
  60. data/lib/sakai-cle-test-api/page_objects/search.rb +34 -0
  61. data/lib/sakai-cle-test-api/page_objects/sections.rb +295 -0
  62. data/lib/sakai-cle-test-api/page_objects/single_user.rb +1 -0
  63. data/lib/sakai-cle-test-api/page_objects/site_setup.rb +686 -0
  64. data/lib/sakai-cle-test-api/page_objects/site_statistics.rb +1 -0
  65. data/lib/sakai-cle-test-api/page_objects/sites.rb +255 -0
  66. data/lib/sakai-cle-test-api/page_objects/styles.rb +74 -0
  67. data/lib/sakai-cle-test-api/page_objects/syllabus.rb +166 -0
  68. data/lib/sakai-cle-test-api/page_objects/user_membership.rb +57 -0
  69. data/lib/sakai-cle-test-api/page_objects/users.rb +88 -0
  70. data/lib/sakai-cle-test-api/rich_text.rb +27 -0
  71. data/lib/sakai-cle-test-api/utilities.rb +260 -0
  72. data/lib/sakai-cle-test-api/workflows.rb +224 -0
  73. data/sakai-cle-test-api.gemspec +3 -5
  74. metadata +74 -64
  75. data/lib/sakai-cle-test-api/admin_page_elements.rb +0 -1030
  76. data/lib/sakai-cle-test-api/announcements.rb +0 -59
  77. data/lib/sakai-cle-test-api/assessments.rb +0 -194
  78. data/lib/sakai-cle-test-api/assignments.rb +0 -113
  79. data/lib/sakai-cle-test-api/basic_lti.rb +0 -5
  80. data/lib/sakai-cle-test-api/blogs.rb +0 -5
  81. data/lib/sakai-cle-test-api/calendar.rb +0 -65
  82. data/lib/sakai-cle-test-api/calendar_summary.rb +0 -0
  83. data/lib/sakai-cle-test-api/common_page_elements.rb +0 -1228
  84. data/lib/sakai-cle-test-api/drop_box.rb +0 -0
  85. data/lib/sakai-cle-test-api/email_archive.rb +0 -10
  86. data/lib/sakai-cle-test-api/forums.rb +0 -39
  87. data/lib/sakai-cle-test-api/gradebook.rb +0 -10
  88. data/lib/sakai-cle-test-api/gradebook2.rb +0 -6
  89. data/lib/sakai-cle-test-api/messages.rb +0 -119
  90. data/lib/sakai-cle-test-api/news.rb +0 -9
  91. data/lib/sakai-cle-test-api/polls.rb +0 -24
  92. data/lib/sakai-cle-test-api/post_em.rb +0 -0
  93. data/lib/sakai-cle-test-api/profile.rb +0 -17
  94. data/lib/sakai-cle-test-api/profile2.rb +0 -43
  95. data/lib/sakai-cle-test-api/rwiki.rb +0 -0
  96. data/lib/sakai-cle-test-api/sections.rb +0 -47
  97. data/lib/sakai-cle-test-api/single_user.rb +0 -0
  98. data/lib/sakai-cle-test-api/site_page_elements.rb +0 -2350
  99. data/lib/sakai-cle-test-api/site_statistics.rb +0 -0
  100. data/lib/sakai-cle-test-api/syllabus.rb +0 -77
  101. data/lib/sakai-cle-test-api/tools_menu.rb +0 -415
@@ -1,9 +1,9 @@
1
1
  require 'cgi'
2
- require 'kuali-sakai-common-lib'
3
- require 'sakai-cle-test-api/utilities'
4
- require 'sakai-cle-test-api/tools_menu'
5
- require 'sakai-cle-test-api/admin_page_elements'
2
+ require 'watir-webdriver'
3
+ require 'sakai-cle-test-api/page_maker.rb'
6
4
  Dir["#{File.dirname(__FILE__)}/sakai-cle-test-api/*.rb"].each {|f| require f }
5
+ Dir["#{File.dirname(__FILE__)}/sakai-cle-test-api/page_objects/*.rb"].each {|f| require f }
6
+ Dir["#{File.dirname(__FILE__)}/sakai-cle-test-api/data_objects/*.rb"].each {|f| require f }
7
7
 
8
8
  # Initialize this class at the start of your test cases to
9
9
  # open the specified test browser at the specified Sakai welcome page URL.
@@ -21,7 +21,6 @@ class SakaiCLE
21
21
  @browser = Watir::Browser.new web_browser
22
22
  @browser.window.resize_to(1400,900)
23
23
  @browser.goto url
24
- $frame_index = 0 # TODO - Need to remove this and all dependent code.
25
24
  end
26
25
 
27
26
  # Returns the class containing the welcome page's page elements.
@@ -0,0 +1,20 @@
1
+ class BasePage < PageMaker
2
+
3
+ class << self
4
+
5
+ def frame_element
6
+ element(:frm) { |b| b.frame(:class=>"portletMainIframe") }
7
+ end
8
+
9
+ def basic_page_elements
10
+ # Returns the text of the error message box
11
+ value(:alert_box) { |b| b.frm.div(:class=>"alertMessage").text }
12
+ # Returns the text of the header.
13
+ value(:header) { |b| b.frm.div(:class=>"portletBody").h3.text }
14
+ end
15
+
16
+ # More element group defs go here...
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,90 @@
1
+ class Time
2
+
3
+ # Using the :year_range option (or no option), this method creates a
4
+ # Time object of a random value, within
5
+ # the year range specified (default is 5 years in the past).
6
+ #
7
+ # Using the :series option, this method returns an array
8
+ # containing a randomized Time object as its first element (limited by
9
+ # the specified :year_range value). Subsequent elements will be Time objects
10
+ # with values putting them later than the prior element, within the specified
11
+ # range value (see examples).
12
+ #
13
+ # Usage Examples:
14
+ # @example
15
+ # a random date...
16
+ # ?> Time.random
17
+ # => Tue Aug 05 00:00:00 EDT 2007
18
+ #
19
+ # birthdays, anyone?...
20
+ # 5.times { p Time.random(:year_range=>80) }
21
+ # Wed Feb 06 00:00:00 EDT 1974
22
+ # Tue Dec 22 00:00:00 EST 1992
23
+ # Fri Apr 14 00:00:00 EWT 1944
24
+ # Thu Jul 01 00:00:00 EDT 1993
25
+ # Wed Oct 02 00:00:00 EDT 2002
26
+ #
27
+ # A series of dates are useful for account-related info...
28
+ # ?> Time.random(:series=>[20.days, 3.years])
29
+ # => [Sat Jan 22 00:00:00 EST 2005,
30
+ # Sat Jan 29 12:58:45 EST 2005,
31
+ # Fri Sep 08 09:34:58 EDT 2006]
32
+ #
33
+ # or maybe to simulate events during an hour?...
34
+ # ?> Time.random(:series=>[1.hour,1.hour,1.hour])
35
+ # => [Wed Apr 21 00:00:00 EDT 2004,
36
+ # Wed Apr 21 00:45:59 EDT 2004,
37
+ # Wed Apr 21 01:02:47 EDT 2004,
38
+ # Wed Apr 21 01:31:00 EDT 2004]
39
+ def self.random(params={})
40
+ years_back = params[:year_range] || 5
41
+ year = (rand * (years_back)).ceil + (Time.now.year - years_back)
42
+ month = (rand * 12).ceil
43
+ day = (rand * 31).ceil
44
+ series = [date = Time.local(year, month, day)]
45
+ if params[:series]
46
+ params[:series].each do |some_time_after|
47
+ series << series.last + (rand * some_time_after).ceil
48
+ end
49
+ return series
50
+ end
51
+ date
52
+ end
53
+
54
+ end # Time
55
+
56
+ module Enumerable
57
+
58
+ # Use for getting a natural sort order instead of the ASCII
59
+ # sort order.
60
+ def alphabetize
61
+ sort { |a, b| grouped_compare(a, b) }
62
+ end
63
+
64
+ # Use for sorting an Enumerable object in place.
65
+ def alphabetize!
66
+ sort! { |a, b| grouped_compare(a, b) }
67
+ end
68
+
69
+ private
70
+ def grouped_compare(a, b)
71
+ loop {
72
+ a_chunk, a = extract_alpha_or_number_group(a)
73
+ b_chunk, b = extract_alpha_or_number_group(b)
74
+ ret = a_chunk <=> b_chunk
75
+ return -1 if a_chunk == ''
76
+ return ret if ret != 0
77
+ }
78
+ end
79
+
80
+ def extract_alpha_or_number_group(item)
81
+ test_item = item.downcase
82
+ matchdata = /([a-z]+|[\d]+)/.match(test_item)
83
+ if matchdata.nil?
84
+ ["", ""]
85
+ else
86
+ [matchdata[0], test_item = test_item[matchdata.offset(0)[1] .. -1]]
87
+ end
88
+ end
89
+
90
+ end # Enumerable
@@ -0,0 +1,81 @@
1
+ class AnnouncementObject
2
+
3
+ include Utilities
4
+ include PageHelper
5
+ include Workflows
6
+
7
+ attr_accessor :title, :body, :site, :link, :access, :availability,
8
+ :subject, :saved_by, :date, :creation_date, :groups,
9
+ :message, :message_html
10
+
11
+ def initialize(browser, opts={})
12
+ @browser = browser
13
+
14
+ defaults = {
15
+ :title=>random_alphanums,
16
+ :body=>random_multiline(500, 10, :alpha)
17
+ }
18
+ options = defaults.merge(opts)
19
+ @title=options[:title]
20
+ @body=options[:body]
21
+ @site=options[:site]
22
+ raise "You must specify a Site for the announcement" if @site==nil
23
+ end
24
+
25
+ alias :name :title
26
+
27
+ def create
28
+ open_my_site_by_name @site unless @browser.title=~/#{@site}/
29
+ announcements unless @browser.title=~/Announcements$/
30
+ on_page Announcements do |page|
31
+ page.add
32
+ end
33
+ on_page AddEditAnnouncements do |page|
34
+ page.title.set @title
35
+ page.enter_source_text page.editor, @body
36
+ page.add_announcement
37
+ @creation_date=make_date Time.now
38
+ end
39
+ on_page Announcements do |page|
40
+ @link = page.href(@title)
41
+ end
42
+ end
43
+
44
+ def edit opts={}
45
+ open_my_site_by_name @site unless @browser.title=~/#{@site}/
46
+ announcements unless @browser.title=~/Announcements$/
47
+ on_page Announcements do |list|
48
+ list.edit @title
49
+ end
50
+ on AddEditAnnouncements do |edit|
51
+ edit.title.set opts[:title] unless opts[:title]==nil
52
+ edit.send(opts[:access]) unless opts[:access]==nil
53
+ edit.send(opts[:availability]) unless opts[:availability]==nil
54
+ unless opts[:body]==nil
55
+ edit.enter_source_text edit.editor, opts[:body]
56
+ end
57
+ edit.save_changes
58
+ end
59
+ @title=opts[:title] unless opts[:title]==nil
60
+ @body=opts[:body] unless opts[:body]==nil
61
+ @access=opts[:access]
62
+ @availability=opts[:availability]
63
+ end
64
+
65
+ def view
66
+ open_my_site_by_name @site unless @browser.title=~/#{@site}/
67
+ announcements unless @browser.title=~/Announcements$/
68
+ on Announcements do |list|
69
+ list.view @title
70
+ end
71
+ on ViewAnnouncement do |view|
72
+ @subject=view.subject
73
+ @saved_by=view.saved_by
74
+ @date=view.date
75
+ @groups=view.groups
76
+ @message=view.message
77
+ @message_html=view.message_html
78
+ end
79
+ end
80
+
81
+ end
@@ -0,0 +1,32 @@
1
+ class AssessmentObject
2
+
3
+ include PageHelper
4
+ include Utilities
5
+ include Workflows
6
+
7
+ attr_accessor :title, :site
8
+
9
+ def initialize(browser, opts={})
10
+ @browser = browser
11
+
12
+ defaults = {
13
+ :title=>random_alphanums,
14
+ :site=>"placeholder"
15
+ }
16
+ options = defaults.merge(opts)
17
+ @title=options[:title]
18
+ @site=options[:site]
19
+ raise "You must specify a Site for your Assessment" if @site==nil
20
+ end
21
+
22
+ def create
23
+ my_workspace.open_my_site_by_name @site unless @browser.title=~/#{@site}/
24
+ tests_and_quizzes unless @browser.title=~/Tests & Quizzes$/
25
+ on_page AssessmentsList do |page|
26
+ page.title.set @title
27
+ page.create
28
+ end
29
+ # Do more here eventually...
30
+ end
31
+
32
+ end
@@ -0,0 +1,90 @@
1
+ class AssignmentObject
2
+
3
+ include PageHelper
4
+ include Utilities
5
+ include Workflows
6
+
7
+ attr_accessor :title, :site, :instructions, :id, :link, :status
8
+
9
+ def initialize(browser, opts={})
10
+ @browser = browser
11
+
12
+ defaults = {
13
+ :title=>random_alphanums,
14
+ :instructions=>random_multiline(250, 10, :string)
15
+ }
16
+ options = defaults.merge(opts)
17
+
18
+ @title=options[:title]
19
+ @instructions=options[:instructions]
20
+ @site=options[:site]
21
+ raise "You must specify a Site for your Assignment" if @site==nil
22
+ end
23
+
24
+ alias :name :title
25
+
26
+ def create
27
+ open_my_site_by_name @site unless @browser.title=~/#{@site}/
28
+
29
+ # Go to assignments page
30
+ assignments unless @browser.title=~/Assignments$/
31
+
32
+ on_page AssignmentsList do |page|
33
+ page.add
34
+ end
35
+ on_page AssignmentAdd do |add|
36
+ add.title.set @title
37
+ add.instructions=@instructions
38
+ add.post
39
+ end
40
+ on_page AssignmentsList do |list|
41
+ @id = list.get_assignment_id @title
42
+ @link = list.assignment_href @title
43
+ @status = list.status_of @title
44
+ end
45
+ end
46
+
47
+ def edit opts={}
48
+ open_my_site_by_name @site unless @browser.title=~/#{@site}/
49
+ assignments unless @browser.title=~/Assignments$/
50
+ on AssignmentsList do |list|
51
+ if @status=="Draft"
52
+ list.edit_assignment "Draft - #{@title}"
53
+ else
54
+ list.edit_assignment @title
55
+ end
56
+ end
57
+ on AssignmentAdd do |edit|
58
+ edit.title.set opts[:title] unless opts[:title] == nil
59
+ unless opts[:instructions] == nil
60
+ edit.enter_source_text edit.editor, opts[:instructions]
61
+ end
62
+ edit.post
63
+ end
64
+ @title=opts[:title] unless opts[:title] == nil
65
+ @instructions=opts[:instructions] unless opts[:instructions] == nil
66
+ on AssignmentsList do |list|
67
+ @status=list.status_of @title
68
+ end
69
+ end
70
+
71
+ def get_assignment_info
72
+ open_my_site_by_name @site unless @browser.title=~/#{@site}/
73
+ assignments unless @browser.title=~/Assignments$/
74
+ on AssignmentsList do |list|
75
+ @id = list.get_assignment_id @title
76
+ @status=list.status_of @title
77
+ @link=list.assignment_href @title
78
+ if @status=="Draft"
79
+ list.open_assignment "Draft - #{@title}"
80
+ else
81
+ list.open_assignment @title
82
+ end
83
+ end
84
+ on AssignmentAdd do |edit|
85
+ # TODO: Need to add more stuff here as needed...
86
+ @instructions=edit.get_source_text edit.editor
87
+ end
88
+ end
89
+
90
+ end
@@ -0,0 +1,89 @@
1
+ class EventObject
2
+
3
+ include PageHelper
4
+ include Utilities
5
+ include Workflows
6
+
7
+ attr_accessor :title, :month, :day, :year, :start_hour, :start_minute,
8
+ :start_meridian, :duration_hours, :duration_minutes, :end_hour,
9
+ :end_minute, :end_meridian, :message, :site, :link
10
+
11
+ def initialize(browser, opts={})
12
+ @browser = browser
13
+
14
+ defaults = {
15
+ :title=>random_alphanums,
16
+ :month=>in_15_minutes[:month_str],
17
+ :day=>in_15_minutes[:day],
18
+ :year=>in_15_minutes[:year],
19
+ :start_hour=>in_15_minutes[:hour],
20
+ :start_minute=>in_15_minutes[:minute],
21
+ :start_meridian=>in_15_minutes[:meridian],
22
+ :duration_hours=>nil,
23
+ :duration_minutes=>nil,
24
+ :end_hour=>nil,
25
+ :end_minute=>nil,
26
+ :end_meridian=>nil,
27
+ :message=>random_multiline(400,20, :alpha),
28
+ :site=>"placeholder"
29
+ }
30
+ options = defaults.merge(opts)
31
+
32
+ @title=options[:title]
33
+ @month=options[:month]
34
+ @day=options[:day]
35
+ @year=options[:year]
36
+ @start_hour=options[:start_hour]
37
+ @start_minute=options[:start_minute]
38
+ @start_meridian=options[:start_meridian]
39
+ @duration_hours=options[:duration_hours]
40
+ @duration_minutes=options[:duration_minutes]
41
+ @end_hour=options[:end_hour]
42
+ @end_minute=options[:end_minute]
43
+ @end_meridian=options[:end_meridian]
44
+ @message=options[:message]
45
+ @site=options[:site]
46
+
47
+ end
48
+
49
+ def create
50
+ open_my_site_by_name @site unless @browser.title=~/#{@site}/
51
+ calendar unless @browser.title=~/Calendar$/
52
+ on Calendar do |cal|
53
+ cal.add
54
+ end
55
+ on AddEditEvent do |add_event|
56
+ add_event.message.set @message
57
+ add_event.title.set @title
58
+ add_event.month.select @month
59
+ add_event.day.select @day
60
+ add_event.year.select @year
61
+ add_event.start_hour.select @start_hour
62
+ add_event.start_minute.select @start_minute
63
+ add_event.start_meridian.select @start_meridian
64
+ if @end_hour == nil && @duration_hours == nil
65
+ @duration_hours = add_event.hours.value
66
+ @duration_minutes = add_event.minutes.value
67
+ @end_hour = add_event.end_hour.value
68
+ @end_minute = add_event.end_minute.value
69
+ @end_meridian = add_event.end_meridian.value
70
+ elsif @end_hour == nil
71
+ add_event.hours.select @duration_hours
72
+ add_event.minutes.select @duration_minutes
73
+ @end_hour = add_event.end_hour.value
74
+ @end_minute = add_event.end_minute.value
75
+ @end_meridian = add_event.end_meridian.value
76
+ elsif @duration_hours == nil
77
+
78
+ else
79
+
80
+ end
81
+
82
+ add_event.save_event
83
+ end
84
+ on Calendar do |cal|
85
+ @link = cal.event_href @title
86
+ end
87
+ end
88
+
89
+ end
@@ -0,0 +1,185 @@
1
+ class ModuleObject
2
+
3
+ include PageHelper
4
+ include Utilities
5
+ include Workflows
6
+
7
+ attr_accessor :title, :description, :keywords, :start_date, :end_date, :site, :href
8
+
9
+ def initialize(browser, opts={})
10
+ @browser = browser
11
+
12
+ defaults = {
13
+ :title=>random_alphanums
14
+ }
15
+ options = defaults.merge(opts)
16
+
17
+ @title=options[:title]
18
+ @description=options[:description]
19
+ @keywords=options[:keywords]
20
+ @start_date=options[:start_date]
21
+ @end_date=options[:end_date]
22
+ @site=options[:site]
23
+ raise "You must specify a Site name for your lesson" if @site==nil
24
+ end
25
+
26
+ alias :name :title
27
+
28
+ def create
29
+ open_my_site_by_name @site unless @browser.title=~/#{@site}/
30
+ lessons unless @browser.title=~/Lessons$/
31
+ reset
32
+ on_page Lessons do |page|
33
+ page.add_module
34
+ end
35
+ on_page AddEditModule do |page|
36
+ page.title.set @title
37
+ page.description.set @description
38
+ page.keywords.set @keywords
39
+ page.start_date.set @start_date
40
+ page.end_date.set @end_date
41
+ page.add
42
+ end
43
+ on_page ConfirmModule do |page|
44
+ page.return_to_modules
45
+ end
46
+ on_page Lessons do |list|
47
+ @href = list.href @title
48
+ end
49
+ end
50
+
51
+ end
52
+
53
+ class ContentSectionObject
54
+
55
+ include PageHelper
56
+ include Utilities
57
+ include Workflows
58
+
59
+ attr_accessor :site, :module, :title, :instructions, :modality, :content_type,
60
+ :copyright_status, :editor_content, :file_folder, :file_name, :file_path,
61
+ :url, :url_title, :file_description, :url_description, :href
62
+
63
+ def initialize(browser, opts={})
64
+ @browser = browser
65
+
66
+ defaults = {
67
+ :title=>random_alphanums,
68
+ :copyright_status=>"Public Domain",
69
+ :modality=>[:check_textual]
70
+ }
71
+ options = defaults.merge(opts)
72
+
73
+ @site=options[:site]
74
+ @module=options[:module]
75
+ @title=options[:title]
76
+ @instructions=options[:instructions]
77
+ @modality=options[:modality]
78
+ @content_type=options[:content_type]
79
+ @copyright_status=options[:copyright_status]
80
+ @editor_content=options[:editor_content]
81
+ @file_name=options[:file_name]
82
+ @file_path=options[:file_path]
83
+ @file_description=options[:file_description]
84
+ @file_folder=options[:file_folder]
85
+ @url=options[:url]
86
+ @url_title=options[:url_title]
87
+ @url_description=options[:url_description]
88
+ raise "Your modality variable must be an Array containing one or more keys\nthat match the checkbox methods, like this:\n[:uncheck_textual, :check_visual, :check_auditory]" unless @modality.class==Array
89
+ raise "You must specify a Site for your Section" if @site==nil
90
+ raise "You must specify a Module for your Section" if @module==nil
91
+ end
92
+
93
+ alias :name :title
94
+
95
+ def create
96
+ open_my_site_by_name @site unless @browser.title=~/#{@site}/
97
+ lessons unless @browser.title=~/Lessons$/
98
+ reset
99
+ on_page Lessons do |page|
100
+ page.open_lesson @module
101
+ end
102
+ on_page AddEditModule do |page|
103
+ page.add_content_sections
104
+ end
105
+ on_page AddEditContentSection do |page|
106
+ page.title.set @title
107
+ page.instructions.set @instructions
108
+ @modality.each do |content|
109
+ page.send(content)
110
+ end
111
+ page.content_type.select @content_type unless @content_type==nil
112
+ end
113
+
114
+ on AddEditContentSection do |page| # Note we are reinstantiating the class here because of
115
+ # an issue with Selenium Webdriver throwing a
116
+ # WeakReference error, given the partial page reload.
117
+ case @content_type
118
+ when "Compose content with editor"
119
+ page.enter_source_text page.content_editor, @editor_content
120
+ when "Upload or link to a file"
121
+ page.select_a_file
122
+ on_page LessonAddAttachment do |add|
123
+ add.upload_local_file @file_name, @file_path
124
+ add.continue
125
+ end
126
+ page.file_description.set @file_description
127
+ when "Link to new or existing URL resource on server"
128
+ page.select_url
129
+ on_page SelectingContent do |select|
130
+ select.new_url.set @url
131
+ select.url_title.set @url_title
132
+ select.continue
133
+ end
134
+ page.url_description.set @url_description
135
+ when "Upload or link to a file in Resources"
136
+ page.select_or_upload_file
137
+ on_page ResourcesBase do |add|
138
+ add.open_folder @file_folder unless @file_folder == nil
139
+ add.select_file @file_name
140
+ add.continue
141
+ end
142
+ else
143
+ raise "You have a typo in what you've specified for your Section's content type.\nIt must be one of the options contained in the dropdown."
144
+ end
145
+ page.copyright_status.select @copyright_status
146
+ page.add
147
+ end
148
+ on ConfirmSectionAdd do |confirm|
149
+ confirm.finish
150
+ end
151
+ on Lessons do |list|
152
+ @href = list.href @title
153
+ end
154
+ end
155
+
156
+ def edit opts={}
157
+ open_my_site_by_name @site unless @browser.title=~/#{@site}/
158
+ lessons unless @browser.title=~/Lessons$/
159
+ reset
160
+ on Lessons do |list|
161
+ list.check_section @title
162
+ list.edit
163
+ end
164
+ on AddEditContentSection do |edit|
165
+ edit.title.set opts[:title] unless opts[:title]==nil
166
+ edit.instructions.set opts[:instructions] unless opts[:instructions]==nil
167
+ if opts[:modality].class==Array
168
+ opts[:modality].each do |item|
169
+ edit.send(item)
170
+ end
171
+ end
172
+
173
+ # TODO: Add code here for updating attached resources
174
+
175
+ edit.enter_source_text(edit.content_editor, opts[:editor_content]) unless opts[:editor_content]==nil
176
+
177
+ # TODO: Add code here for updating remaining variables
178
+
179
+ edit.finish
180
+ end
181
+ @title=opts[:title] unless opts[:title]==nil
182
+ @instructions=opts[:instructions] unless opts[:instructions]==nil
183
+ @modality=opts[:modality] unless opts[:modality]==nil
184
+ end
185
+ end