|
| 1 | +require 'test_helper' |
| 2 | +require 'webmock/minitest' |
| 3 | +require 'base64' |
| 4 | + |
| 5 | +# $ rake test:unit TEST=test/unit/android/device/mjsonwp/commands_test.rb |
| 6 | +class AppiumLibCoreTest |
| 7 | + module Android |
| 8 | + module Device |
| 9 | + module MJSONWP |
| 10 | + class AppManagementTest < Minitest::Test |
| 11 | + include AppiumLibCoreTest::Mock |
| 12 | + |
| 13 | + def setup |
| 14 | + @core ||= ::Appium::Core.for(self, Caps.android) |
| 15 | + @driver ||= android_mock_create_session |
| 16 | + end |
| 17 | + |
| 18 | + def test_delete |
| 19 | + stub_request(:delete, SESSION) |
| 20 | + .to_return(headers: HEADER, status: 200, body: { value: nil }.to_json) |
| 21 | + |
| 22 | + @driver.quit |
| 23 | + |
| 24 | + assert_requested(:delete, SESSION, times: 1) |
| 25 | + end |
| 26 | + |
| 27 | + def test_launch_app |
| 28 | + stub_request(:post, "#{SESSION}/appium/app/launch") |
| 29 | + .to_return(headers: HEADER, status: 200, body: { value: nil }.to_json) |
| 30 | + |
| 31 | + @driver.launch_app |
| 32 | + |
| 33 | + assert_requested(:post, "#{SESSION}/appium/app/launch", times: 1) |
| 34 | + end |
| 35 | + |
| 36 | + def test_close_app |
| 37 | + stub_request(:post, "#{SESSION}/appium/app/close") |
| 38 | + .to_return(headers: HEADER, status: 200, body: { value: nil }.to_json) |
| 39 | + |
| 40 | + @driver.close_app |
| 41 | + |
| 42 | + assert_requested(:post, "#{SESSION}/appium/app/close", times: 1) |
| 43 | + end |
| 44 | + |
| 45 | + def test_reset |
| 46 | + stub_request(:post, "#{SESSION}/appium/app/reset") |
| 47 | + .to_return(headers: HEADER, status: 200, body: { value: nil }.to_json) |
| 48 | + |
| 49 | + @driver.reset |
| 50 | + |
| 51 | + assert_requested(:post, "#{SESSION}/appium/app/reset", times: 1) |
| 52 | + end |
| 53 | + |
| 54 | + def test_app_strings |
| 55 | + stub_request(:post, "#{SESSION}/appium/app/strings") |
| 56 | + .to_return(headers: HEADER, status: 200, body: { value: 'xxxx' }.to_json) |
| 57 | + |
| 58 | + @driver.app_strings |
| 59 | + |
| 60 | + assert_requested(:post, "#{SESSION}/appium/app/strings", times: 1) |
| 61 | + end |
| 62 | + |
| 63 | + def test_background_app |
| 64 | + stub_request(:post, "#{SESSION}/appium/app/background") |
| 65 | + .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) |
| 66 | + |
| 67 | + @driver.background_app 0 |
| 68 | + |
| 69 | + assert_requested(:post, "#{SESSION}/appium/app/background", times: 1) |
| 70 | + end |
| 71 | + |
| 72 | + def test_end_coverage |
| 73 | + stub_request(:post, "#{SESSION}/appium/app/end_test_coverage") |
| 74 | + .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) |
| 75 | + |
| 76 | + @driver.end_coverage 'path/to', 'intent' |
| 77 | + |
| 78 | + assert_requested(:post, "#{SESSION}/appium/app/end_test_coverage", times: 1) |
| 79 | + end |
| 80 | + |
| 81 | + def test_install_app |
| 82 | + stub_request(:post, "#{SESSION}/appium/device/install_app") |
| 83 | + .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) |
| 84 | + |
| 85 | + @driver.install_app 'app_path' |
| 86 | + |
| 87 | + assert_requested(:post, "#{SESSION}/appium/device/install_app", times: 1) |
| 88 | + end |
| 89 | + |
| 90 | + def test_install_app_with_params |
| 91 | + stub_request(:post, "#{SESSION}/appium/device/install_app") |
| 92 | + .with(body: { appPath: 'app_path', |
| 93 | + options: { |
| 94 | + replace: true, |
| 95 | + timeout: 20_000, |
| 96 | + allowTestPackages: true, |
| 97 | + useSdcard: false, |
| 98 | + grantPermissions: false |
| 99 | + } }.to_json) |
| 100 | + .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) |
| 101 | + |
| 102 | + @driver.install_app 'app_path', |
| 103 | + replace: true, |
| 104 | + timeout: 20_000, |
| 105 | + allow_test_packages: true, |
| 106 | + use_sdcard: false, |
| 107 | + grant_permissions: false |
| 108 | + |
| 109 | + assert_requested(:post, "#{SESSION}/appium/device/install_app", times: 1) |
| 110 | + end |
| 111 | + |
| 112 | + def test_remove_app |
| 113 | + stub_request(:post, "#{SESSION}/appium/device/remove_app") |
| 114 | + .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) |
| 115 | + |
| 116 | + @driver.remove_app 'com.app.id' |
| 117 | + |
| 118 | + assert_requested(:post, "#{SESSION}/appium/device/remove_app", times: 1) |
| 119 | + end |
| 120 | + |
| 121 | + def test_remove_app_with_param |
| 122 | + stub_request(:post, "#{SESSION}/appium/device/remove_app") |
| 123 | + .with(body: { appId: 'com.app.id', options: { keepData: false, timeout: 20_000 } }.to_json) |
| 124 | + .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) |
| 125 | + |
| 126 | + @driver.remove_app 'com.app.id', keep_data: false, timeout: 20_000 |
| 127 | + |
| 128 | + assert_requested(:post, "#{SESSION}/appium/device/remove_app", times: 1) |
| 129 | + end |
| 130 | + |
| 131 | + def test_terminate_app |
| 132 | + stub_request(:post, "#{SESSION}/appium/device/terminate_app") |
| 133 | + .to_return(headers: HEADER, status: 200, body: { value: true }.to_json) |
| 134 | + |
| 135 | + @driver.terminate_app 'com.app.id' |
| 136 | + |
| 137 | + assert_requested(:post, "#{SESSION}/appium/device/terminate_app", times: 1) |
| 138 | + end |
| 139 | + |
| 140 | + def test_terminate_app_with_param |
| 141 | + stub_request(:post, "#{SESSION}/appium/device/terminate_app") |
| 142 | + .with(body: { appId: 'com.app.id', options: { timeout: 20_000 } }.to_json) |
| 143 | + .to_return(headers: HEADER, status: 200, body: { value: true }.to_json) |
| 144 | + |
| 145 | + @driver.terminate_app 'com.app.id', timeout: 20_000 |
| 146 | + |
| 147 | + assert_requested(:post, "#{SESSION}/appium/device/terminate_app", times: 1) |
| 148 | + end |
| 149 | + |
| 150 | + def test_activate_app |
| 151 | + stub_request(:post, "#{SESSION}/appium/device/activate_app") |
| 152 | + .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) |
| 153 | + |
| 154 | + @driver.activate_app 'com.app.id' |
| 155 | + |
| 156 | + assert_requested(:post, "#{SESSION}/appium/device/activate_app", times: 1) |
| 157 | + end |
| 158 | + |
| 159 | + def test_app_state |
| 160 | + stub_request(:post, "#{SESSION}/appium/device/app_state") |
| 161 | + .to_return(headers: HEADER, status: 200, body: { value: 1 }.to_json) |
| 162 | + |
| 163 | + state = @driver.app_state 'com.app.id' |
| 164 | + |
| 165 | + assert_requested(:post, "#{SESSION}/appium/device/app_state", times: 1) |
| 166 | + assert_equal :not_running, state |
| 167 | + end |
| 168 | + |
| 169 | + def test_app_installed? |
| 170 | + stub_request(:post, "#{SESSION}/appium/device/app_installed") |
| 171 | + .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) |
| 172 | + |
| 173 | + @driver.app_installed? 'com.app.id' |
| 174 | + |
| 175 | + assert_requested(:post, "#{SESSION}/appium/device/app_installed", times: 1) |
| 176 | + end |
| 177 | + end # class AppManagementTest |
| 178 | + end # module MJSONWP |
| 179 | + end # module Device |
| 180 | + end # module Android |
| 181 | +end # class AppiumLibCoreTest |
0 commit comments