Module: Appium::Core::Device
- Extended by:
- Forwardable
- Defined in:
- lib/appium_lib_core/device.rb,
lib/appium_lib_core/device/app_state.rb,
lib/appium_lib_core/device/screen_record.rb,
lib/appium_lib_core/device/image_comparison.rb,
lib/appium_lib_core/device/clipboard_content_type.rb
Defined Under Namespace
Modules: Clipboard, ImageComparison Classes: AppState, ScreenRecord
Class Method Summary collapse
-
.add_app_management ⇒ Object
rubocop:disable Metrics/ParameterLists,Metrics/PerceivedComplexity,Metrics/CyclomaticComplexity.
- .add_device_lock ⇒ Object
- .add_endpoint_method(method) ⇒ Object
- .add_file_management ⇒ Object
- .add_handling_context ⇒ Object
- .add_ime_actions ⇒ Object
-
.add_keyevent ⇒ Object
rubocop:enable Metrics/ParameterLists,Metrics/PerceivedComplexity,Metrics/CyclomaticComplexity.
- .add_screen_recording ⇒ Object
- .add_touch_actions ⇒ Object
- .create_bridge_command(method) ⇒ Object
- .delegate_driver_method(method) ⇒ Object
-
.delegate_from_appium_driver(method, delegation_target = :driver) ⇒ Object
For ruby_lib compatibility.
- .extend_webdriver_with_forwardable ⇒ Object
- .extended(_mod) ⇒ Object
Instance Method Summary collapse
-
#activate_app(app_id) ⇒ Hash
Activate(Launch) the specified app.
-
#app_installed?(app_id) ⇒ Boolean
Check whether the specified app is installed on the device.
-
#app_strings(language = nil) ⇒ Hash
Return the hash of all localization strings.
-
#available_contexts ⇒ Array<String>
All usable contexts, as an array of strings.
-
#background_app(duration = 0) ⇒ String
Backgrounds the app for a set number of seconds.
-
#close_app ⇒ Object
Close an app on device.
-
#current_context ⇒ String
The context currently being used.
-
#device_locked? ⇒ Object
Check current device status is weather locked or not.
-
#device_time ⇒ Object
Get the time on the device.
-
#get_settings ⇒ Object
Get appium Settings for current test session.
-
#hide_keyboard(close_key = nil, strategy = nil) ⇒ Object
Hide the onscreen keyboard.
-
#ime_activate(ime_name) ⇒ Object
Android only.
-
#ime_activated ⇒ Object
Android only.
-
#ime_active_engine ⇒ Object
Android only.
-
#ime_available_engines ⇒ Object
Android only.
-
#ime_deactivate ⇒ Object
Android only.
-
#install_app(path, replace: nil, timeout: nil, allow_test_packages: nil, use_sdcard: nil, grant_permissions: nil) ⇒ Object
Install the given app onto the device.
-
#keyevent(key, metastate = nil) ⇒ Object
Send keyevent on the device.(Only for Selendroid) developer.android.com/reference/android/view/KeyEvent.html.
-
#launch_app ⇒ Object
Start the simulator and application configured with desired capabilities.
-
#lock(duration = nil) ⇒ String
Lock the device.
-
#long_press_keycode(key, metastate = nil) ⇒ Object
Long press keycode on the device.
-
#press_keycode(key, metastate = nil) ⇒ Object
Press keycode on the device.
-
#pull_file(path) ⇒ Object
Retrieve a file from the device.
-
#pull_folder(path) ⇒ Object
Retrieve a folder from the device.
-
#push_file(path, filedata) ⇒ Object
Place a file in a specific location on the device.
- #remove_app(app_id, keep_data: nil, timeout: nil) ⇒ Object
-
#replace_value(element, *value) ⇒ Object
Replace the value to element directly.
-
#reset ⇒ Object
Reset the device, relaunching the application.
-
#save_viewport_screenshot ⇒ Object
Save screenshot except for status bar while ‘@driver.save_screenshot` save entire screen.
-
#set_context(context) ⇒ Object
Change the context to the given context.
-
#set_immediate_value(element, *value) ⇒ Object
Set the value to element directly.
-
#shake ⇒ Object
Cause the device to shake.
- #stop_and_save_recording_screen(file_path) ⇒ Object
- #stop_recording_screen(remote_path: nil, user: nil, pass: nil, method: 'PUT') ⇒ Object
-
#take_element_screenshot(element, png_path) ⇒ File
Path to the screenshot.
-
#terminate_app(app_id) ⇒ Boolean
Terminate the specified app.
-
#unlock ⇒ Object
Unlock the device.
-
#update_settings(settings) ⇒ Object
Update Appium Settings for current test session.
Class Method Details
.add_app_management ⇒ Object
rubocop:disable Metrics/ParameterLists,Metrics/PerceivedComplexity,Metrics/CyclomaticComplexity
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 |
# File 'lib/appium_lib_core/device.rb', line 611 def add_app_management add_endpoint_method(:launch_app) do def launch_app execute :launch_app end end add_endpoint_method(:close_app) do def close_app execute :close_app end end add_endpoint_method(:close_app) do def close_app execute :close_app end end add_endpoint_method(:reset) do def reset execute :reset end end add_endpoint_method(:app_strings) do def app_strings(language = nil) opts = language ? { language: language } : {} execute :app_strings, {}, opts end end add_endpoint_method(:background_app) do def background_app(duration = 0) execute :background_app, {}, seconds: duration end end add_endpoint_method(:install_app) do def install_app(path, replace: nil, timeout: nil, allow_test_packages: nil, use_sdcard: nil, grant_permissions: nil) args = { appPath: path } args[:options] = {} unless (replace, timeout, allow_test_packages, use_sdcard, ) args[:options][:replace] = replace unless replace.nil? args[:options][:timeout] = timeout unless timeout.nil? args[:options][:allowTestPackages] = allow_test_packages unless allow_test_packages.nil? args[:options][:useSdcard] = use_sdcard unless use_sdcard.nil? args[:options][:grantPermissions] = unless .nil? execute :install_app, {}, args end private def (replace, timeout, allow_test_packages, use_sdcard, ) replace.nil? || timeout.nil? || allow_test_packages.nil? || use_sdcard.nil? || .nil? end end add_endpoint_method(:remove_app) do def remove_app(id, keep_data: nil, timeout: nil) # required: [['appId'], ['bundleId']] args = { appId: id } args[:options] = {} unless keep_data.nil? || timeout.nil? args[:options][:keepData] = keep_data unless keep_data.nil? args[:options][:timeout] = timeout unless timeout.nil? execute :remove_app, {}, args end end add_endpoint_method(:app_installed?) do def app_installed?(app_id) # required: [['appId'], ['bundleId']] execute :app_installed?, {}, bundleId: app_id end end add_endpoint_method(:activate_app) do def activate_app(app_id) # required: [['appId'], ['bundleId']] execute :activate_app, {}, bundleId: app_id end end add_endpoint_method(:terminate_app) do def terminate_app(app_id, timeout: nil) # required: [['appId'], ['bundleId']] # args = { appId: app_id } args[:options] = {} unless timeout.nil? args[:options][:timeout] = timeout unless timeout.nil? execute :terminate_app, {}, args end end add_endpoint_method(:app_state) do def app_state(app_id) # required: [['appId'], ['bundleId']] response = execute :app_state, {}, appId: app_id case response when 0 ::Appium::Core::Device::AppState::NOT_INSTALLED when 1 ::Appium::Core::Device::AppState::NOT_RUNNING when 2 ::Appium::Core::Device::AppState::RUNNING_IN_BACKGROUND_SUSPENDED when 3 ::Appium::Core::Device::AppState::RUNNING_IN_BACKGROUND when 4 ::Appium::Core::Device::AppState::RUNNING_IN_FOREGROUND else ::Appium::Logger.debug("Unexpected status in app_state: #{response}") response end end end end |
.add_device_lock ⇒ Object
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 |
# File 'lib/appium_lib_core/device.rb', line 566 def add_device_lock add_endpoint_method(:lock) do def lock(duration = nil) opts = duration ? { seconds: duration } : {} execute :lock, {}, opts end end add_endpoint_method(:device_locked?) do def device_locked? execute :device_locked? end end add_endpoint_method(:unlock) do def unlock execute :unlock end end end |
.add_endpoint_method(method) ⇒ Object
529 530 531 532 533 534 |
# File 'lib/appium_lib_core/device.rb', line 529 def add_endpoint_method(method) block_given? ? create_bridge_command(method, &Proc.new) : create_bridge_command(method) delegate_driver_method method delegate_from_appium_driver method end |
.add_file_management ⇒ Object
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 |
# File 'lib/appium_lib_core/device.rb', line 587 def add_file_management add_endpoint_method(:push_file) do def push_file(path, filedata) encoded_data = Base64.encode64 filedata execute :push_file, {}, path: path, data: encoded_data end end add_endpoint_method(:pull_file) do def pull_file(path) data = execute :pull_file, {}, path: path Base64.decode64 data end end add_endpoint_method(:pull_folder) do def pull_folder(path) data = execute :pull_folder, {}, path: path Base64.decode64 data end end end |
.add_handling_context ⇒ Object
819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 |
# File 'lib/appium_lib_core/device.rb', line 819 def add_handling_context add_endpoint_method(:within_context) do def within_context(context) existing_context = current_context set_context context if block_given? result = yield set_context existing_context result else set_context existing_context end end end add_endpoint_method(:switch_to_default_context) do def switch_to_default_context set_context nil end end add_endpoint_method(:current_context) do def current_context execute :current_context end end add_endpoint_method(:available_contexts) do def available_contexts # return empty array instead of nil on failure execute(:available_contexts, {}) || [] end end add_endpoint_method(:set_context) do def set_context(context = null) execute :set_context, {}, name: context end end end |
.add_ime_actions ⇒ Object
783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 |
# File 'lib/appium_lib_core/device.rb', line 783 def add_ime_actions add_endpoint_method(:ime_activate) do def ime_activate(ime_name) # from Selenium::WebDriver::Remote::OSS execute :ime_activate_engine, {}, engine: ime_name end end add_endpoint_method(:ime_available_engines) do def ime_available_engines execute :ime_get_available_engines end end add_endpoint_method(:ime_active_engine) do # from Selenium::WebDriver::Remote::OSS def ime_active_engine execute :ime_get_active_engine end end add_endpoint_method(:ime_activated) do # from Selenium::WebDriver::Remote::OSS def ime_activated execute :ime_is_activated end end add_endpoint_method(:ime_deactivate) do # from Selenium::WebDriver::Remote::OSS def ime_deactivate execute :ime_deactivate, {} end end end |
.add_keyevent ⇒ Object
rubocop:enable Metrics/ParameterLists,Metrics/PerceivedComplexity,Metrics/CyclomaticComplexity
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 |
# File 'lib/appium_lib_core/device.rb', line 741 def add_keyevent # Only for Selendroid add_endpoint_method(:keyevent) do def keyevent(key, = nil) args = { keycode: key } args[:metastate] = if execute :keyevent, {}, args end end add_endpoint_method(:press_keycode) do def press_keycode(key, = nil) args = { keycode: key } args[:metastate] = if execute :press_keycode, {}, args end end add_endpoint_method(:long_press_keycode) do def long_press_keycode(key, = nil) args = { keycode: key } args[:metastate] = if execute :long_press_keycode, {}, args end end end |
.add_screen_recording ⇒ Object
860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 |
# File 'lib/appium_lib_core/device.rb', line 860 def add_screen_recording add_endpoint_method(:stop_recording_screen) do def stop_recording_screen(remote_path: nil, user: nil, pass: nil, method: 'PUT') option = ::Appium::Core::Device::ScreenRecord.new( remote_path: remote_path, user: user, pass: pass, method: method ).upload_option params = option.empty? ? {} : { options: option } execute(:stop_recording_screen, {}, params) end end add_endpoint_method(:stop_and_save_recording_screen) do def stop_and_save_recording_screen(file_path) base64data = execute(:stop_recording_screen, {}, {}) File.open(file_path, 'wb') { |f| f << Base64.decode64(base64data) } end end end |
.add_touch_actions ⇒ Object
768 769 770 771 772 773 774 775 776 777 778 779 780 781 |
# File 'lib/appium_lib_core/device.rb', line 768 def add_touch_actions add_endpoint_method(:touch_actions) do def touch_actions(actions) actions = { actions: [actions].flatten } execute :touch_actions, {}, actions end end add_endpoint_method(:multi_touch) do def multi_touch(actions) execute :multi_touch, {}, actions: actions end end end |
.create_bridge_command(method) ⇒ Object
557 558 559 560 561 562 563 564 |
# File 'lib/appium_lib_core/device.rb', line 557 def create_bridge_command(method) ::Appium::Core::Base::Bridge::MJSONWP.class_eval do block_given? ? class_eval(&Proc.new) : define_method(method) { execute method } end ::Appium::Core::Base::Bridge::W3C.class_eval do block_given? ? class_eval(&Proc.new) : define_method(method) { execute method } end end |
.delegate_driver_method(method) ⇒ Object
551 552 553 554 |
# File 'lib/appium_lib_core/device.rb', line 551 def delegate_driver_method(method) return if ::Appium::Core::Base::Driver.method_defined? method ::Appium::Core::Base::Driver.class_eval { def_delegator :@bridge, method } end |
.delegate_from_appium_driver(method, delegation_target = :driver) ⇒ Object
For ruby_lib compatibility
546 547 548 |
# File 'lib/appium_lib_core/device.rb', line 546 def delegate_from_appium_driver(method, delegation_target = :driver) def_delegator delegation_target, method end |
.extend_webdriver_with_forwardable ⇒ Object
537 538 539 540 541 542 |
# File 'lib/appium_lib_core/device.rb', line 537 def extend_webdriver_with_forwardable return if ::Appium::Core::Base::Driver.is_a? Forwardable ::Appium::Core::Base::Driver.class_eval do extend Forwardable end end |
.extended(_mod) ⇒ Object
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 |
# File 'lib/appium_lib_core/device.rb', line 438 def extended(_mod) extend_webdriver_with_forwardable add_endpoint_method(:shake) do def shake execute :shake end end add_endpoint_method(:device_time) do def device_time execute :device_time end end add_endpoint_method(:hide_keyboard) do def hide_keyboard(close_key = nil, strategy = nil) option = {} option[:key] = close_key || 'Done' # default to Done key. option[:strategy] = strategy || :pressKey # default to pressKey execute :hide_keyboard, {}, option end end add_endpoint_method(:take_element_screenshot) do def take_element_screenshot(element, png_path) result = execute :take_element_screenshot, id: element.ref extension = File.extname(png_path).downcase if extension != '.png' ::Appium::Logger.warn 'name used for saved screenshot does not match file type. '\ 'It should end with .png extension' end File.open(png_path, 'wb') { |f| f << result.unpack('m')[0] } end end add_endpoint_method(:set_immediate_value) do def set_immediate_value(element, *value) keys = ::Selenium::WebDriver::Keys.encode(value) execute :set_immediate_value, { id: element.ref }, value: Array(keys) end end add_endpoint_method(:replace_value) do def replace_value(element, *value) keys = ::Selenium::WebDriver::Keys.encode(value) execute :replace_value, { id: element.ref }, value: Array(keys) end end add_endpoint_method(:get_settings) do def get_settings execute :get_settings, {} end end add_endpoint_method(:update_settings) do def update_settings(settings) execute :update_settings, {}, settings: settings end end add_endpoint_method(:save_viewport_screenshot) do def (png_path) extension = File.extname(png_path).downcase if extension != '.png' ::Appium::Logger.warn 'name used for saved screenshot does not match file type. '\ 'It should end with .png extension' end = execute_script('mobile: viewportScreenshot') File.open(png_path, 'wb') { |f| f << .unpack('m')[0] } end end add_keyevent add_touch_actions add_ime_actions add_handling_context add_screen_recording add_app_management add_device_lock add_file_management Core::Device::ImageComparison.extended end |
Instance Method Details
#activate_app(app_id) ⇒ Hash
Activate(Launch) the specified app.
|
|
# File 'lib/appium_lib_core/device.rb', line 133
|
#app_installed?(app_id) ⇒ Boolean
Check whether the specified app is installed on the device
|
|
# File 'lib/appium_lib_core/device.rb', line 111
|
#app_strings(language = nil) ⇒ Hash
Return the hash of all localization strings.
|
|
# File 'lib/appium_lib_core/device.rb', line 160
|
#available_contexts ⇒ Array<String>
Returns All usable contexts, as an array of strings.
|
|
# File 'lib/appium_lib_core/device.rb', line 371
|
#background_app(duration = 0) ⇒ String
Backgrounds the app for a set number of seconds. This is a blocking application
|
|
# File 'lib/appium_lib_core/device.rb', line 180
|
#close_app ⇒ Object
Close an app on device
|
|
# File 'lib/appium_lib_core/device.rb', line 29
|
#current_context ⇒ String
Returns The context currently being used.
|
|
# File 'lib/appium_lib_core/device.rb', line 363
|
#device_locked? ⇒ Object
Check current device status is weather locked or not
|
|
# File 'lib/appium_lib_core/device.rb', line 61
|
#device_time ⇒ Object
Get the time on the device
|
|
# File 'lib/appium_lib_core/device.rb', line 69
|
#get_settings ⇒ Object
Get appium Settings for current test session
|
|
# File 'lib/appium_lib_core/device.rb', line 271
|
#hide_keyboard(close_key = nil, strategy = nil) ⇒ Object
Hide the onscreen keyboard
|
|
# File 'lib/appium_lib_core/device.rb', line 193
|
#ime_activate(ime_name) ⇒ Object
Android only. Make an engine that is available active.
|
|
# File 'lib/appium_lib_core/device.rb', line 313
|
#ime_activated ⇒ Object
Android only. Indicates whether IME input is active at the moment (not if it is available).
|
|
# File 'lib/appium_lib_core/device.rb', line 338
|
#ime_active_engine ⇒ Object
Android only. Get the name of the active IME engine.
|
|
# File 'lib/appium_lib_core/device.rb', line 330
|
#ime_available_engines ⇒ Object
Android only. List all available input engines on the machine.
|
|
# File 'lib/appium_lib_core/device.rb', line 322
|
#ime_deactivate ⇒ Object
Android only. De-activates the currently-active IME engine.
|
|
# File 'lib/appium_lib_core/device.rb', line 346
|
#install_app(path, replace: nil, timeout: nil, allow_test_packages: nil, use_sdcard: nil, grant_permissions: nil) ⇒ Object
Install the given app onto the device
|
|
# File 'lib/appium_lib_core/device.rb', line 83
|
#keyevent(key, metastate = nil) ⇒ Object
Send keyevent on the device.(Only for Selendroid) developer.android.com/reference/android/view/KeyEvent.html
|
|
# File 'lib/appium_lib_core/device.rb', line 208
|
#launch_app ⇒ Object
Start the simulator and application configured with desired capabilities
|
|
# File 'lib/appium_lib_core/device.rb', line 21
|
#lock(duration = nil) ⇒ String
Lock the device
|
|
# File 'lib/appium_lib_core/device.rb', line 169
|
#long_press_keycode(key, metastate = nil) ⇒ Object
Long press keycode on the device. developer.android.com/reference/android/view/KeyEvent.html
|
|
# File 'lib/appium_lib_core/device.rb', line 230
|
#press_keycode(key, metastate = nil) ⇒ Object
Press keycode on the device. developer.android.com/reference/android/view/KeyEvent.html
|
|
# File 'lib/appium_lib_core/device.rb', line 219
|
#pull_file(path) ⇒ Object
Retrieve a file from the device. This can retrieve an absolute path or a path relative to the installed app (iOS only).
|
|
# File 'lib/appium_lib_core/device.rb', line 251
|
#pull_folder(path) ⇒ Object
Retrieve a folder from the device.
|
|
# File 'lib/appium_lib_core/device.rb', line 262
|
#push_file(path, filedata) ⇒ Object
Place a file in a specific location on the device.
|
|
# File 'lib/appium_lib_core/device.rb', line 241
|
#remove_app(app_id, keep_data: nil, timeout: nil) ⇒ Object
|
|
# File 'lib/appium_lib_core/device.rb', line 99
|
#replace_value(element, *value) ⇒ Object
Replace the value to element directly
|
|
# File 'lib/appium_lib_core/device.rb', line 305
|
#reset ⇒ Object
Reset the device, relaunching the application.
|
|
# File 'lib/appium_lib_core/device.rb', line 37
|
#save_viewport_screenshot ⇒ Object
Save screenshot except for status bar while ‘@driver.save_screenshot` save entire screen.
|
|
# File 'lib/appium_lib_core/device.rb', line 279
|
#set_context(context) ⇒ Object
Change the context to the given context.
|
|
# File 'lib/appium_lib_core/device.rb', line 354
|
#set_immediate_value(element, *value) ⇒ Object
Set the value to element directly
|
|
# File 'lib/appium_lib_core/device.rb', line 297
|
#shake ⇒ Object
Cause the device to shake
|
|
# File 'lib/appium_lib_core/device.rb', line 45
|
#stop_and_save_recording_screen(file_path) ⇒ Object
|
|
# File 'lib/appium_lib_core/device.rb', line 423
|
#stop_recording_screen(remote_path: nil, user: nil, pass: nil, method: 'PUT') ⇒ Object
|
|
# File 'lib/appium_lib_core/device.rb', line 406
|
#take_element_screenshot(element, png_path) ⇒ File
Returns Path to the screenshot.
|
|
# File 'lib/appium_lib_core/device.rb', line 396
|
#terminate_app(app_id) ⇒ Boolean
Terminate the specified app.
|
|
# File 'lib/appium_lib_core/device.rb', line 120
|
#unlock ⇒ Object
Unlock the device
|
|
# File 'lib/appium_lib_core/device.rb', line 53
|
#update_settings(settings) ⇒ Object
Update Appium Settings for current test session
|
|
# File 'lib/appium_lib_core/device.rb', line 288
|