Skip to content

Instantly share code, notes, and snippets.

@jkwaldrip
Created June 24, 2013 15:21
Show Gist options
  • Save jkwaldrip/5850838 to your computer and use it in GitHub Desktop.
Save jkwaldrip/5850838 to your computer and use it in GitHub Desktop.
OLE Staff Uploader - A quick-and-easy test to perform X staff uploads end-to-end. Run in multiple instances for easy scale testing of the Staff Upload function for paired Marc/EDI EOCR records. (Requires ./data/ to contain paired .mrc/.edi records; uses ole-qa-framework 1.0.0+ )
#!/usr/bin/env ruby
#
# Upload x paired Marc/EDI order files. Used for scale testing of Staff Upload function.
#
# Copyright 2005-2013 The Kuali Foundation
#
# Licensed under the Educational Community License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
# http://www.opensource.org/licenses/ecl2.php
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require 'ole-qa-framework'
working_dir = File.expand_path(File.dirname(__FILE__))
$LOAD_PATH.unshift(working_dir) unless $LOAD_PATH.include?(working_dir)
if ARGV.empty?
x = 1
else
x = ARGV[0].to_i
end
puts "Starting OLE session..."
$ole = OLE_QA::Framework.new(:headless? => true, :explicit_wait => 10)
puts "...done!"
class UploadPage < OLE_QA::Page
include OLE_QA::Helpers
include OLE_QA::Data_Helpers
def initialize
ole_session = $ole
url = $ole.fs_url + 'portal.do?channelTitle=Staff Upload&channelUrl=' + $ole.ls_url + 'kr-krad/'\
+ 'staffuploadcontroller?viewId=StaffUploadView&methodToCall=start&__login_user=admin&user=ole-khuntley'
super(ole_session, url)
end
def set_elements
element(:title) {browser.h1(:class => 'uif-headerText').span}
element(:marc_field) {browser.input(:id => "StaffUploadView-marcFileUpload_control").to_subtype}
element(:edi_field) {browser.input(:id => "StaffUploadView-ediFileUpload_control").to_subtype}
element(:profile_selector) {browser.select_list(:id => "StaffUploadView-agenda_control")}
element(:description_field) {browser.input(:id => "StaffUploadView-agendaDescription_control").to_subtype}
element(:upload_button) {browser.button(:id => "uploadButton")}
element(:cancel_button) {browser.button(:id => "cancelButton")}
element(:load_reports_button) {browser.button(:id => "loadReportsButton")}
end
def wait_for_elements
@wait_on << :title
super
end
end
# Get the names of all and only the Marc files in the data directory.
# Strip the extensions from the end, and then we have an array of bare filenames.
@files = Dir.glob("./data/*.mrc")
@files.each do |filename|
ind = @files.index(filename)
filename.to_s.gsub!('.mrc','')
@files[ind] = filename
end
def pick_one
bare_name = @files.sample
bare_name
@files.delete(bare_name)
end
upload_page = UploadPage.new
puts "Beginning #{x} uploads..."
i = 1
x.times do
bare_file = pick_one
target_file = File.expand_path(bare_file)
description = "Test - #{bare_file.gsub(/\.\/data\//,'')} - #{Time.now}"
puts "#{i}. #{target_file} (#{description})"
upload_page.open
upload_page.marc_field.set("#{target_file}.mrc")
upload_page.edi_field.wait_until_present
upload_page.edi_field.set("#{target_file}.edi")
upload_page.profile_selector.wait_until_present
upload_page.profile_selector.select("YBP")
upload_page.description_field.wait_until_present
upload_page.description_field.set(description)
upload_page.upload_button.click
upload_page.wait_for_page_to_load
upload_page.browser.div(:id => "MessageFieldSection").span(:text => /executed successfully/).wait_until_present
$ole.browser.goto($ole.base_url)
i += 1
end
puts "...done!"
puts "Quitting OLE session..."
$ole.quit
puts "...done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment