browza 0.0.3.2 → 0.0.3.3
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.
- checksums.yaml +4 -4
- data/examples/ex1.rb +10 -3
- data/lib/browza/base/manager.rb +183 -16
- data/lib/browza/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd61a969dc11056dbb1109fc1ef5ee41cc4e7d34
|
4
|
+
data.tar.gz: 89e6c7133d312ecb9bc9d4e44abdd61aea4d38d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b5c35e769e9dd79688810167814f5e2f3ec2d1d5691e7be15b0466647d42c0556ee3792bac2f1c9932296104a436a3dffbc7faa36c07934e4ccc03fd30f8e20
|
7
|
+
data.tar.gz: 194681b280cd0e17e5a490f149344b715ad0d65cea21cf183289c93b3eec813a058553f0d2246b58bd9f53f47ba6a406da215ca99591398c4a14f4c39be08b2e
|
data/examples/ex1.rb
CHANGED
@@ -8,16 +8,23 @@ puts "Creating Chrome Browser!"
|
|
8
8
|
|
9
9
|
|
10
10
|
ENV['SELENIUM_BROWSER']='firefox'
|
11
|
-
|
11
|
+
ENV['SELENIUM_PLATFORM']='local'
|
12
|
+
Browza::Manager.instance.start
|
13
|
+
|
14
|
+
Browza::Manager.instance.addModel('./model.json')
|
15
|
+
|
16
|
+
#Browza::Manager.instance.createBrowser()
|
12
17
|
|
13
18
|
|
14
19
|
puts "Navigate to playground"
|
15
20
|
Browza::Manager.instance.navigate('https://stark-bastion-95510.herokuapp.com/playground')
|
16
21
|
|
17
|
-
Browza::Manager.instance.click("//button[text()='Van Halen']")
|
22
|
+
#Browza::Manager.instance.click("//button[text()='Van Halen']")
|
23
|
+
Browza::Manager.instance.click("page(exPage).get(vh)")
|
18
24
|
|
19
|
-
Browza::Manager.instance.highlight("//button[text()='Van Halen']", 'red')
|
20
25
|
|
26
|
+
#Browza::Manager.instance.highlight("//button[text()='Van Halen']", 'red')
|
27
|
+
Browza::Manager.instance.highlight("page(exPage).get(vh)", 'red')
|
21
28
|
|
22
29
|
puts "PRESS ENTER to Continue .."
|
23
30
|
STDIN.gets
|
data/lib/browza/base/manager.rb
CHANGED
@@ -236,6 +236,8 @@ class Manager
|
|
236
236
|
|
237
237
|
def createBrowser(*p)
|
238
238
|
|
239
|
+
timeout = nil
|
240
|
+
|
239
241
|
if ENV['SELENIUM_RESOLUTION']
|
240
242
|
@logger.debug " SELENIUM_RESOLUTION=#{ENV['SELENIUM_RESOLUTION']}" if @debug
|
241
243
|
_width = ENV['SELENIUM_RESOLUTION'].match(/\s*(\d+)\s*x\s*(\d+)\s*$/)[1].to_s
|
@@ -281,6 +283,10 @@ class Manager
|
|
281
283
|
_height = h[:height]
|
282
284
|
end
|
283
285
|
|
286
|
+
if h.has_key?(:timeout)
|
287
|
+
timeout = h[:timeout]
|
288
|
+
end
|
289
|
+
|
284
290
|
if h.has_key?(:id)
|
285
291
|
_id = h[:id]
|
286
292
|
end
|
@@ -316,7 +322,17 @@ class Manager
|
|
316
322
|
@logger.debug "Selenium::WebDriver.for #{@browserType} (isSymbol: #{@browserType.is_a?(Symbol)})" if @debug
|
317
323
|
|
318
324
|
begin
|
319
|
-
|
325
|
+
if timeout.nil?
|
326
|
+
@drv = Selenium::WebDriver.for @browserType
|
327
|
+
else
|
328
|
+
client = Selenium::WebDriver::Remote::Http::Default.new
|
329
|
+
client.read_timeout = timeout.to_i
|
330
|
+
|
331
|
+
@drv = Selenium::WebDriver.for @browserType, http_client: client
|
332
|
+
|
333
|
+
puts __FILE__ + (__LINE__).to_s + " Set NET::TIMEOUT to #{timeout.to_s}"
|
334
|
+
end
|
335
|
+
|
320
336
|
rescue TypeError
|
321
337
|
@logger.warn __FILE__ + (__LINE__).to_s + " See https://github.com/mozilla/geckodriver/issues/676" if @browserType == :firefox
|
322
338
|
end
|
@@ -411,6 +427,7 @@ class Manager
|
|
411
427
|
|
412
428
|
def goto(url, id=nil)
|
413
429
|
|
430
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " goto(#{url})"
|
414
431
|
rc = false
|
415
432
|
|
416
433
|
if id.nil?
|
@@ -434,6 +451,7 @@ class Manager
|
|
434
451
|
|
435
452
|
if p.is_a?(Array)
|
436
453
|
if p.length == 1
|
454
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " navigate(#{p[0].to_s}"
|
437
455
|
rc = goto(p[0].to_s)
|
438
456
|
elsif p.length == 2
|
439
457
|
rc = goto(p[0], p[1])
|
@@ -788,27 +806,86 @@ class Manager
|
|
788
806
|
return @driverList[0][:drv].execute_script('var s = new Date().toString(); return s')
|
789
807
|
end
|
790
808
|
|
809
|
+
|
810
|
+
def text(_locator, _drv = nil, _timeout = 30)
|
811
|
+
rc = nil
|
812
|
+
|
813
|
+
2.times { |i|
|
814
|
+
|
815
|
+
@driverList.each do |b|
|
816
|
+
begin
|
817
|
+
|
818
|
+
drv = b[:drv]
|
819
|
+
obj = nil
|
820
|
+
drv.switch_to.default_content
|
821
|
+
isDisplayed = Selenium::WebDriver::Wait.new(timeout: _timeout).until {
|
822
|
+
obj = findLocator(_locator, drv)
|
823
|
+
obj.is_a?(Selenium::WebDriver::Element) && obj.displayed? && obj.enabled?
|
824
|
+
}
|
825
|
+
if !obj.nil? && isDisplayed && obj.is_a?(Selenium::WebDriver::Element)
|
826
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " clicked #{_locator}"
|
827
|
+
rc = obj.text
|
828
|
+
end
|
829
|
+
|
830
|
+
break
|
831
|
+
|
832
|
+
|
833
|
+
rescue Selenium::WebDriver::Error::TimeOutError
|
834
|
+
puts __FILE__ + (__LINE__).to_s + " retry: #{i} locator:#{_locator}"
|
835
|
+
|
836
|
+
rescue => ex
|
837
|
+
puts __FILE__ + (__LINE__).to_s + " #{ex.class}"
|
838
|
+
puts "#{ex.class}"
|
839
|
+
puts "Backtrace:\n\t#{ex.backtrace.join("\n\t")}"
|
840
|
+
end
|
841
|
+
end
|
842
|
+
}
|
843
|
+
|
844
|
+
rc
|
845
|
+
end
|
846
|
+
|
847
|
+
|
848
|
+
def _getActionableElement(_locator, drv, _timeout = 30)
|
849
|
+
obj = nil
|
850
|
+
begin
|
851
|
+
drv.switch_to.default_content
|
852
|
+
|
853
|
+
isDisplayed = Selenium::WebDriver::Wait.new(timeout: _timeout).until {
|
854
|
+
obj = findLocator(_locator, drv)
|
855
|
+
obj.is_a?(Selenium::WebDriver::Element) && obj.displayed? && obj.enabled?
|
856
|
+
}
|
857
|
+
|
858
|
+
rescue Selenium::WebDriver::Error::NoSuchElementError
|
859
|
+
;
|
860
|
+
|
861
|
+
rescue Selenium::WebDriver::Error::TimeOutError
|
862
|
+
;
|
863
|
+
end
|
864
|
+
|
865
|
+
obj
|
866
|
+
end
|
867
|
+
|
791
868
|
##
|
792
869
|
# Browza.instance.click('page(sideNav).get(desktop)')
|
793
870
|
##
|
794
|
-
def click(_locator, _drv=nil, _timeout=30)
|
871
|
+
def click(_locator, _drv=nil, _timeout = 30)
|
795
872
|
|
796
873
|
@logger.debug __FILE__ + (__LINE__).to_s + " click(#{_locator})"
|
797
874
|
rc = false
|
798
875
|
|
799
876
|
@driverList.each do |b|
|
800
877
|
begin
|
801
|
-
drv=b[:drv]
|
802
|
-
|
878
|
+
drv = b[:drv]
|
803
879
|
obj = nil
|
804
|
-
|
805
|
-
# obj = findLocator(_locator, drv)
|
880
|
+
drv.switch_to.default_content
|
806
881
|
|
807
882
|
isDisplayed = Selenium::WebDriver::Wait.new(timeout: _timeout).until {
|
808
883
|
obj = findLocator(_locator, drv)
|
809
884
|
obj.is_a?(Selenium::WebDriver::Element) && obj.displayed? && obj.enabled?
|
810
885
|
}
|
811
886
|
|
887
|
+
# obj = _getActionableElement(_locator, drv, _timeout)
|
888
|
+
|
812
889
|
# drv.action.move_to(obj).perform
|
813
890
|
scrollElementIntoMiddle = "var viewPortHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);" +
|
814
891
|
"var elementTop = arguments[0].getBoundingClientRect().top;" +
|
@@ -821,13 +898,13 @@ class Manager
|
|
821
898
|
|
822
899
|
@logger.debug __FILE__ + (__LINE__).to_s + " [click]: obj => #{obj.class} : #{isDisplayed}"
|
823
900
|
|
824
|
-
if !obj.nil? &&
|
901
|
+
if !obj.nil? && obj.is_a?(Selenium::WebDriver::Element) && obj.displayed?
|
825
902
|
@logger.debug __FILE__ + (__LINE__).to_s + " clicked #{_locator}"
|
826
903
|
obj.click
|
827
904
|
rc = true
|
828
905
|
end
|
829
906
|
rescue => ex
|
830
|
-
@logger.debug __FILE__ + (__LINE__).to_s + " #{ex.class}"
|
907
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " #{ex.class} : #{_locator}"
|
831
908
|
@logger.debug "Backtrace:\n\t#{ex.backtrace.join("\n\t")}"
|
832
909
|
end
|
833
910
|
end
|
@@ -842,9 +919,15 @@ class Manager
|
|
842
919
|
|
843
920
|
def highlight(_locator, color='red', _drv=nil, _timeout=30)
|
844
921
|
rc = false
|
845
|
-
rgb=nil
|
922
|
+
rgb = nil
|
923
|
+
obj = nil
|
924
|
+
|
925
|
+
if _locator.is_a?(Selenium::WebDriver::Element)
|
926
|
+
obj = _locator
|
927
|
+
else
|
928
|
+
obj = findLocator(_locator)
|
929
|
+
end
|
846
930
|
|
847
|
-
obj = findLocator(_locator)
|
848
931
|
if !obj.nil?
|
849
932
|
if color.match(/\s*blue/i)
|
850
933
|
rgb='rgb(0, 0, 255)'
|
@@ -898,7 +981,13 @@ class Manager
|
|
898
981
|
rc = false
|
899
982
|
|
900
983
|
# obj = getElement(findLocator(_locator), _drv, _timeout)
|
901
|
-
|
984
|
+
|
985
|
+
if _locator.match(/(active|focused)/i)
|
986
|
+
obj = @drv.switch_to.active_element
|
987
|
+
else
|
988
|
+
obj = findLocator(_locator)
|
989
|
+
end
|
990
|
+
|
902
991
|
if !obj.nil?
|
903
992
|
|
904
993
|
if _text.match(/\s*__CLEAR__\s*$/i)
|
@@ -931,12 +1020,78 @@ class Manager
|
|
931
1020
|
rc
|
932
1021
|
end
|
933
1022
|
|
1023
|
+
def type!(data)
|
1024
|
+
rc = { :length => nil, :comment => nil, :data => data }
|
1025
|
+
|
1026
|
+
drv = Browza::Manager.instance.getDriver()
|
1027
|
+
|
1028
|
+
if drv.is_a?(Selenium::WebDriver::Driver)
|
1029
|
+
obj = drv.switch_to.active_element
|
1030
|
+
|
1031
|
+
if obj.is_a?(Selenium::WebDriver::Element) && Browza::Manager.instance.isVisible?(obj)
|
1032
|
+
|
1033
|
+
Browza::Manager.instance.highlight(obj)
|
1034
|
+
|
1035
|
+
begin
|
1036
|
+
jsCmd = "hlt = function(c) { arguments[0].value = '#{data}'; }; return hlt(arguments[0]);"
|
1037
|
+
jsCmd = "return arguments[0].value = '#{data}'"
|
1038
|
+
puts __FILE__ + (__LINE__).to_s + " Data.lines : #{data.lines.count}"
|
1039
|
+
if data.lines.count > 1
|
1040
|
+
jsCmd = "return arguments[0].value = '#{data.gsub("\n", "\t")}'"
|
1041
|
+
end
|
1042
|
+
drv.execute_script(jsCmd, obj)
|
1043
|
+
rc[:length] = data.length
|
1044
|
+
rc[:comment] = 'JSDOM'
|
1045
|
+
|
1046
|
+
rescue Selenium::WebDriver::Error::JavascriptError
|
1047
|
+
Browza::Manager.instance.type('focused', data)
|
1048
|
+
rc[:comment] = 'Typed:JavaScriptError'
|
1049
|
+
rc[:length] = data.length
|
1050
|
+
|
1051
|
+
rescue Selenium::WebDriver::Error::UnknownError => ex
|
1052
|
+
puts "#{ex.class} : #{ex.message.to_s}"
|
1053
|
+
|
1054
|
+
if ex.message.to_s.match(/SyntaxError: Invalid or unexpected token/)
|
1055
|
+
rc[:comment] = "execute_script::SyntaxError - unexpected token"
|
1056
|
+
puts __FILE__ + (__LINE__).to_s + " Invalid Cmd => #{jsCmd}"
|
1057
|
+
else
|
1058
|
+
rc[:comment] = ex.class.to_s
|
1059
|
+
puts "Backtrace:\n\t#{ex.backtrace.join("\n\t")}"
|
1060
|
+
puts "Data => #{data}";
|
1061
|
+
end
|
1062
|
+
|
1063
|
+
Browza::Manager.instance.type('focused', data)
|
1064
|
+
|
1065
|
+
rc[:length] = data.length
|
1066
|
+
|
1067
|
+
|
1068
|
+
end
|
1069
|
+
|
1070
|
+
end
|
1071
|
+
end
|
1072
|
+
|
1073
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " type!(#{data}) : rc:#{rc}"
|
1074
|
+
rc
|
1075
|
+
end
|
1076
|
+
|
934
1077
|
|
1078
|
+
# TODO: Proper handling of _timeout, instead of hack to globalize @defaultTimeout.
|
935
1079
|
def isNotDisplayed?(_locator, _timeout=10)
|
936
|
-
|
1080
|
+
rc = false
|
1081
|
+
_saveDefault = @defaultTimeout
|
1082
|
+
|
1083
|
+
@defaultTimeout = _timeout
|
1084
|
+
begin
|
1085
|
+
rc = !displayed?(_locator, getDriver(), _timeout)
|
1086
|
+
rescue => ex
|
1087
|
+
;
|
1088
|
+
end
|
1089
|
+
|
1090
|
+
@defaultTimeout = _saveDefault
|
1091
|
+
rc
|
937
1092
|
end
|
938
1093
|
|
939
|
-
def displayed?(_locator, _drv=nil, _timeout=30)
|
1094
|
+
def displayed?(_locator, _drv=nil, _timeout = 30)
|
940
1095
|
obj = findLocator(_locator)
|
941
1096
|
obj.is_a?(Selenium::WebDriver::Element) && obj.displayed?
|
942
1097
|
end
|
@@ -991,10 +1146,22 @@ class Manager
|
|
991
1146
|
|
992
1147
|
def isVisible?(_locator, expected = true, _timeout = 30)
|
993
1148
|
obj = nil
|
994
|
-
|
995
|
-
|
996
|
-
|
1149
|
+
|
1150
|
+
|
1151
|
+
@drv.switch_to.default_content
|
1152
|
+
|
1153
|
+
if _locator.is_a?(Selenium::WebDriver::Element)
|
1154
|
+
obj = _locator
|
1155
|
+
|
1156
|
+
rc = Selenium::WebDriver::Wait.new(timeout: _timeout).until {
|
1157
|
+
obj.displayed?
|
1158
|
+
}
|
1159
|
+
else
|
1160
|
+
rc = Selenium::WebDriver::Wait.new(timeout: _timeout).until {
|
1161
|
+
obj = findLocator(_locator, @drv)
|
1162
|
+
obj.is_a?(Selenium::WebDriver::Element) && obj.displayed?
|
997
1163
|
}
|
1164
|
+
end
|
998
1165
|
|
999
1166
|
@logger.debug __FILE__ + (__LINE__).to_s + " isVisible?(#{_locator}) : #{rc}"
|
1000
1167
|
rc == expected
|
data/lib/browza/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: browza
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.3.
|
4
|
+
version: 0.0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- H20Dragon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|