Ifd_Automation 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. checksums.yaml +7 -0
  2. data/bin/Ifd_Automation +30 -0
  3. data/bin/generate.rb +20 -0
  4. data/bin/helper.rb +51 -0
  5. data/features/TestData/testdata.yml +4 -0
  6. data/features/TestSuite/Login/login.feature +6 -0
  7. data/features/step_definitions/lib_steps/login_steps.rb +3 -0
  8. data/features/step_definitions/repositories/ob_login.rb +3 -0
  9. data/features/support/env.rb +102 -0
  10. data/features/support/hooks.rb +57 -0
  11. data/features/support/project_env.rb +51 -0
  12. data/lib/Ifd_Automation/assertion_steps.rb +96 -0
  13. data/lib/Ifd_Automation/email_steps.rb +91 -0
  14. data/lib/Ifd_Automation/javascript_handling_steps.rb +34 -0
  15. data/lib/Ifd_Automation/lib_file_steps.rb +45 -0
  16. data/lib/Ifd_Automation/lib_schema_data_steps.rb +110 -0
  17. data/lib/Ifd_Automation/lib_web_steps.rb +184 -0
  18. data/lib/Ifd_Automation/lib_webservice_steps.rb +44 -0
  19. data/lib/Ifd_Automation/methods/IFD_Assertion_methods.rb +206 -0
  20. data/lib/Ifd_Automation/methods/IFD_Connection.rb +28 -0
  21. data/lib/Ifd_Automation/methods/IFD_email_methods.rb +16 -0
  22. data/lib/Ifd_Automation/methods/IFD_webservice.rb +17 -0
  23. data/lib/Ifd_Automation/methods/core.rb +342 -0
  24. data/lib/Ifd_Automation/methods/database_methods.rb +25 -0
  25. data/lib/Ifd_Automation/methods/db_utils.rb +37 -0
  26. data/lib/Ifd_Automation/methods/error_handling_methods.rb +87 -0
  27. data/lib/Ifd_Automation/methods/javascript_handling_methods.rb +46 -0
  28. data/lib/Ifd_Automation/methods/lib_var.rb +59 -0
  29. data/lib/Ifd_Automation/methods/misc_methods.rb +33 -0
  30. data/lib/Ifd_Automation/methods/required_files.rb +33 -0
  31. data/lib/Ifd_Automation/methods/util.rb +168 -0
  32. data/lib/Ifd_Automation/methods/web_methods.rb +291 -0
  33. data/lib/Ifd_Automation/methods/web_service_methods.rb +63 -0
  34. data/lib/Ifd_Automation/version.rb +5 -0
  35. data/lib/Ifd_Automation.rb +1 -0
  36. metadata +439 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4b2a5b2e44888d5988db54e57fd2e47e28831ef8
4
+ data.tar.gz: 3ac4e763c5160caa5136702575a94bcaac119a0f
5
+ SHA512:
6
+ metadata.gz: bff8f02df7c5fb68b185f700f9a4140ea25704bf05eeef200954e5ed396772a6f131eb1415b1eff459d074fd185615fdeb09214e9896d508d25d064ca6d9e1da
7
+ data.tar.gz: 24d6859007c1fac14342d172fc9b495263985122500477ced292e1f151900ebdab4318b6f0ed8547bf3f913ece66e6a9be0665a86eecbe1b98d0c8c1e720393b
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative 'helper.rb'
4
+ require_relative 'generate.rb'
5
+ require 'Ifd_Automation/version'
6
+
7
+ @features_dir = File.join(FileUtils.pwd, "features")
8
+ @support_dir = File.join(@features_dir, "support")
9
+ @support_dir = File.join(@features_dir, "expected_images")
10
+ @support_dir = File.join(@features_dir, "actual_images")
11
+ @support_dir = File.join(@features_dir, "image_difference")
12
+ @support_dir = File.join(@features_dir, "screenshots")
13
+ @source_dir = File.join(File.dirname(__FILE__), '..', 'features')
14
+
15
+ if (ARGV.length == 0)
16
+ print_usage
17
+ else
18
+ cmd = ARGV.shift
19
+
20
+ if cmd == "help"
21
+ print_help
22
+ elsif cmd == "gen"
23
+ ifd_automation_scaffold
24
+ elsif cmd == "version"
25
+ puts Ifd::Automation::VERSION
26
+ else
27
+ print_usage
28
+ end
29
+ end
30
+
data/bin/generate.rb ADDED
@@ -0,0 +1,20 @@
1
+
2
+ def ifd_automation_scaffold
3
+ if File.exists?(@features_dir)
4
+ puts "A features directory already exists. Stopping..."
5
+ exit 1
6
+ end
7
+ msg("Question") do
8
+ puts "I'm about to create a subdirectory called features."
9
+ puts "features will contain all your project tests."
10
+ puts "Please hit return to confirm that's what you want."
11
+ end
12
+ exit 2 unless STDIN.gets.chomp == ''
13
+
14
+ FileUtils.cp_r(@source_dir, @features_dir)
15
+
16
+ msg("Info") do
17
+ puts "features subdirectory created. \n"
18
+ end
19
+
20
+ end
data/bin/helper.rb ADDED
@@ -0,0 +1,51 @@
1
+ require 'tempfile'
2
+ require 'json'
3
+ require "rubygems"
4
+
5
+ def msg(title, &block)
6
+ puts "\n" + "-"*10 + title + "-"*10
7
+ block.call
8
+ puts "-"*10 + "-------" + "-"*10 + "\n"
9
+ end
10
+
11
+ def print_usage
12
+ puts <<EOF
13
+
14
+ Usage: Ifd_Automation <command-name> [parameters] [options]
15
+
16
+ <command-name> can be one of
17
+ help
18
+ prints more detailed help information.
19
+ gen
20
+ generate a features folder structure.
21
+ version
22
+ prints the gem version
23
+
24
+ <options> can be
25
+ -v, --verbose Turns on verbose logging
26
+ EOF
27
+ end
28
+
29
+ def print_help
30
+ puts <<EOF
31
+
32
+ Usage: Ifd_Automation <command-name> [parameters] [options]
33
+
34
+ <command-name> can be one of
35
+ help
36
+ gen
37
+ version
38
+
39
+ Commands:
40
+ help : prints more detailed help information.
41
+
42
+ gen : creates a skeleton features dir. This is usually used once when
43
+ setting up ifd-automation to ensure that the features folder contains
44
+ the right step definitions and environment to run with cucumber.
45
+
46
+ version : prints the gem version
47
+
48
+ <Options>
49
+ -v, --verbose Turns on verbose logging
50
+ EOF
51
+ end
@@ -0,0 +1,4 @@
1
+ #################### TEST DATA FOR LOGIN ACCOUNT
2
+ login:
3
+ username: anh.pham@infodation.vn
4
+ password: anhanh
@@ -0,0 +1,6 @@
1
+ #Author: Anh Pham
2
+
3
+ @LOGIN
4
+ Feature: Testing login functionality
5
+ Scenario: Test Case for Demo
6
+ Given I navigate to Demo page
@@ -0,0 +1,3 @@
1
+ When /^I navigate to Demo page$/ do
2
+ step %{I am on Login Page}
3
+ end
@@ -0,0 +1,3 @@
1
+ $_RP_OBJECT['textbox_username'] = {xpath_selector: '//*[@id="login_user"]'}
2
+ $_RP_OBJECT['textbox_password'] = {xpath_selector: '//*[@id="login_pass"]'}
3
+ $_RP_OBJECT['button_login'] = {xpath_selector: '//*[@id="wp-submit"]'}
@@ -0,0 +1,102 @@
1
+ # Define global variables
2
+ $current_dir = File.expand_path(File.dirname(__FILE__))
3
+ $base_dir = File.expand_path(File.dirname(__FILE__) + '/../..')
4
+
5
+ require "#{$current_dir}/project_env.rb"
6
+ require 'mail'
7
+ require 'capybara'
8
+ require 'capybara/cucumber'
9
+ require 'test/unit'
10
+ require 'test/unit/assertions'
11
+ require 'action_mailer'
12
+ require 'rubygems'
13
+ require 'Ifd_Automation'
14
+ Mail.defaults do
15
+ delivery_method :smtp, {
16
+ :enable_starttls_auto => true,
17
+ :address => $SEND_EMAIL_ADDRESS,
18
+ :port => $SEND_EMAIL_PORT,
19
+ :domain => $SEND_EMAIL_DOMAIN,
20
+ :authentication => :plain,
21
+ :user_name => $SEND_EMAIL_USERNAME,
22
+ :password => $SEND_EMAIL_PASSWORD
23
+ }
24
+ retriever_method :pop3, {
25
+ :address => $RECEIVE_EMAIL_ADDRESS,
26
+ :port => $RECEIVE_EMAIL_PORT,
27
+ :user_name => $RECEIVE_EMAIL_USERNAME,
28
+ :password => $RECEIVE_EMAIL_PASSWORD,
29
+ :enable_ssl => true
30
+ }
31
+ end
32
+
33
+ if ENV["SELENIUM"] == 'remote'
34
+ Capybara.app_host = $_CFWEB['Page Address']
35
+ Capybara.default_wait_time = $_CFWEB['Wait Time']
36
+ Capybara.default_driver = :selenium
37
+ Capybara.register_driver :selenium do |app|
38
+ if $_CFWEB['Default Browser'] == :firefox
39
+ profile = Selenium::WebDriver::Firefox::Profile.new
40
+ profile['browser.download.dir'] = $_CFWEB['Download Dir']
41
+ profile['browser.download.folderList'] = 2
42
+ profile['browser.helperApps.neverAsk.saveToDisk'] = "text/csv,application/pdf"
43
+ capabilities = Selenium::WebDriver::Remote::Capabilities.firefox(:firefox_profile => profile)
44
+ Capybara::Selenium::Driver.new(app,
45
+ :browser => :remote,
46
+ :url => $selenium_grid_url,
47
+ :desired_capabilities => capabilities)
48
+ elsif $_CFWEB['Default Browser'] == :internet_explorer
49
+ capabilities = Selenium::WebDriver::Remote::Capabilities.internet_explorer
50
+ Capybara::Selenium::Driver.new(app,
51
+ :browser => :remote,
52
+ :url => $selenium_grid_url,
53
+ :desired_capabilities => capabilities)
54
+ elsif $_CFWEB['Default Browser'] == :chrome
55
+ prefs = {:download => {:prompt_for_download => false, :default_directory => $_CFWEB['Download Dir']}}
56
+ capabilities = Selenium::WebDriver::Remote::Capabilities.chrome
57
+ capabilities['chromeOptions'] = {'prefs' => prefs}
58
+ Capybara::Selenium::Driver.new(app, :browser => :remote,
59
+ :url => $selenium_grid_url,
60
+ :desired_capabilities => capabilities)
61
+ else
62
+ puts("Not support browser...")
63
+ end
64
+ end
65
+ else
66
+ ENV["SELENIUM"] == 'local'
67
+ Capybara.configure do |config|
68
+ config.app_host = $_CFWEB['Page Address']
69
+ config.default_wait_time = $_CFWEB['Wait Time']
70
+ config.run_server = false
71
+ config.default_driver = :selenium
72
+ config.default_selector = :css
73
+ config.ignore_hidden_elements = true
74
+ #config.visible_text_only = true
75
+ end
76
+ Capybara.register_driver :selenium do |app|
77
+ if $_CFWEB['Default Browser'] == :firefox
78
+ profile = Selenium::WebDriver::Firefox::Profile.new
79
+ profile['browser.download.folderList'] = 2
80
+ profile['browser.download.dir'] = $_CFWEB['Download Dir']
81
+ profile['browser.helperApps.neverAsk.saveToDisk'] = "text/csv,application/pdf,application/x-pdf,application/octet-stream"
82
+ profile["pdfjs.disabled"] = true
83
+ Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile)
84
+ elsif $_CFWEB['Default Browser'] == :internet_explorer
85
+ Capybara::Selenium::Driver.new(app, :browser => :internet_explorer)
86
+ elsif $_CFWEB['Default Browser'] == :chrome
87
+ prefs = {:download => {
88
+ :prompt_for_download => false,
89
+ :default_directory => $_CFWEB['Download Dir']
90
+ }}
91
+ args = []
92
+ args << "--test-type" #to fix the error of chrome "you are using an unsupported command-line flag ignore-certificate-errors"
93
+
94
+ Capybara::Selenium::Driver.new(app, :browser => :chrome, :prefs => prefs, :args => args)
95
+ else
96
+ puts("Not support browser...")
97
+ end
98
+ end
99
+ end
100
+ CI_REPORTS = 'features/reports'
101
+ World(Test::Unit::Assertions)
102
+
@@ -0,0 +1,57 @@
1
+ #Only run IE browser
2
+ Before('@IE') do
3
+ $_Old_Default_Browser = $_CFWEB['Default Browser']
4
+ $_CFWEB['Default Browser'] = 'IE'
5
+ end
6
+ After('@IE') do
7
+ $_CFWEB['Default Browser'] = $_Old_Default_Browser
8
+ end
9
+
10
+ #Only run Chrome browser
11
+ Before('@CH') do
12
+ $_Old_Default_Browser = $_CFWEB['Default Browser']
13
+ $_CFWEB['Default Browser'] = 'CH'
14
+ end
15
+ After('@CH') do
16
+ $_CFWEB['Default Browser'] = $_Old_Default_Browser
17
+ end
18
+
19
+ #Only run Firefox browser
20
+ Before('@FF') do
21
+ $_Old_Default_Browser = $_CFWEB['Default Browser']
22
+ $_CFWEB['Default Browser'] = 'FF'
23
+ end
24
+ After('@FF') do
25
+ $_CFWEB['Default Browser'] = $_Old_Default_Browser
26
+ end
27
+
28
+ Before do
29
+ begin
30
+ browser = Capybara.current_session.driver.browser
31
+ browser.manage.delete_all_cookies
32
+ rescue StandardError => myStandardError
33
+ put_log "\n>>> Error: #{myStandardError}"
34
+ end
35
+ end
36
+
37
+ After do |scenario|
38
+ begin
39
+ Capybara.page.driver.quit
40
+ Capybara.send(:session_pool).delete_if { |key, value| key =~ /selenium/i }
41
+ rescue StandardError => myStandardError
42
+ put_log "\n>>> Error: #{myStandardError}"
43
+ end
44
+ end
45
+
46
+ at_exit do
47
+ end
48
+
49
+ AfterConfiguration do |config|
50
+ end
51
+
52
+ Around do |scenario, block|
53
+ block.call
54
+ end
55
+
56
+ AfterStep do |scenario|
57
+ end
@@ -0,0 +1,51 @@
1
+ $_CFWEB = Hash.new
2
+ ###################################################################
3
+ # BROWSER CONFIGURATION #
4
+ ###################################################################
5
+ #---------------------------
6
+ # :firefox=> "FireFox"
7
+ # :internet_explorer => "Internet Explorer"
8
+ # :chrome => "Chrome"
9
+ #---------------------------
10
+ $_CFWEB['Print Log'] = true
11
+ $_CFWEB['Default Browser'] = :firefox
12
+ $_CFWEB['Wait Time'] = 30
13
+ $_CFWEB['Maximize Browser'] = true
14
+ STDOUT.sync = true
15
+ ###################################################################
16
+ # EDITABLE CONFIGURATION #
17
+ ###################################################################
18
+ $_CFWEB['Download Dir'] = "#{$test_data_dir}DownloadFolder/"
19
+ $_CFWEB['Expected Data Dir'] = "#{$test_data_dir}/ExpectedDataFile/"
20
+ $test_data_dir = $base_dir + '/features/TestData'
21
+ $sql_dir = $base_dir + '/features/TestData/SqlScript/'
22
+ $testdata = YAML.load_file("#{$test_data_dir}/testdata.yml")
23
+ $_CFWEB['Page Address'] = 'http://google.com/'
24
+ $selenium_grid_url='http://10.5.1.202:5555/wd/hub'
25
+ ###################################################################
26
+ # DATABASE CONFIGURATION #
27
+ ###################################################################
28
+ #-----------------------------------------------------------------
29
+ # $db_type=> "sql_server" || "mysql"
30
+ #-----------------------------------------------------------------
31
+ $data_source_username = ''
32
+ $data_source_password = ''
33
+ $data_source_url = ''
34
+ $db_type='sql_server'
35
+ ###################################################################
36
+ # WEBSERVICE CONFIGURATION #
37
+ ###################################################################
38
+ $WS_URL = 'http://...'
39
+ ###################################################################
40
+ # EMAIL CONFIGURATION #
41
+ ###################################################################
42
+ $SEND_EMAIL_USERNAME=''
43
+ $SEND_EMAIL_PASSWORD=''
44
+ $SEND_EMAIL_DOMAIN='gmail.com'
45
+ $SEND_EMAIL_ADDRESS='smtp.gmail.com'
46
+ $SEND_EMAIL_PORT= 25
47
+ #------------------------------------------------------------------
48
+ $RECEIVE_EMAIL_USERNAME=''
49
+ $RECEIVE_EMAIL_PASSWORD=''
50
+ $RECEIVE_EMAIL_ADDRESS='pop.gmail.com'
51
+ $RECEIVE_EMAIL_PORT=995
@@ -0,0 +1,96 @@
1
+ # require_relative 'methods/web_methods'
2
+ require_relative 'methods/required_files'
3
+ # page title checking
4
+ Then(/^I should\s*((?:not)?)\s+see page title as "(.*?)"$/) do |present, title|
5
+ check_title(title, present.empty?)
6
+ end
7
+
8
+ Then(/^I should\s*((?:not)?)\s+see page title having partial text as "(.*?)"$/) do |present, partial_text_title|
9
+ check_partial_title(partial_text_title, present.empty?)
10
+ end
11
+
12
+ # check property for object
13
+ Then /^I check property "(.*?)" with "(.*?)" has( | not)? value "(.*?)"$/ do |object, property, negate, value|
14
+ value = var_collect(value)
15
+ execute_checkproperty(object, property, negate, value)
16
+ end
17
+
18
+ Then /^the following multiline step should (fail|succeed):$/ do |expectation, multiline_step|
19
+ multiline_step = multiline_step.gsub(%{'''}, %{"""})
20
+ if expectation == 'fail'
21
+ expect { steps(multiline_step) }.to raise_error(RSPEC_EXPECTATION_NOT_MET_ERROR)
22
+ else # succeed
23
+ steps(multiline_step)
24
+ end
25
+ end
26
+
27
+ Then /^the following steps? should (fail|succeed):$/ do |expectation, steps_table|
28
+ steps = steps_table.raw.flatten
29
+
30
+ steps.each do |step|
31
+ if expectation == 'fail'
32
+ expect { step(step) }.to raise_error(RSPEC_EXPECTATION_NOT_MET_ERROR)
33
+ else # succeed
34
+ step(step)
35
+ end
36
+ end
37
+ end
38
+
39
+ Then /^I should see a form with the following values:$/ do |table|
40
+ expectations = table.raw
41
+ expectations.each do |label, expected_value|
42
+ step %(I check property "#{label}" with "text" has value "#{expected_value}")
43
+ end
44
+ end
45
+
46
+ Then /^Status of "([^\"]*)" should be "(disabled|enabled)"$/ do |element, status|
47
+ puts "status: #{status} => status =='disabled': #{status =='disabled'}"
48
+ foundElement = if(status =='disabled')
49
+ find_object(element + "{'disabled':'true'}")
50
+ elsif (status =='enabled')
51
+ find_object(element + "{'disabled':''}")
52
+ else
53
+ puts "Error >> '#{status }' status is not support."
54
+ exit
55
+ end
56
+
57
+ if foundElement == nil
58
+ puts "Error >> Not found object..."
59
+ exit
60
+ end
61
+ end
62
+
63
+ And /^I check( not)? exists element is "(.*?)"$/ do |negate, object|
64
+ #negate = negate.strip if negate != nil
65
+ execute_checkexists(negate, object,2)
66
+ end
67
+
68
+ # step to assert checkbox is checked or unchecked
69
+ Then(/^checkbox "(.*?)" should be (checked|unchecked)$/) do |element, state|
70
+ flag = state == 'checked'
71
+ is_checkbox_checked(element, flag)
72
+ end
73
+
74
+ # steps to assert radio button checked or unchecked
75
+ Then(/^radio button "(.*?)" should be (selected|unselected)$/) do |element, state|
76
+ flag = state == 'selected'
77
+ is_radio_button_selected(element, flag)
78
+ end
79
+
80
+ # step to assert javascript pop-up alert text
81
+ Then(/^I should see alert text as "(.*?)"$/) do |actual_value|
82
+ check_alert_text(actual_value)
83
+ end
84
+
85
+ # step to assert difference in images
86
+ Then(/^actual image having (.+) "(.*?)" and expected image having (.+) "(.*?)" should be similar$/) do |actual_img_access_type, actual_img_access_name, excp_img_access_type, excp_img_access_name|
87
+ IFD_Assertion.does_images_similar?(actual_img_access_type, actual_img_access_name, excp_img_access_type, excp_img_access_name)
88
+ end
89
+
90
+ # step to check element enabled or not
91
+ Then(/^element "([^\"]*)" should\s*((?:not)?)\s+be (enabled|disabled)$/) do |element, present, state|
92
+ flag = state == 'enabled'
93
+ flag = !flag unless present.empty?
94
+ check_element_enable(element, flag)
95
+ end
96
+
@@ -0,0 +1,91 @@
1
+ require 'mail'
2
+ require_relative 'methods/required_files'
3
+ # Before do
4
+ # ActionMailer::Base.deliveries.clear
5
+ # end
6
+
7
+ Then /^I send the email to "(.*)" with subject is "(.*)" and email body in "(.*)" file$/ do |to_address, subject, file|
8
+ data_file = File.read($test_data_dir + file)
9
+ filepath = ($test_data_dir + file)
10
+ body_email = data_file.force_encoding('UTF-8').encode('UTF-16', :invalid => :replace, :replace => "'").encode('UTF-8')
11
+ if File.exist?(filepath)
12
+ IFD_Email.send_email(to_address, subject, body_email)
13
+ end
14
+ end
15
+ Then /^I send the email to "(.*)" with subject is "(.*)" and email body "(.*)"$/ do |to_address, subject, email_body|
16
+ email_body = email_body.force_encoding('UTF-8').encode('UTF-16', :invalid => :replace, :replace => "'").encode('UTF-8')
17
+ IFD_Email.send_email(to_address, subject, email_body)
18
+ end
19
+
20
+ Then /^I should receive the email from "(.*)" with subject "(.*)"$/ do |email_from, email_subject|
21
+ sleep 5
22
+ emails = Mail.find(:what => :last, :count => 1)
23
+ if emails.instance_of? Mail::Message
24
+ # puts emails.from[0].to_s
25
+ IFD_Assertion.assert_string_equal(email_from, emails.from[0].to_s)
26
+ IFD_Assertion.assert_string_equal(email_subject, emails.subject)
27
+ else
28
+ raise "WARNING: *** No new Email is found"
29
+ end
30
+ end
31
+
32
+ Then /^I should receive the mail from "(.*)" with Email content has following value:$/ do |email_from, email_content|
33
+ sleep 5
34
+ emails = Mail.find(:what => :last, :count => 1)
35
+ if emails.instance_of? Mail::Message
36
+ IFD_Assertion.assert_string_equal(email_from, emails.from[0].to_s)
37
+ email_content.raw[0].each do |line|
38
+ assert(true) if emails.body.should include(line.strip)
39
+ end
40
+ else
41
+ raise "WARNING: *** No new Email is found"
42
+ end
43
+ end
44
+
45
+ Then /^I should receive the mail from "(.*)" with subject "(.*)" amd Email content has following value:$/ do |email_from,email_subject, email_content|
46
+ sleep 5
47
+ emails = Mail.find(:what => :last, :count => 1)
48
+ if emails.instance_of? Mail::Message
49
+ IFD_Assertion.assert_string_equal(email_from, emails.from[0].to_s)
50
+ IFD_Assertion.assert_string_equal(email_subject, emails.subject)
51
+ email_content.raw[0].each do |line|
52
+ assert(true) if emails.body.should include(line.strip)
53
+ end
54
+ else
55
+ raise "WARNING: *** No new Email is found"
56
+ end
57
+ end
58
+
59
+ Then /^I send the email to "(.*)" with subject is "(.*)" and email body template in "(.*)" file and following conditions:$/ do |to_address, subject, file, data_table|
60
+ data_file = File.read($test_data_dir + file)
61
+ filepath = ($test_data_dir + file)
62
+ body_email = data_file.force_encoding('UTF-8').encode('UTF-16', :invalid => :replace, :replace => "'").encode('UTF-8')
63
+ if File.exist?(filepath)
64
+ raw_data = JSON.parse(JSON.generate(data_table))
65
+ header = raw_data[0]
66
+ value = raw_data[1]
67
+ $test = String.new
68
+ $i = 0
69
+ body_email.each_line do |lines|
70
+ header.zip(value).each do |headers, values|
71
+ group1, group2, group3= lines.match(/(^.*)(:)(.*)/i).try(:captures)
72
+ if headers == group1 && group1.size > 0
73
+ $new_value = lines.gsub(group3, " #{values}")
74
+ $test += "#{$new_value}"
75
+ $i = 1
76
+ break
77
+ elsif headers == "taaknummer"
78
+ $new_value = lines.gsub("[TASKID]", " #{values}")
79
+ $test += "#{$new_value}"
80
+ $i = 1
81
+ else
82
+ $i = 0
83
+ end
84
+ end
85
+ if $i == 0
86
+ $test += "#{lines}"
87
+ end
88
+ end
89
+ IFD_Email.send_email(to_address, subject, $test)
90
+ end
91
+ end
@@ -0,0 +1,34 @@
1
+ # require_relative 'methods/javascript_handling_methods'
2
+ require_relative 'methods/required_files'
3
+
4
+ Then(/^I accept pop-up alert$/) do
5
+ handle_alert('accept')
6
+ end
7
+
8
+ Then(/^I dismiss pop-up alert$/) do
9
+ handle_alert('dismiss')
10
+ end
11
+
12
+ And /^I focus in new open page$/ do
13
+ switch_to_windows(last)
14
+ end
15
+
16
+ And /^I focus in previous page$/ do
17
+ switch_to_windows(first)
18
+ end
19
+
20
+ And /^I close current windows$/ do
21
+ close_windows
22
+ end
23
+
24
+ Given /^I go back to the previous page$/ do
25
+ get_browser_back
26
+ end
27
+
28
+ When /^I refresh this page$/ do
29
+ refresh_page
30
+ end
31
+
32
+ And /^I open new browser windows$/ do
33
+ open_new_windows_browser
34
+ end
@@ -0,0 +1,45 @@
1
+ require_relative 'methods/required_files'
2
+ Then /^All records in download file "(.*)" must be included in expected file "(.*)"$/ do |dl_file, expected_file|
3
+ # Read downloaded file and expected file
4
+ actual_file_path = ($_CFWEB['Download Dir'] + dl_file)
5
+ expected_file_path= ($_CFWEB['Expected Data Dir'] + expected_file)
6
+ if File.exist?(actual_file_path) && File.exist?(expected_file_path)
7
+ actual_lines = CSV.read($_CFWEB['Download Dir'] + dl_file)
8
+ expected_lines = CSV.read($_CFWEB['Expected Data Dir'] + expected_file)
9
+ # Assert 2 CSV files
10
+ IFD_Assertion.do_assertion_csv_tab_non_order(expected_lines, actual_lines)
11
+ else
12
+ raise "*** ERROR: Please check #{expected_file} or #{expected_file_path} exists."
13
+ end
14
+
15
+ end
16
+
17
+ Then /^I run exe file "(.*)" on windows$/ do |filename|
18
+ if File.exist?(filename)
19
+ system("'"+filename+"'")
20
+ else
21
+ raise "*** ERROR: Please check Actual File or Expected file exists."
22
+ end
23
+ end
24
+
25
+ # Delete downloaded file
26
+ Then /^I delete previous downloaded (tab|csv) files of "(.*)"$/ do |extension, file_prefix|
27
+ #Check file whose name include file_prefix in downloaded folder
28
+ Dir.open($_CFWEB['Download Dir']).each do |filename|
29
+ #Delete if file exists
30
+ if filename.include? file_prefix then
31
+ File.delete($_CFWEB['Download Dir']+filename)
32
+ end
33
+ end
34
+ end
35
+
36
+ #Delete file from $test_data_dir folder
37
+ Then /^I delete file "(.*)" on Data folder/ do |file_name|
38
+ file = ($test_data_dir + file_name)
39
+ if File.exists?(file)
40
+ File.delete(file)
41
+ puts "#{file_name} is deleted successfully"
42
+ else
43
+ puts "#{file_name} does not exists"
44
+ end
45
+ end