|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +require 'test_helper' |
| 16 | +require 'webmock/minitest' |
| 17 | + |
| 18 | +# $ rake test:unit TEST=test/unit/android/device/w3c/commands_test.rb |
| 19 | +class AppiumLibCoreTest |
| 20 | + module Android |
| 21 | + module Device |
| 22 | + module W3C |
| 23 | + class ExecuteCDPAndroidTest < Minitest::Test |
| 24 | + include AppiumLibCoreTest::Mock |
| 25 | + def test_execute_cdp |
| 26 | + @core = ::Appium::Core.for(Caps.android) |
| 27 | + @driver = android_mock_create_session_w3c |
| 28 | + |
| 29 | + stub_request(:post, "#{SESSION}/goog/cdp/execute") |
| 30 | + .with(body: { cmd: 'Page.captureScreenshot', params: { quality: 50, format: 'jpeg' } }.to_json) |
| 31 | + .to_return(headers: HEADER, status: 200, body: { value: {} }.to_json) |
| 32 | + |
| 33 | + @driver.execute_cdp 'Page.captureScreenshot', quality: 50, format: 'jpeg' |
| 34 | + |
| 35 | + assert_requested(:post, "#{SESSION}/goog/cdp/execute", times: 1) |
| 36 | + end |
| 37 | + end |
| 38 | + |
| 39 | + class ExecuteCDPChromeTest < Minitest::Test |
| 40 | + include AppiumLibCoreTest::Mock |
| 41 | + def test_execute_cdp_chrome |
| 42 | + @core = ::Appium::Core.for(Caps.android) |
| 43 | + @driver = android_chrome_mock_create_session_w3c |
| 44 | + |
| 45 | + stub_request(:post, "#{SESSION}/goog/cdp/execute") |
| 46 | + .with(body: { cmd: 'Emulation.setTimezoneOverride', params: { timezoneId: 'Asia/Tokyo' } }.to_json) |
| 47 | + .to_return(headers: HEADER, status: 200, body: { value: {} }.to_json) |
| 48 | + |
| 49 | + @driver.execute_cdp 'Emulation.setTimezoneOverride', 'timezoneId': 'Asia/Tokyo' |
| 50 | + |
| 51 | + assert_requested(:post, "#{SESSION}/goog/cdp/execute", times: 1) |
| 52 | + end |
| 53 | + end |
| 54 | + end # module W3C |
| 55 | + end # module Device |
| 56 | + end # module Android |
| 57 | +end # class AppiumLibCoreTest |
0 commit comments