#---------------------------------------------------------------------------------
# Etime web load testing using WATIR and RUBY
#---------------------------------------------------------------------------------
require 'watir'   # the watir controller

#initialize variable
linesPerPage = 10
lineCounter = 1

test_site            = 'HTTPS://WEBSITEADDRESS'
paySchedule          = 'MM/DD/YYYY - @@@@@@@@@@@@@@@@@@@@@@@'
formType             = '@@@@@@@@@@'
formCUC              = '#####'
totalEmployee        =  ## 
transactionCodeValue = '@@'
payEndDateValue      = 'MM/DD/YYYY'
earningTypeValue     = '@@@'
jobClassValue        = '######'
jobAccountValue      = '######'
commentText          = 'Comment #' 

ie = Watir::IE.start(test_site)

# SSL Login Page
ie.text_field(:index, 1).set('LOGINNAME')
ie.text_field(:index, 2).set('PASSWORD')
ie.button(:value, "Login").click

#Form Create
ie.radio(:name, 'creation', 'N').set
ie.select_list(:name, 'schedule1').select(paySchedule)
ie.select_list(:name, 'cuc').select(formCUC)
ie.select_list(:name,'type').select(formType)
ie.button(:value, "Create New Form").click

#Select Employees to Pay
if totalEmployee > 25
	i = 1
	while i <= (totalEmployee % 25.to_f)
		empCount = empCount + ie.checkboxes.length
   	        ie.button(:value, "Select All-This Page").click

		if i < (totalEmployee % 25)
   				ie.button(:value, 'Next >>').click
		end
		i = i + 1
	end
else
	empCount = ie.checkboxes.length
   	ie.button(:value, "Select All-This Page").click
end
ie.button(:value, "Go Create Form").click

#Put details on each employee's transaction
#For each employee transaction there are 7 input boxes
# 6 drop downs and 1 check box
# and webpage displays 10 records per page
while lineCounter <= empCount
	strLineCounter  = lineCounter.to_s
	transactionCode = 'trans_'        + strLineCounter
	payEndDate      = 'enddate_'      + strLineCounter
	earningType1    = 'EarningType1_' + strLineCounter
	hours1    	= 'Hours1_'       + strLineCounter
	jobClass        = 'jobClass_'     + strLineCounter
	jobAccount	= 'jobAccount_'   + strLineCounter
	comments	= 'Comments_'     + strLineCounter

	ie.select_list(:name, transactionCode).select(transactionCodeValue)
	ie.select_list(:name, payEndDate).select(payEndDateValue)
	ie.select_list(:name, earningType1).select(earningTypeValue)
   	ie.text_field(:name, hours1).set(strLineCounter)
	ie.text_field(:name, jobClass).set(jobClassValue)
	ie.select_list(:name, jobAccount).select(jobAccountValue)
	ie.text_field(:name, comments).set(commentText + strLineCounter)

	if lineCounter == linesPerPage
		linesPerPage = linesPerPage + 10
   			ie.button(:value, 'Next >>').click
	end
	lineCounter = lineCounter + 1
end

   	ie.button(:value, "Submit Form").click
ie.close()

# -end of simple Google search test
