diff --git a/tests/constants.rb b/tests/constants.rb new file mode 100644 index 0000000..e897e83 --- /dev/null +++ b/tests/constants.rb @@ -0,0 +1,53 @@ +# +#This file contains all the constants required for all tests +#require this file if you are writing a standalone test. +# + +#Database Constants +#DBUSERNAME='eft_nom_kingdonj' +#DBPASSWORD='eft_nom_kingdonj' +DBUSERNAME='mip_dev_e' +DBPASSWORD='mip_dev_e' +#DATABASE='dev10g' +# Screen Constants +#MACHINE='wxp0113' +MACHINE = 'loordv01' +#MACHINE = '195.228.69.35' +#DAD='eftnomfat' +DAD= 'pls/apex' +#DAD= 'eftnom' +#DAD= 'pls/eftnomkingdonj' +#PROTOCOL = 'https://' +PROTOCOL = 'http://' + +# +# Default Screen urls +# +START_URL = PROTOCOL+MACHINE+'/'+DAD+'/f?p=156:1:380279258624897:::::' +LOGIN = PROTOCOL+MACHINE+'/'+DAD+'/f?p=156:1' +EXPORT_DATA = PROTOCOL+MACHINE+'/'+DAD+'/f?p=156:5' + +# +# Users required for the script +# may need to add more as the integration tests grow +# +JAMIE = 'priestj' +JAMIE_PWD = 'password' +AGENT = 'testagent' +AGENT_PWD = 'testagent' +SUPP = 'testagent' +SUPP_PWD = 'testagent' +SUPPADMIN = 'testagent' +SUPPADMIN_PWD = 'testagent' +MIPADMIN = 'testagent' +MIPADMIN_PWD = 'testagent' +ICU = 'testagent' +ICU_PWD = 'testagent' +CS = 'testagent' +CS_PWD = 'testagent' +INORG = 'testagent' +INORG_PWD = 'testagent' +EXTORG = 'testagent' +EXTORG_PWD = 'testagent' +MEMBER = 'testagent' +MEMBER_PWD = 'testagent' \ No newline at end of file diff --git a/tests/default_methods.rb b/tests/default_methods.rb new file mode 100644 index 0000000..2a5264f --- /dev/null +++ b/tests/default_methods.rb @@ -0,0 +1,344 @@ +# Oracle stuff +# +require 'oci8' +#used to handle javascript popups +require 'watir/contrib/enabled_popup' +require 'watir/WindowHelper' +# +# Method to handle javascript popups. +# +require 'thread' +# +require 'win32ole' +# +def startClicker( button , waitTime = 3) + w = WinClicker.new + longName = @@ie.dir.gsub("/" , "\\" ) + shortName = w.getShortFileName(longName) + c = "start ruby #{shortName}\\watir\\clickJSDialog.rb #{button} #{waitTime} " + puts "Starting #{c}" + w.winsystem(c) + w=nil +end +# +# +# DOSQL +# +def dosql(p_sql) + conn = OCI8.new(DBUSERNAME,DBPASSWORD,DATABASE) + #conn.exec('begin DELETE_TEST_DATA; end;') + puts p_sql + conn.exec(p_sql) + #conn.exec('commit;') +end + +# +#LOGIN +# +def login(p_username, p_password) + # + # Enter logon details + # + @@ie.text_field( :id, 'P101_USERNAME' ).set( p_username ) + @@ie.text_field( :id, 'P101_PASSWORD' ).set( p_password ) + # + @@ie.button(:id, "login").click + @@ie.wait + # + # TRUE if doesn't find + # + assert_nil(@@ie.contains_text('Invalid Login Credentials'),'Unable to login') +end + +# +# SETCONTRACTVALUE +# +def set_contract_value(p_index_start,p_values) + # + i = p_index_start + @@ie.text_field( :index, i).set(p_values[0] ) + @@ie.text_field(:index, i+1).set(p_values[1]) + @@ie.text_field(:index, i+2).set(p_values[2]) + @@ie.text_field(:index, i+3).set(p_values[3]) + @@ie.text_field(:index, i+4).set(p_values[4]) + @@ie.text_field(:index, i+5).set(p_values[5]) + @@ie.text_field(:index, i+6).set(p_values[6]) + @@ie.text_field(:index, i+7).set(p_values[7]) + @@ie.text_field(:index, i+8).set(p_values[8]) + @@ie.text_field(:index, i+9).set(p_values[9]) + @@ie.text_field(:index, i+10).set(p_values[10]) + @@ie.text_field(:index, i+11).set(p_values[11]) + #@@ie.text_field(:index, i+12).set(p_values[12]) + # +end +# +# SETCONTRACT +# +def set_contract(p_name,p_customer,p_template,p_format,p_verify_data_entry,p_date_from=futuredate(0),p_date_to=futuredate(100),p_expect_success='y') + @@ie.button(:value, 'Find').click + @@ie.wait + @@ie.button(:value, 'New Contract').click + @@ie.wait + # + @@ie.text_field(:name,'p_contract_number').set(p_name) + @@ie.select_list(:name, 'p_customer_id').select(p_customer) + # + # + #get javascript popup, start thread before as popup locks ruby so can't click the button! + # + startClicker("OK" , 1) + #sleep 1 + @@ie.select_list(:name,'p_template_id').select(p_template) + # + # Will need to click the cutton manually if can't find a way to interact with the Javascript box + # + @@ie.select_list(:name,'p_spte_id').select(p_format) + @@ie.text_field(:name,'p_date_from').set(p_date_from) + @@ie.text_field(:name,'p_date_to').set(p_date_to) + @@ie.text_field(:name,'p_ops_contact').set('John') + @@ie.text_field(:name,'p_bus_contact').set('Paul') + @@ie.text_field(:name,'p_val_window').set('0') + @@ie.text_field(:name,'p_days_before').set('14') + @@ie.select_list(:name,'p_val_action').select('Look Back') + @@ie.select_list(:name,'p_status').select('Open') + @@ie.select_list(:name,'p_val_exception').select('Contracted Amount') + # + @@ie.select_list(:name,'add_nepo_id').select('EDEN HAG') + @@ie.select_list(:name,'add_nepo_id').select('EDEN TSTV') + @@ie.button(:value,'Add Network Points').click + @@ie.wait + @@ie.button('Insert').click + # + if p_expect_success=='y' + assert(@@ie.contains_text('Success!'),'Create Contract '+p_name+' did not succeed: ' +geterrormess(@@ie)) + else + assert(@@ie.contains_text('Insert failed'),'Create Contract '+p_name+' succeeded, should have given us an overlap error') + assert(@@ie.contains_text('Open contracts exist for this date period'),'Expected error message: [Open contracts exist for this date period] but did not find it') + #if we are testing it to fail there is no need to continue through rest of the test below + return + end + # + # Create the contract rule values + # + @@ie.button('Set Values').click + # + # + if p_verify_data_entry == 'Y' + # + # Format of the numbers must be 99999.99 + # + set_contract_value(3,['17,123.30','35,616.46','34,246.60','0.00','17123.3','0.00','0.00','17123.3','0.00','0.00','17123.3','0.00']) + set_contract_value(15,['68493.20','142,465.86','136,986.40','0.00','68,493.20','0.00','0.00','68,493.20','0.00','0.00','68,493.20','0.00']) + @@ie.button('Update').click + @@ie.wait + # + assert(@@ie.contains_text('Data supplied with invalid number formats'),'Create Contract Values did not fail as expected'+geterrormess(@@ie)) + # + # Contracted value is > maximum + # + set_contract_value(3,['17123.30','34246.60','35616.46','0.00','17123.3','0.00','0.00','17123.3','0.00','0.00','17123.3','0.00']) + set_contract_value(15,['68493.20','136986.40','142465.86','0.00','68493.20','0.00','0.00','68493.20','0.00','0.00','68493.20','0.00']) + @@ie.button('Update').click + @@ie.wait + # + assert(@@ie.contains_text('Contracted greater than Maximum'),'Create Contract Values did not fail as expected'+geterrormess(@@ie)) + # + # + # Contracted value is < minimum + # + set_contract_value(3,['17123.30','35616.46','246.60','0.00','17123.3','0.00','0.00','17123.3','0.00','0.00','17123.3','0.00']) + set_contract_value(15,['68493.20','142465.86','6986.40','0.00','68493.20','0.00','0.00','68493.20','0.00','0.00','68493.20','0.00']) + @@ie.button('Update').click + @@ie.wait + # + assert(@@ie.contains_text('Contracted less than Minimum'),'Create Contract Values did not fail as expected'+geterrormess(@@ie)) + # + end + # + set_contract_value(3,['17123.30','35616.46','34246.60','0.00','17123.3','0.00','0.00','17123.3','0.00','0.00','17123.3','0.00']) + set_contract_value(15,['68493.20','142465.86','136986.40','0.00','68493.20','0.00','0.00','68493.20','0.00','0.00','68493.20','0.00']) + @@ie.button('Update').click + @@ie.wait + # + assert(@@ie.contains_text('Success!'),'Create Contract Values for '+p_name+' did not succeed: ' +geterrormess(@@ie)) + # +end +# +# SETRULE +# +def set_rule(p_name,p_errmsg,p_LHS,p_RHS,p_operator) + # + @@ie.button(:value, 'New Rule').click + @@ie.wait + # + @@ie.text_field(:name,'p_rule_name').set(p_name) + @@ie.text_field(:name,'p_err_message_hu').set(p_errmsg) + @@ie.text_field(:name,'p_err_message_en').set(p_errmsg) + # + @@ie.text_field(:name,'p_left_side').set('$<'+p_LHS+'>') + @@ie.text_field(:name,'p_right_side').set('$<'+p_RHS+'>') + # + @@ie.select_list(:name, 'p_rule_relation').select(p_operator) + # + @@ie.button( :value, 'Insert' ).click + @@ie.wait + # + assert(@@ie.contains_text('Success!'),'Create Rule '+p_name+' did not succeed: ' +geterrormess(@@ie)) + # + @@ie.button( :value, 'Cancel' ).click + @@ie.wait + # +end +# +# SETCATEGORIES +# +def set_categories(p_name,p_display_seq) + # + @@ie.button(:value,'New').click + @@ie.wait + # + @@ie.text_field(:name,'P_CODE').set(p_name) + @@ie.text_field(:name,'P_NAME').set(p_name) + @@ie.text_field(:name,'P_UNITS').set('m3/day') + @@ie.text_field(:name,'P_NUMBER_FORMAT').set('999999.99') + @@ie.text_field(:name,'P_DISPLAY_SEQUENCE').set(p_display_seq) + # + @@ie.button( :value, 'Insert' ).click + @@ie.wait + #c +end +# +# SETNETWORKPOINT +# +def set_network_point(p_name) + # + @@ie.button(:value,'New').click + @@ie.wait + # + @@ie.text_field( :name, 'P_CODE').set( p_name ) + @@ie.text_field( :name, 'P_NAME').set( p_name ) + @@ie.select_list( :name , "P_STATUS").select("Active") + @@ie.select_list( :name , "P_SITE_TYPE").select("Entry") + # + @@ie.button( :value, 'Insert' ).click + @@ie.wait + # +end ; +# +# SETNOMINATION +# +#This method simply takes the date/time of the nomination , the nominated value and +#number of subsequent days and submits it into the current web form. It assumes you have +#already loaded the web form in the @@ie class object variable +#Method designed for use iwth the EDEN1 contract (2 NP plus 4 categories) +# +def setnomination(p_contract, p_quantity) + # + @@ie.select_list( :name , "p_contract").select(p_contract) + @@ie.wait + # + #@@ie.text_field( :name, 'nomid' ).set( 'PUW_EDEN1_'+(Time.now).strftime("%d%m%y%H%M%S") ) + # + i = 4 + # + # Passing in an array of arrays the loop though, use the index i to deermine the text field for data entry. + # + p_quantity.each do |nomination| + # + @@ie.text_field( :index, i).set( nomination[0] ) + @@ie.text_field(:index, i+1).set(nomination[1]) + @@ie.text_field(:index, i+2).set(nomination[2]) + @@ie.text_field(:index, i+3).set(nomination[3]) + @@ie.text_field(:index, i+4).set(nomination[4]) + @@ie.text_field(:index, i+5).set(nomination[5]) + @@ie.text_field(:index, i+6).set(nomination[6]) + @@ie.text_field(:index, i+7).set(nomination[7]) + @@ie.text_field(:index, i+8).set(nomination[8]) + # + i = i + 8 + # + end + # + @@ie.button( :value, 'Insert' ).click + @@ie.wait + # +end +# +# SETMULTINOM +# +#This method simply takes the date/time of the nimination , the nominated value and +#number of subsequent days and submits it into the current web form. It assumes you have +#already loaded the web form in the @@ie class object variable +#Method designed for use iwth the EDEN1 contract (2 NP plus 4 categories) +# +def setmultinom(p_contract, p_quantity) + # + @@ie.select_list( :name , "p_contract").select(p_contract) + @@ie.wait + # + #@@ie.text_field( :name, 'nomid' ).set( 'PUW_EDEN2_'+(Time.now).strftime("%d%m%y%H%M%S") ) + # + i = 5 + # + # Passing in an array of arrays the loop though, use the index i to deermine the text field for data entry. + # + p_quantity.each do |nomination| + # + @@ie.text_field( :index, i).set( nomination[0] ) + @@ie.text_field(:index, i+1).set(nomination[1]) + @@ie.text_field(:index, i+2).set(nomination[2]) + @@ie.text_field(:index, i+3).set(nomination[3]) + @@ie.text_field(:index, i+4).set(nomination[4]) + i = i + 5 + # + end + # + @@ie.button( :value, 'Insert' ).click + @@ie.wait + # +end +# +# GETERRORMESS +# +#The geterrormess method extracts the error message from +#a designer built screen +def geterrormess (ie) + #get the html for the current page + html = ie.html + #Find the start of the error + i= html.index('Error!') + if i == nil + return '' + end + #get the html code from the error onwards + htmlex = html.slice(i,html.length) + #get the end of the error message + x= htmlex.index('') + #extract just the error message (skip 'Error!
') + return errcode = htmlex.slice(21,x-21) +end +# +# STARTDATE +# +#set up the startdate method (you could call it a function if you're not into Ruby) +#create time (year, month, day, hour, minutes, seconds) +#Hello testers be sure to set the start date for the test here +#Note that I've now set this in the controlling program so it's no longer +#required here +#STARTDATE = Time.gm(2007,'feb',13) + +def futuredate (days=0) +#The startdate method takes a number of days + or - and then takes or +#adds them to the startdate specified in the local variable startdate and returns +#the date in the format dd-mmm-yyyy + +#add a number of days to the time and return it in the format dd/mm/yyyy eg. 10/02/2007 +return ((Time.now)+(86400*days)).strftime("%d/%m/%Y").upcase +end +# +# +# +def purge_EDEN2_noms + dosql('begin DELETE nom_net_point_cat_vals WHERE nomi_id IN (SELECT nomi_id FROM nominations WHERE cont_id = (SELECT cont_id FROM contracts WHERE contract_number = \'EDEN2\')); commit; end;') + dosql('begin DELETE nominations WHERE cont_id = (SELECT cont_id FROM contracts WHERE contract_number = \'EDEN2\'); commit; end;') +end \ No newline at end of file diff --git a/tests/exportdatatests.rb b/tests/exportdatatests.rb new file mode 100644 index 0000000..09361f1 --- /dev/null +++ b/tests/exportdatatests.rb @@ -0,0 +1,82 @@ +#--- +#This unit test checks the export data function of webmip +#should check that all the tables are available for export +#may have some issues with the file downloads as I'm not sure how +#we handle these with ie and watir +#--- +class Test_01_export_data < Test::Unit::TestCase + # + #Test we can logon to the system using the webmip administrator user’s login credentials + # + def test_01_data_export_screen_appears + @@ie.goto(EXPORT_DATA) + #we'll need to login + login(JAMIE, JAMIE_PWD) + assert(@@ie.contains_text('Data Export'),'The data export screen did not appear') + assert(@@ie.select_list(:id, 'P5_TABLES').exists?,'The tables field was not available') + assert(@@ie.select_list(:id, 'P5_COLUMN_NAMES').exists?,'The column headings field was not available') + assert(@@ie.button(:id, 'Export Data').exists?,'The export data button was not available') + end + # + #Check that all the appropriate tables are listed for export + # + def test_02_correct_list_of_tables_displayed + listoftablestoexport= %W[ACCESS_CONTROLS +ADDRESSES +ASSET_LOCATION_TYPES +BASES +BYPASS_REASONS +CARE_CATEGORIES +CONNECTION_ORIENTATIONS +CONNECTION_TYPES +CONTACT_MECHANISMS +CONTACT_MECHANISM_TYPES +COSTS +DATA_ITEMS +DATA_ITEM_ROLES +DATA_ITEM_ROLES_IMPORT +DRAWINGS +ENQUIRIES +ENQUIRY_EVENTS +ENQUIRY_ROLES +ENQUIRY_STATUS_TYPES +ENQUIRY_TYPES +ERROR_LOGS +EXCEPTION_MESSAGES +FILTERS +FILTER_TYPES +HOUSINGS +HOUSING_TYPES +METERS +METER_SIZE_CODES +METER_TYPES +MODULES +PARTIES +PARTY_ADDRESSES +PARTY_ADDRESS_ROLES +PARTY_CONTACT_MECHANISMS +PARTY_CONTACT_MECHANISM_ROLES +PARTY_RELATIONSHIPS +PARTY_RELATIONSHIP_TYPES +PARTY_ROLES +PASSWORDS +QUOTES +QUOTE_EVENTS +QUOTE_ITEMS +QUOTE_ROLES +QUOTE_STATUSES +REGIONS +REGULATORS +REGULATOR_TYPES +RELIEF_VALVES +RELIEF_VALVE_TYPES +ROLE_TYPES +SERVICE_PRESSURES +SERVICE_PRESSURE_TYPES +SLAMSHUT_TYPES +SLAMSHUT_VALVES] + assert_equal(listoftablestoexport,@@ie.select_list(:id, 'P5_TABLES').getAllContents ,'The data export screen did not appear') + end + + +end \ No newline at end of file diff --git a/tests/start.rb b/tests/start.rb new file mode 100644 index 0000000..1903c56 --- /dev/null +++ b/tests/start.rb @@ -0,0 +1,42 @@ +#requires +require 'watir' +#require the test unit library +require 'test/unit' +#require our constants +require 'constants' +#require our useful helper methods +require 'default_methods.rb' + +#includes +include Watir + + +@@ie = IE.new +@@ie.maximize +#set the speed of watir, we'd also set the speed of light but that's supposed to be a constant +@@ie.speed = :fast + +# +# Setup default config +# +# Remove the test data +# +#dosql('begin cleanup_testdata; commit; end;') +# +# Set the system submission deadline +# +#dosql('begin UPDATE system_configuration SET value = \'20:00\' + # WHERE parameter = \'G_SUBMISSION_DEADLINE\'; commit; end; ') + +# +#Set up our contracts before we start serious testing +# +#require 'usefulscriptthatmightsetupdata' + +# +#Get our individual integration tests +# +require 'exportdatatests' + +#@@ie.wait +#@@ie.close \ No newline at end of file