@@ -156,7 +156,7 @@ def initialize(opts = {}, global_driver = false)
156
156
157
157
$driver&.driver_quit if global_driver
158
158
159
- raise 'opts must be a hash' unless opts . is_a? Hash
159
+ raise ArgumentError , 'opts must be a hash' unless opts . is_a? Hash
160
160
161
161
@core = ::Appium ::Core . for ( opts )
162
162
extend ::Appium ::Core ::Device
@@ -329,7 +329,7 @@ def automation_name_is_xcuitest?
329
329
# action.click(element).perform # The `click` is a part of `PointerActions`
330
330
#
331
331
def action
332
- @driver . action
332
+ @driver & .action
333
333
end
334
334
335
335
# Returns the server's version info
@@ -384,12 +384,12 @@ def appium_client_version
384
384
#
385
385
# @return [String] APP_PATH as an absolute path
386
386
def self . absolute_app_path ( opts )
387
- raise 'opts must be a hash' unless opts . is_a? Hash
387
+ raise ArgumentError , 'opts must be a hash' unless opts . is_a? Hash
388
388
389
389
# FIXME: 'caps' and 'app' will be correct
390
390
caps = opts [ :caps ] || opts [ 'caps' ] || { }
391
391
app_path = caps [ :app ] || caps [ 'app' ]
392
- raise 'absolute_app_path invoked and app is not set!' if app_path . nil? || app_path . empty?
392
+ raise ArgumentError , 'absolute_app_path invoked and app is not set!' if app_path . nil? || app_path . empty?
393
393
# Sauce storage API. http://saucelabs.com/docs/rest#storage
394
394
return app_path if app_path . start_with? 'sauce-storage:'
395
395
return app_path if app_path =~ URI ::DEFAULT_PARSER . make_regexp # public URL for Sauce
@@ -431,7 +431,7 @@ def restart
431
431
# @param png_save_path [String] the full path to save the png
432
432
# @return [File]
433
433
def screenshot ( png_save_path )
434
- @driver . save_screenshot png_save_path
434
+ @driver & .save_screenshot png_save_path
435
435
end
436
436
437
437
# Takes a png screenshot of particular element's area
@@ -445,7 +445,7 @@ def screenshot(png_save_path)
445
445
# @param [String] png_save_path the full path to save the png
446
446
# @return [File]
447
447
def element_screenshot ( element , png_save_path )
448
- @driver . take_element_screenshot element , png_save_path
448
+ @driver & .take_element_screenshot element , png_save_path
449
449
nil
450
450
end
451
451
@@ -469,6 +469,9 @@ def driver_quit
469
469
# size.height #=> Integer
470
470
#
471
471
def window_size
472
+ # maybe exception is expected as no driver created
473
+ raise NoDriverInstanceError if @driver . nil?
474
+
472
475
@driver . window_size
473
476
end
474
477
@@ -484,6 +487,8 @@ def window_size
484
487
# size.y #=> Integer
485
488
#
486
489
def window_rect
490
+ raise NoDriverInstanceError if @driver . nil?
491
+
487
492
@driver . window_rect
488
493
end
489
494
@@ -555,7 +560,7 @@ def set_implicit_wait(wait)
555
560
556
561
# Set implicit wait to zero.
557
562
def no_wait
558
- @driver . manage . timeouts . implicit_wait = 0
563
+ @driver & .manage & .timeouts & .implicit_wait = 0
559
564
end
560
565
561
566
# Set implicit wait. Default to @default_wait.
@@ -570,7 +575,7 @@ def no_wait
570
575
# @return [void]
571
576
def set_wait ( timeout = nil )
572
577
timeout = @default_wait if timeout . nil?
573
- @driver . manage . timeouts . implicit_wait = timeout
578
+ @driver & .manage & .timeouts & .implicit_wait = timeout
574
579
end
575
580
576
581
# Returns existence of element.
@@ -589,9 +594,9 @@ def exists(pre_check = 0, post_check = @default_wait)
589
594
# do not uset set_wait here.
590
595
# it will cause problems with other methods reading the default_wait of 0
591
596
# which then gets converted to a 1 second wait.
592
- @driver . manage . timeouts . implicit_wait = pre_check
597
+ @driver & .manage & .timeouts & .implicit_wait = pre_check
593
598
# the element exists unless an error is raised.
594
- exists = true
599
+ exists = true
595
600
596
601
begin
597
602
yield # search for element
@@ -600,7 +605,7 @@ def exists(pre_check = 0, post_check = @default_wait)
600
605
end
601
606
602
607
# restore wait
603
- @driver . manage . timeouts . implicit_wait = post_check if post_check != pre_check
608
+ @driver & .manage & .timeouts & .implicit_wait = post_check if post_check != pre_check
604
609
605
610
exists
606
611
end
@@ -610,6 +615,8 @@ def exists(pre_check = 0, post_check = @default_wait)
610
615
# @param [*args] args The args to pass to the script
611
616
# @return [Object]
612
617
def execute_script ( script , *args )
618
+ raise NoDriverInstanceError if @driver . nil?
619
+
613
620
@driver . execute_script script , *args
614
621
end
615
622
@@ -618,6 +625,8 @@ def execute_script(script, *args)
618
625
###
619
626
# Get the window handles of open browser windows
620
627
def execute_async_script ( script , *args )
628
+ raise NoDriverInstanceError if @driver . nil?
629
+
621
630
@driver . execute_async_script script , *args
622
631
end
623
632
@@ -650,41 +659,59 @@ def execute_async_script(script, *args)
650
659
# r.logs #=> The `logs` key part as `{'log' => [], 'warn' => [], 'error' => []}`
651
660
#
652
661
def execute_driver ( script : '' , type : 'webdriverio' , timeout_ms : nil )
662
+ raise NoDriverInstanceError if @driver . nil?
663
+
653
664
@driver . execute_driver ( script : script , type : type , timeout_ms : timeout_ms )
654
665
end
655
666
656
667
def window_handles
668
+ raise NoDriverInstanceError if @driver . nil?
669
+
657
670
@driver . window_handles
658
671
end
659
672
660
673
# Get the current window handle
661
674
def window_handle
675
+ raise NoDriverInstanceError if @driver . nil?
676
+
662
677
@driver . window_handle
663
678
end
664
679
665
680
def navigate
681
+ raise NoDriverInstanceError if @driver . nil?
682
+
666
683
@driver . navigate
667
684
end
668
685
669
686
def manage
687
+ raise NoDriverInstanceError if @driver . nil?
688
+
670
689
@driver . manage
671
690
end
672
691
673
692
def get ( url )
693
+ raise NoDriverInstanceError if @driver . nil?
694
+
674
695
@driver . get ( url )
675
696
end
676
697
677
698
def current_url
699
+ raise NoDriverInstanceError if @driver . nil?
700
+
678
701
@driver . current_url
679
702
end
680
703
681
704
def title
705
+ raise NoDriverInstanceError if @driver . nil?
706
+
682
707
@driver . title
683
708
end
684
709
685
710
# @return [TargetLocator]
686
711
# @see TargetLocator
687
712
def switch_to
713
+ raise NoDriverInstanceError if @driver . nil?
714
+
688
715
@driver . switch_to
689
716
end
690
717
###
@@ -712,6 +739,8 @@ def switch_to
712
739
# @param [*args] args The args to use
713
740
# @return [Array<Element>] Array is empty when no elements are found.
714
741
def find_elements ( *args )
742
+ raise NoDriverInstanceError if @driver . nil?
743
+
715
744
@driver . find_elements ( *args )
716
745
end
717
746
@@ -728,6 +757,8 @@ def find_elements(*args)
728
757
# @param [*args] args The args to use
729
758
# @return [Element]
730
759
def find_element ( *args )
760
+ raise NoDriverInstanceError if @driver . nil?
761
+
731
762
@driver . find_element ( *args )
732
763
end
733
764
@@ -743,6 +774,8 @@ def find_element(*args)
743
774
# @driver.find_element_by_image './test/functional/data/test_element_image.png'
744
775
#
745
776
def find_element_by_image ( png_img_path )
777
+ raise NoDriverInstanceError if @driver . nil?
778
+
746
779
@driver . find_element_by_image ( png_img_path )
747
780
end
748
781
@@ -758,6 +791,8 @@ def find_element_by_image(png_img_path)
758
791
# @driver.find_elements_by_image ['./test/functional/data/test_element_image.png']
759
792
#
760
793
def find_elements_by_image ( png_img_paths )
794
+ raise NoDriverInstanceError if @driver . nil?
795
+
761
796
@driver . find_elements_by_image ( png_img_paths )
762
797
end
763
798
@@ -771,6 +806,8 @@ def find_elements_by_image(png_img_paths)
771
806
# @option opts [Float] :altitude the altitude, defaulting to 75
772
807
# @return [Selenium::WebDriver::Location] the location constructed by the selenium webdriver
773
808
def set_location ( opts = { } )
809
+ raise NoDriverInstanceError if @driver . nil?
810
+
774
811
latitude = opts . fetch ( :latitude )
775
812
longitude = opts . fetch ( :longitude )
776
813
altitude = opts . fetch ( :altitude , 75 )
@@ -794,10 +831,13 @@ def set_location(opts = {})
794
831
# # 'appium:anotherEvent' => 1572959315}
795
832
#
796
833
def log_event ( vendor :, event :)
834
+ raise NoDriverInstanceError if @driver . nil?
835
+
797
836
@driver . logs . event vendor : vendor , event : event
798
837
end
799
838
800
839
def log_event = ( log_event )
840
+ raise if @driver . nil?
801
841
unless log_event . is_a? ( Hash )
802
842
raise ::Appium ::Core ::Error ::ArgumentError ( 'log_event should be Hash like { vendor: "appium", event: "funEvent"}' )
803
843
end
@@ -817,6 +857,8 @@ def log_event=(log_event)
817
857
# log_events #=> {'commands' => [{'cmd' => 123455, ....}], 'startTime' => 1572954894127, }
818
858
#
819
859
def log_events ( type = nil )
860
+ raise NoDriverInstanceError if @driver . nil?
861
+
820
862
@driver . logs . events ( type )
821
863
end
822
864
0 commit comments