soda 1.4.2 → 1.4.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1873,39 +1873,15 @@ class Soda
1873
1873
  result = nil
1874
1874
 
1875
1875
  if (event['content'].length > 0)
1876
- if (Watir::Browser.default == 'firefox')
1877
- # Executing javascript from within the firefox window context
1878
- # (injection) requires firebug, for now.
1879
- toExec = "";
1880
- if (event.key?('addUtils') && (getStringBool(event['addUtils'])))
1881
- event['content'] = SodaUtils::getSodaJS() + event['content'];
1882
- end
1883
-
1884
- escapedContent = event['content'].gsub(/\\/, '\\').gsub(/"/, '\"');
1885
-
1886
- toExec = <<JSCode
1887
- if (typeof window.Firebug != "undefined") {
1888
- window.TabWatcher.watchBrowser(window.FirebugChrome.getCurrentBrowser());
1889
- window.Firebug.minimizeBar();
1890
- window.Firebug.CommandLine.evaluateInWebPage("#{escapedContent}", browser.contentDocument.defaultView);
1891
- window.Firebug.closeFirebug();
1892
- }
1893
- JSCode
1894
-
1895
- result = @browser.execute_script(toExec)
1896
- else
1897
- escapedContent = event['content'].gsub(/\\/, '\\').gsub(/"/, '\"')
1898
- toExec = 'browser.document.parentWindow.execScript("' + escapedContent + '")'
1899
- result = @browser.execute_script(event['content'])
1900
- end
1901
- result = result.to_s()
1902
- PrintDebug("JavaScript Results: \"#{result}\"\n")
1876
+ addUtils = event.key?('addUtils') && (getStringBool(event['addUtils']))
1877
+ result = SodaUtils.execute_script(event['content'], addUtils, @browser, @rep)
1903
1878
  else
1904
1879
  @rep.log("No javascript source content found!", SodaUtils::ERROR)
1905
1880
  return -1
1906
1881
  end
1907
1882
 
1908
1883
  CheckJavaScriptErrors()
1884
+ return result;
1909
1885
  end
1910
1886
 
1911
1887
  ###############################################################################
@@ -2638,7 +2614,7 @@ JSCode
2638
2614
  e_dump = SodaUtils.DumpEvent(event)
2639
2615
  @rep.log("No Element found for event!\n",
2640
2616
  SodaUtils::ERROR)
2641
- @rep.log("Event Dump for unfound element: #{e_dump}!\n",
2617
+ @rep.log("Event Dump for unfound element: #{e_dump}!\n",
2642
2618
  SodaUtils::EVENT)
2643
2619
  end
2644
2620
  else
@@ -2950,7 +2926,7 @@ JSCode
2950
2926
  result = {}
2951
2927
  tests = []
2952
2928
  suite_name = File.basename(suitefile, ".xml")
2953
-
2929
+
2954
2930
  print "Running Suite: #{suitefile}\n"
2955
2931
 
2956
2932
  begin
@@ -2982,7 +2958,7 @@ JSCode
2982
2958
  end
2983
2959
  end
2984
2960
  end
2985
-
2961
+
2986
2962
  fd.close()
2987
2963
  rescue Exception => e
2988
2964
  SodaUtils.PrintSoda(e.message, SodaUtils::ERROR)
@@ -1,4 +1,4 @@
1
- <soda>
1
+ <soda>
2
2
  <!--
3
3
  Copyright (c) 2010, SugarCRM, Inc.
4
4
  All rights reserved.
@@ -59,6 +59,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59
59
  </accessor_attributes>
60
60
  </wait>
61
61
 
62
+ <sugarwait>
63
+ <accessor_attributes>
64
+ <accessor type="integer">timeout</accessor>
65
+ <accessor type="string">condition</accessor>
66
+ </accessor_attributes>
67
+ </sugarwait>
68
+
62
69
  <puts>
63
70
  <accessor_attributes>
64
71
  <accessor type="string">text</accessor>
@@ -748,65 +748,26 @@ def SodaUtils.IEConvertHref(event, url)
748
748
  end
749
749
 
750
750
  ###############################################################################
751
- # WaitSugarAjaxDone -- function
752
- # This function waits to make sure that sugar has finished all ajax
753
- # actions.
751
+ # execute_script -- function
752
+ # Executes given javascript in the browser
754
753
  #
755
754
  # Input:
755
+ # script: javascript string to be executed
756
756
  # browser: This is a watir browser object.
757
757
  # reportobj: This is an active SodaReporter object.
758
758
  #
759
759
  # Returns:
760
- # -1 on error else 0.
761
- #
762
- # Notes:
763
- # I had to split up how Windows OS finds the windows, because Watir's
764
- # browser.url() method returns '' every time if there are more then
765
- # one window open. This is not the cause it Linux, as linux seems to
766
- # know what the current active browser is and returns the expected url.
760
+ # -1 on error else the javascript result.
767
761
  #
768
762
  ###############################################################################
769
- def SodaUtils.WaitSugarAjaxDone(browser, reportobj)
770
- done = false
771
- result = 0
772
- undef_count = 0
773
- url = browser.url()
774
- os = ""
775
- str_res = ""
776
- t1 = nil
777
- t2 = nil
778
-
779
- os = GetOsType()
780
-
781
- linux_js = <<JAVA
782
- var windows = getWindows();
783
- var win_count = windows.length -1;
784
- var current_browser_id = -1;
785
- var result = "undefined";
786
-
787
- for (var i = 0; i <= win_count; i++) {
788
- var tmp_win = windows[i];
789
- var tmp_url = tmp_win.getBrowser().contentDocument.URL;
790
-
791
- if (tmp_url == "#{url}") {
792
- current_browser_id = i;
793
- break;
794
- }
795
- }
796
- JAVA
797
-
798
- other_js = <<JAVA
799
- var current_browser_id = 0;
800
- JAVA
801
-
802
- if (os =~ /linux/i)
803
- js = "#{linux_js}\n"
804
- else
805
- js = "#{other_js}\n"
806
- end
807
-
808
- js += <<JAVA
809
- current_browser_id = 0;
763
+ def SodaUtils.execute_script(script, addUtils, browser, rep)
764
+ result = nil
765
+
766
+ if (script.length > 0)
767
+ script = script.gsub(/[\n\r]/, "")
768
+ escapedContent = script.gsub(/\\/, '\\').gsub(/"/, '\"')
769
+ js = <<JSCode
770
+ current_browser_id = 0;
810
771
  if (current_browser_id > -1) {
811
772
  var target = getWindows()[current_browser_id];
812
773
  var browser = target.getBrowser();
@@ -819,31 +780,67 @@ if (current_browser_id > -1) {
819
780
  if (tmp != null) {
820
781
  doc.body.removeChild(tmp);
821
782
  }
822
-
823
- d.setAttribute("id", "Sodahack");
824
- var src = "if (typeof SUGAR == 'undefined') {\n";
825
- src += " document.soda_sugar_done = 'undefined';\n";
826
- src += "} else {\n";
827
- src += " document.soda_sugar_done = SUGAR.util.ajaxCallInProgress();\n";
828
- src += "}";
829
783
 
784
+ d.setAttribute("id", "Sodahack");
785
+ var src = "document.soda_js_result = (function(){#{escapedContent}})()";
830
786
  d.innerHTML = src;
831
787
  doc.body.appendChild(d);
832
- print(doc.soda_sugar_done);
833
- result = doc.soda_sugar_done;
788
+ print(doc.soda_js_result);
789
+ result = doc.soda_js_result;
834
790
  } else {
835
- result = "undefined";
791
+ result = "No Browser to use";
836
792
  }
837
-
838
793
  print(result);
839
- JAVA
794
+ JSCode
795
+
796
+ #Now actually execute the js in the browser
797
+ result = browser.js_eval(js)
798
+ result = result.chomp()
799
+ else
800
+ result = "No script passed"
801
+ end
802
+
803
+ return result
804
+ end
805
+
806
+
807
+
808
+
809
+ ###############################################################################
810
+ # WaitSugarAjaxDone -- function
811
+ # This function waits to make sure that sugar has finished all ajax
812
+ # actions.
813
+ #
814
+ # Input:
815
+ # browser: This is a watir browser object.
816
+ # reportobj: This is an active SodaReporter object.
817
+ #
818
+ # Returns:
819
+ # -1 on error else 0.
820
+ #
821
+ # Notes:
822
+ # I had to split up how Windows OS finds the windows, because Watir's
823
+ # browser.url() method returns '' every time if there are more then
824
+ # one window open. This is not the cause it Linux, as linux seems to
825
+ # know what the current active browser is and returns the expected url.
826
+ #
827
+ ###############################################################################
828
+ def SodaUtils.WaitSugarAjaxDone(browser, reportobj)
829
+ done = false
830
+ result = 0
831
+ undef_count = 0
832
+ url = browser.url()
833
+ os = ""
834
+ str_res = ""
835
+ t1 = nil
836
+ t2 = nil
840
837
 
838
+ js = "if(SUGAR && SUGAR.util && !SUGAR.util.ajaxCallInProgress()) return 'true'; else return 'false';"
841
839
  reportobj.log("Calling: SugarWait.\n")
842
840
  t1 = Time.now()
843
841
 
844
- for i in 0..300
845
- tmp = browser.js_eval(js)
846
- tmp = tmp.chomp()
842
+ for i in 0..60
843
+ tmp = SodaUtils.execute_script(js, false, browser, reportobj)
847
844
 
848
845
  case (tmp)
849
846
  when /false/i
@@ -861,7 +858,7 @@ JAVA
861
858
  SodaUtils::WARN)
862
859
  end
863
860
 
864
- if (tmp == false)
861
+ if (tmp == true)
865
862
  done = true
866
863
  break
867
864
  end
@@ -1,4 +1,4 @@
1
1
  require 'Soda'
2
2
 
3
- SODA_GEM_VERSION = "1.4.2"
3
+ SODA_GEM_VERSION = "1.4.3"
4
4
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soda
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 4
9
- - 2
10
- version: 1.4.2
9
+ - 3
10
+ version: 1.4.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Trampus Richmond
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-10 00:00:00 Z
18
+ date: 2011-05-25 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: firewatir