|
| 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 ExecuteDriverTest < Minitest::Test |
| 24 | + include AppiumLibCoreTest::Mock |
| 25 | + |
| 26 | + def setup |
| 27 | + @core ||= ::Appium::Core.for(Caps.android) |
| 28 | + @driver ||= android_mock_create_session_w3c |
| 29 | + end |
| 30 | + |
| 31 | + def test_batch_no_timeout |
| 32 | + script = <<-SCRIPT |
| 33 | +const status = await driver.status(); |
| 34 | +return status; |
| 35 | + SCRIPT |
| 36 | + |
| 37 | + stub_request(:post, "#{SESSION}/appium/execute_driver") |
| 38 | + .with(body: { script: script, type: 'webdriverio' }.to_json) |
| 39 | + .to_return(headers: HEADER, status: 200, body: { |
| 40 | + value: { result: { build: 'version' }, logs: { log: [], warn: [], error: [] } } |
| 41 | + }.to_json) |
| 42 | + |
| 43 | + r = @driver.execute_driver(script: script, type: 'webdriverio') |
| 44 | + |
| 45 | + assert_requested(:post, "#{SESSION}/appium/execute_driver", times: 1) |
| 46 | + assert_equal({ 'build' => 'version' }, r.result) |
| 47 | + assert_equal({ 'log' => [], 'warn' => [], 'error' => [] }, r.logs) |
| 48 | + end |
| 49 | + |
| 50 | + def test_batch |
| 51 | + script = <<-SCRIPT |
| 52 | +console.warn('warning message'); |
| 53 | + SCRIPT |
| 54 | + |
| 55 | + stub_request(:post, "#{SESSION}/appium/execute_driver") |
| 56 | + .with(body: { script: script, type: 'webdriverio', timeout: 1000 }.to_json) |
| 57 | + .to_return(headers: HEADER, status: 200, body: { |
| 58 | + value: { result: nil, logs: { log: [], warn: ['warning message'], error: [] } } |
| 59 | + }.to_json) |
| 60 | + |
| 61 | + r = @driver.execute_driver(script: script, type: 'webdriverio', timeout_ms: 1000) |
| 62 | + |
| 63 | + assert_requested(:post, "#{SESSION}/appium/execute_driver", times: 1) |
| 64 | + assert_nil(r.result) |
| 65 | + assert_equal({ 'log' => [], 'warn' => ['warning message'], 'error' => [] }, r.logs) |
| 66 | + end |
| 67 | + end # class DeviceLockTest |
| 68 | + end # module W3C |
| 69 | + end # module Device |
| 70 | + end # module Android |
| 71 | +end # class AppiumLibCoreTest |
0 commit comments