soda 1.1.19 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -70,17 +70,18 @@ class SodaSuite
70
70
  @soda = nil
71
71
 
72
72
  if (NEEDED_SODA_VERSION != Soda::SODA_VERSION)
73
- print "(!)Failed matching Soda Class Versions!\n" +
74
- "--)Required Version: #{NEEDED_SODA_VERSION}\n" +
75
- "--)Found Version : #{Soda::SODA_VERSION}\n\n"
73
+ SodaUtils.PrintSoda("Failed matching Soda Class Versions!\n")
74
+ SodaUtils.PrintSoda("Required Version: #{NEEDED_SODA_VERSION}\n")
75
+ SodaUtils.PrintSoda("Found Version : #{Soda::SODA_VERSION}\n")
76
76
  exit(-1)
77
77
  end
78
78
 
79
79
  if ("#{Watir::VERSION}" != "#{Soda::SODA_WATIR_VERSION}")
80
- print "(!)Failed matching installed Watir version to Soda's" +
81
- " required version!\n" +
82
- "--)Required Version: #{Soda::SODA_WATIR_VERSION}\n" +
83
- "--)Found Version : #{Watir::VERSION}\n\n"
80
+ SodaUtils.PrintSoda("Failed matching installed Watir version to"+
81
+ " Soda's required version!\n", SodaUtils::ERROR)
82
+ SodaUtils.PrintSoda("--)Required Version: "+
83
+ "#{Soda::SODA_WATIR_VERSION}\n")
84
+ SodaUtils.PrintSoda("--)Found Version : #{Watir::VERSION}\n")
84
85
  exit(-1)
85
86
  end
86
87
  end
@@ -238,7 +239,7 @@ Optional Flags:
238
239
  --sugarwait: This enables the auto sugarwait functionality for every click.
239
240
 
240
241
  --restartcount: This tells soda to restart the web browser after so many
241
- tests have been ran.
242
+ tests have been ran. This flag can only be using when running suites!
242
243
 
243
244
  --restarttest: This is a soda test that will be ran right after the browser
244
245
  is restarted.
@@ -322,8 +323,9 @@ def CreateResultsDir(dir)
322
323
  FileUtils::mkdir_p(dir)
323
324
  result = 0
324
325
  rescue Exception => e
325
- print "(!)Failed to create results directory: #{dir}!\n"
326
- print "--)Reason: #{e.message}\n\n"
326
+ SodaUtils.PrintSoda("Failed to create results directory: #{dir}!\n",
327
+ SodaUtils::ERROR)
328
+ SodaUtils.PrintSoda("--)Reason: #{e.message}\n")
327
329
  result = -1
328
330
  end
329
331
 
@@ -353,50 +355,6 @@ def GetFileSetFiles(dir)
353
355
  return test_files
354
356
  end
355
357
 
356
- ###############################################################################
357
- # GetSuiteTestFiles - function
358
- # This function reads a sode suite file and creates a list of tests from
359
- # the file, by expanding on filesets and files.
360
- #
361
- # Params:
362
- # suite_file: This is the suite xml file.
363
- #
364
- # Results:
365
- # returns an array of files.
366
- #
367
- ###############################################################################
368
- def GetSuiteTestFiles(suite_file)
369
- test_files = []
370
- parser = nil
371
- doc = nil
372
-
373
- parser = LibXML::XML::Parser.file(suite_file)
374
- doc = parser.parse()
375
-
376
- doc.root.each do |node|
377
- if (node.name != 'script')
378
- next
379
- end
380
-
381
- attrs = node.attributes()
382
- attrs.each do |a|
383
- h = attrs.to_h()
384
- if (h.key?("file"))
385
- test_files.push(h['file'])
386
- elsif (h.key?('fileset'))
387
- fs = h['fileset']
388
- if (File.directory?(fs))
389
- fs_set = GetFileSetFiles(fs)
390
- test_files.concat(fs_set)
391
- fs_set = nil
392
- end
393
- end
394
- end
395
- end
396
-
397
- return test_files
398
- end
399
-
400
358
  ###############################################################################
401
359
  # ReadConfigFile - function
402
360
  # This functions reads the soda config file into a hash.
@@ -586,7 +544,7 @@ def Main
586
544
  when "--nonzippytext"
587
545
  params['nonzippytext'] = true
588
546
  when "--version"
589
- print "(*)SODA Version: #{SODA_GEM_VERSION}\n\n"
547
+ SodaUtils.PrintSoda("(*)SODA Version: #{SODA_GEM_VERSION}\n")
590
548
  return 0
591
549
  end
592
550
  end
@@ -611,6 +569,12 @@ def Main
611
569
  PrintHelp()
612
570
  end
613
571
 
572
+ if (params['suites'].length < 1 && params['restart_count'] > 0)
573
+ SodaUtils.PrintSoda("Error: --restartcount can only be used with"+
574
+ " --suite!\n\n")
575
+ PrintHelp()
576
+ end
577
+
614
578
  if (params['debug'])
615
579
  SodaUtils.PrintSoda("SodaSuite Params:\n")
616
580
  params.each do |k, v|
@@ -627,7 +591,6 @@ def Main
627
591
 
628
592
  if (params['resultsdir'] != nil)
629
593
  err = CreateResultsDir(params['resultsdir'])
630
- print "Result: #{err}\n"
631
594
  if (err != 0)
632
595
  exit(-1)
633
596
  end
@@ -640,7 +603,7 @@ def Main
640
603
 
641
604
  if (params['suites'].length > 0)
642
605
  sweet = SodaSuite.new(params)
643
- result = sweet.ExecuteTestSuites(params['suites'])
606
+ suites_result = sweet.ExecuteTestSuites(params['suites'])
644
607
  end
645
608
 
646
609
  if (params['test_files'].length > 0)
@@ -668,9 +631,8 @@ def Main
668
631
  params['summaryfile'], true)
669
632
  end
670
633
  rescue Exception => e
671
- print "Error: calling: SodaReportSummery: #{e.message}\n"
672
- print e.backtrace.join("\n")
673
- print "\n\n"
634
+ SodaUtils.PrintSoda("SodaReportSummery: #{e.message}\n",
635
+ SodaUtils::ERROR)
674
636
  exit(-1)
675
637
  ensure
676
638
  end
@@ -104,7 +104,7 @@ class Soda
104
104
  $mutex = Mutex.new()
105
105
  @whiteList = []
106
106
  @white_list_file = ""
107
- @restart_test = ""
107
+ @restart_test = nil
108
108
  @restart_count = 0
109
109
  @non_lib_test_count = 0
110
110
  @last_test = ""
@@ -777,18 +777,12 @@ class Soda
777
777
  valid_xml = false
778
778
  end
779
779
 
780
- if (valid_xml && !@restart_test_running && file != @last_file &&
781
- @non_lib_test_count >= @restart_count)
782
- RestartBrowserTest()
783
- end
784
-
785
780
  if (valid_xml)
786
781
  $run_script = file
787
782
  PrintDebug("Parsing Soda test file: \"#{file}\".\n")
788
783
  begin
789
784
  checker = SodaTestCheck.new(file, @rep)
790
785
  script_check = checker.Check()
791
-
792
786
  if (!script_check)
793
787
  script = nil
794
788
  @rep.IncSkippedTest()
@@ -797,19 +791,11 @@ class Soda
797
791
  end
798
792
  rescue Exception => e
799
793
  @rep.ReportException(e, file)
794
+ script = nil
800
795
  ensure
801
796
  end
802
797
  end
803
798
 
804
- dir = File.dirname(file)
805
- if (dir !~ /lib/)
806
- if(!is_restart && !@restart_test_running && file != @last_test)
807
- @non_lib_test_count += 1
808
- @rep.IncTestCount()
809
- PrintDebug("Test since last restart: #{@non_lib_test_count +1}.\n")
810
- end
811
- end
812
-
813
799
  return script
814
800
  end
815
801
 
@@ -824,48 +810,40 @@ class Soda
824
810
  # None.
825
811
  #
826
812
  ###############################################################################
827
- def RestartBrowserTest()
828
- return 0 if (@restart_count < 1)
813
+ def RestartBrowserTest(suitename)
829
814
 
830
- if (@non_lib_test_count >= @restart_count)
831
- @rep.log("Restarting browser.\n")
832
-
833
- if (!@GotWatchDog)
834
- begin
835
- @browser.close()
836
- sleep(1)
837
- rescue Exception => e
838
- end
839
- @GotWatchDog = false
815
+ if (!@GotWatchDog)
816
+ begin
817
+ @browser.close()
818
+ sleep(1)
819
+ rescue Exception => e
840
820
  end
821
+ @GotWatchDog = false
822
+ end
841
823
 
842
- RestartGlobalTime()
824
+ RestartGlobalTime()
843
825
 
844
- if (@params['browser'] =~ /firefox/i)
845
- SodaFireFox.KillProcesses()
846
- end
826
+ if (@params['browser'] =~ /firefox/i)
827
+ SodaFireFox.KillProcesses()
828
+ end
829
+
830
+ err = NewBrowser()
831
+ if (err != 0)
832
+ print "(!)Failed to restart browser!\n"
833
+ end
847
834
 
848
- err = NewBrowser()
849
- if (err != 0)
850
- @rep.ReportFailure("Failed to restart browser!\n")
851
- end
835
+ if (!@restart_test.empty?)
836
+ resultdir = "#{@resultsDir}/#{suitename}"
837
+ @rep = SodaReporter.new(@restart_test, @saveHtml, resultdir,
838
+ 0, nil, false);
839
+ @rep.log("Restarting browser.\n")
840
+ restart_script = getScript(@restart_test)
841
+ handleEvents(restart_script)
852
842
  @rep.log("Finished: Browser restart.\n")
853
- @non_lib_test_count = 0
854
-
855
- if (!@restart_test.empty?)
856
- parent_test = @currentTestFile
857
- restart_data = getScript(@restart_test, true)
858
- if (restart_data != nil)
859
- @currentTestFile = @restart_test
860
- @restart_test_running = true
861
- @rep.log("Executing restart test: '#{@restart_test}'\n")
862
- handleEvents(restart_data)
863
- @restart_test_running = false
864
- @currentTestFile = parent_test
865
- @rep.log("Finished restart test: '#{@restart_test}'\n")
866
- end
867
- end
843
+ @rep.EndTestReport()
868
844
  end
845
+
846
+ RestartGlobalTime()
869
847
  end
870
848
 
871
849
  ###############################################################################
@@ -893,7 +871,6 @@ class Soda
893
871
  fd = Dir.open(file)
894
872
  fd.each do |f|
895
873
  files.push("#{file}/#{f}") if (f =~ /\.xml$/i)
896
- # @rep.IncTestTotalCount() if (f !~ /lib/i)
897
874
  end
898
875
  fd.close()
899
876
 
@@ -915,22 +892,11 @@ class Soda
915
892
  ((file !~ /^setup/) || (file !~ /^cleanup/) ) )
916
893
  @rep.log("Starting new soda test file: \"#{file}\".\n")
917
894
 
918
- if (file !~ /lib/i)
919
- if (@non_lib_test_count >= @restart_count && file != @last_test)
920
- RestartBrowserTest()
921
- end
922
-
923
- @rep.IncTestCount()
924
- @non_lib_test_count += 1
925
- @last_test = file
926
- end
927
-
928
895
  script = getScript(file)
929
896
  if (script != nil)
930
897
  parent_test_file = @currentTestFile
931
898
  @currentTestFile = file
932
899
  results = handleEvents(script)
933
- PrintDebug("Test since last restart: #{@non_lib_test_count +1}.\n")
934
900
  if (results != 0)
935
901
  @FAILEDTESTS.push(@currentTestFile)
936
902
  @rep.IncFailedTest()
@@ -2286,8 +2252,6 @@ JSCode
2286
2252
  when "disabled"
2287
2253
  event['disabled'] = getStringBool(event['disabled'])
2288
2254
  FieldUtils.CheckDisabled(@curEl, event['disabled'], @rep)
2289
- when "exists"
2290
- # do nothing #
2291
2255
  else
2292
2256
  msg = "Failed to find supported field action.\n"
2293
2257
  @rep.log(msg, SodaUtils::WARN)
@@ -2723,7 +2687,7 @@ JSCode
2723
2687
  result = 0
2724
2688
  master_result = 0
2725
2689
  thread_soda = nil
2726
- thread_timeout = (60 * 10) # 10 minutes #
2690
+ thread_timeout = (60 * 6) # 6 minutes #
2727
2691
  time_check = nil
2728
2692
  resultsdir = nil
2729
2693
  blocked = false
@@ -2745,9 +2709,15 @@ JSCode
2745
2709
  @rep = SodaReporter.new(file, @saveHtml, resultsdir, 0, nil, rerun);
2746
2710
  SetGlobalVars()
2747
2711
  blocked = remBlockScript(file)
2748
-
2712
+
2749
2713
  if (!blocked)
2750
- script = getScript(file)
2714
+ checker = SodaTestCheck.new(file, @rep)
2715
+ script_check = checker.Check()
2716
+ if (!script_check)
2717
+ script = nil
2718
+ else
2719
+ script = getScript(file)
2720
+ end
2751
2721
  else
2752
2722
  script = nil
2753
2723
  end
@@ -2766,10 +2736,10 @@ JSCode
2766
2736
 
2767
2737
  if (time_diff >= thread_timeout)
2768
2738
  msg = "Soda watchdog timed out after #{time_diff} seconds!\n"
2739
+ @GotWatchDog = true
2769
2740
  @rep.ReportFailure(msg)
2770
2741
  PrintDebug("Global Time was: #{$global_time}\n")
2771
2742
  PrintDebug("Timeout Time was: #{time_check}\n")
2772
- @GotWatchDog = true
2773
2743
  @rep.IncTestWatchDogCount()
2774
2744
  begin
2775
2745
  result_dir = @rep.GetResultDir()
@@ -2827,6 +2797,7 @@ JSCode
2827
2797
  def RunAllSuites(suites)
2828
2798
  results = {}
2829
2799
  err = 0
2800
+ global_err = 0
2830
2801
  indent = " " * 2
2831
2802
  indent2 = "#{indent}" * 2
2832
2803
  indent3 = "#{indent}" * 4
@@ -2835,11 +2806,23 @@ JSCode
2835
2806
 
2836
2807
  suites.each do |s|
2837
2808
  base_suite_name = File.basename(s)
2809
+ if (results.key?(base_suite_name))
2810
+ suite_dup_id = 1
2811
+ while (results.key?("#{base_suite_name}-#{suite_dup_id}"))
2812
+ suite_dup_id += 1
2813
+ end
2814
+ base_suite_name = "#{base_suite_name}-#{suite_dup_id}"
2815
+ end
2816
+
2838
2817
  RestartGlobalTime()
2839
2818
  results[base_suite_name] = RunSuite(s)
2840
2819
  RestartGlobalTime()
2841
2820
  end
2842
2821
 
2822
+ if (results.empty?)
2823
+ return results
2824
+ end
2825
+
2843
2826
  time = Time.now()
2844
2827
  time = "#{time.to_i}-#{time.usec}"
2845
2828
  suite_report = "#{@resultsDir}/#{hostname}-#{time}-suite.xml"
@@ -2851,21 +2834,31 @@ JSCode
2851
2834
  results.each do |k,v|
2852
2835
  fd.write("\t<suite>\n")
2853
2836
  fd.write("\t#{indent}<suitefile>#{k}</suitefile>\n")
2854
- v.each do |testname, testhash|
2855
- fd.write("\t#{indent2}<test>\n")
2856
- fd.write("\t#{indent3}<testfile>#{testname}</testfile>\n")
2857
- testhash.each do |tname, tvalue|
2858
- if (tname == "result")
2859
- err = -1 if (tvalue.to_i != 0)
2837
+
2838
+ if (v.key?("Suite Failure"))
2839
+ v.each do |sek, sev|
2840
+ name = sek
2841
+ name = name.gsub(" ", "_")
2842
+ fd.write("\t#{indent2}<#{name}>#{sev}</#{name}>\n")
2843
+ end
2844
+ else
2845
+ v.each do |testname, testhash|
2846
+ fd.write("\t#{indent2}<test>\n")
2847
+ fd.write("\t#{indent3}<testfile>#{testname}</testfile>\n")
2848
+ testhash.each do |tname, tvalue|
2849
+ if (tname == "result")
2850
+ err = -1 if (tvalue.to_i != 0)
2851
+ end
2852
+ new_name = "#{tname}"
2853
+ new_name = new_name.gsub(" ", "_")
2854
+ fd.write("\t#{indent3}<#{new_name}>#{tvalue}</#{new_name}>\n")
2860
2855
  end
2861
- new_name = "#{tname}"
2862
- new_name = new_name.gsub(" ", "_")
2863
- fd.write("\t#{indent3}<#{new_name}>#{tvalue}</#{new_name}>\n")
2856
+ fd.write("\t#{indent2}</test>\n")
2864
2857
  end
2865
- fd.write("\t#{indent2}</test>\n")
2866
2858
  end
2867
2859
  fd.write("\t</suite>\n")
2868
2860
  end
2861
+
2869
2862
  fd.write("</data>\n")
2870
2863
  fd.close()
2871
2864
 
@@ -2881,17 +2874,26 @@ JSCode
2881
2874
  parser = nil
2882
2875
  doc = nil
2883
2876
  test_order = 0
2877
+ test_since_restart = 0
2884
2878
  result = {}
2885
2879
  tests = []
2886
2880
  suite_name = File.basename(suitefile, ".xml")
2887
2881
 
2888
2882
  begin
2883
+ LibXML::XML::Error.set_handler(&LibXML::XML::Error::QUIET_HANDLER)
2889
2884
  parser = LibXML::XML::Parser.file(suitefile)
2890
2885
  doc = parser.parse()
2891
2886
  doc = doc.root()
2892
2887
 
2893
2888
  doc.each do |node|
2894
- next if (node.name !~ /script/)
2889
+ next if (node.name =~ /text/i)
2890
+ next if (node.name =~ /comment/i)
2891
+
2892
+ if (node.name !~ /script/i)
2893
+ raise "Using unsupported Soda suite element: '#{node.name}'"+
2894
+ " in suite file: '#{suitefile}'!"
2895
+ end
2896
+
2895
2897
  attrs = node.attributes()
2896
2898
  attrs = attrs.to_h()
2897
2899
 
@@ -2906,22 +2908,30 @@ JSCode
2906
2908
  end
2907
2909
  end
2908
2910
  rescue Exception => e
2909
- print "ERROR: #{e.message}!\n"
2910
- print e.backtrace.join("\n")
2911
- result = nil
2911
+ SodaUtils.PrintSoda(e.message, SodaUtils::ERROR)
2912
+ err_hash = {
2913
+ 'result' => -1,
2914
+ 'Suite Failure' => true,
2915
+ 'Suite Error' => "#{e.message}"
2916
+ }
2917
+ return err_hash
2912
2918
  ensure
2913
2919
  end
2914
2920
 
2915
2921
  tests.each do |test|
2922
+ if ((@restart_count > 0) && (test_since_restart >= @restart_count))
2923
+ SodaUtils.PrintSoda("Restarting browser...\n")
2924
+ RestartBrowserTest(suite_name)
2925
+ test_since_restart = 0
2926
+ SodaUtils.PrintSoda("(*)Browser restart finished.\n")
2927
+ end
2928
+
2916
2929
  test_order += 1
2917
2930
  tmp_result = {}
2918
- test_basename = File.basename(test, ".xml")
2919
2931
  tmp_result['result'] = run(test, false, true, suite_name)
2920
2932
  tmp_result['Test_Order'] = test_order
2921
2933
  tmp_result.merge!(@rep.GetRawResults)
2922
- tmp_result['Real_Test_Name'] = test
2923
- logfile = tmp_result['Test Log File']
2924
-
2934
+
2925
2935
  if (tmp_result['Test Failure Count'].to_i != 0)
2926
2936
  tmp_result['result'] = -1
2927
2937
  elsif (tmp_result['Test JavaScript Error Count'].to_i != 0)
@@ -2932,8 +2942,25 @@ JSCode
2932
2942
  tmp_result['result'] = -1
2933
2943
  end
2934
2944
 
2935
- result[test] = tmp_result
2945
+ tmp_result['Real_Test_Name'] = test
2946
+ test_basename = File.basename(test, ".xml")
2947
+ logfile = tmp_result['Test Log File']
2948
+
2949
+ if (logfile =~ /#{test_basename}-\d+/)
2950
+ logfile =~ /#{test_basename}(-\d+)/
2951
+ ran_test_name = "#{test_basename}#{$1}"
2952
+ ran_test_name << ".xml"
2953
+ else
2954
+ ran_test_name = test
2955
+ end
2956
+
2957
+ result[ran_test_name] = tmp_result
2936
2958
  @rep.ZeroTestResults()
2959
+
2960
+ test_dir = File.dirname(test)
2961
+ if (test_dir !~ /lib/i)
2962
+ test_since_restart += 1
2963
+ end
2937
2964
  end
2938
2965
 
2939
2966
  return result