|
1 | 1 | require 'test_helper'
|
| 2 | +require 'webmock/minitest' |
2 | 3 |
|
3 | 4 | # $ rake test:unit TEST=test/unit/common_test.rb
|
4 | 5 | class AppiumLibCoreTest
|
5 | 6 | class Common
|
6 | 7 | class AppiumCoreBaseBridgeTest < Minitest::Test
|
| 8 | + include AppiumLibCoreTest::Mock |
| 9 | + |
7 | 10 | def setup
|
8 | 11 | @bridge = Appium::Core::Base::Bridge.new
|
9 | 12 | end
|
10 | 13 |
|
| 14 | + RESPONSE_BASE_VALUE = { |
| 15 | + sessionId: '1234567890', |
| 16 | + capabilities: { |
| 17 | + platformName: :android, |
| 18 | + automationName: 'uiautomator2', |
| 19 | + app: 'test/functional/app/api.apk', |
| 20 | + platformVersion: '7.1.1', |
| 21 | + deviceName: 'Android Emulator', |
| 22 | + appPackage: 'io.appium.android.apis' |
| 23 | + } |
| 24 | + }.freeze |
| 25 | + |
| 26 | + CAPS = { |
| 27 | + platformName: :android, |
| 28 | + automationName: 'uiautomator2', |
| 29 | + app: "#{Dir.pwd}/test/functional/app/api.apk", |
| 30 | + platformVersion: '7.1.1', |
| 31 | + deviceName: 'Android Emulator', |
| 32 | + appPackage: 'io.appium.android.apis' |
| 33 | + }.freeze |
| 34 | + |
| 35 | + APPIUM_PREFIX_CAPS = { |
| 36 | + platformName: :android, |
| 37 | + 'appium:automationName' => 'uiautomator2', |
| 38 | + 'appium:app' => "#{Dir.pwd}/test/functional/app/api.apk", |
| 39 | + 'appium:platformVersion' => '7.1.1', |
| 40 | + 'appium:deviceName' => 'Android Emulator', |
| 41 | + 'appium:appPackage' => 'io.appium.android.apis' |
| 42 | + }.freeze |
| 43 | + |
| 44 | + def test_create_session_force_mjsonwp |
| 45 | + response = { |
| 46 | + status: 0, # To make bridge.dialect == :oss |
| 47 | + value: RESPONSE_BASE_VALUE |
| 48 | + }.to_json |
| 49 | + |
| 50 | + stub_request(:post, 'http://127.0.0.1:4723/wd/hub/session') |
| 51 | + .with(body: { desiredCapabilities: CAPS }.to_json) |
| 52 | + .to_return(headers: Mock::HEADER, status: 200, body: response) |
| 53 | + |
| 54 | + stub_request(:post, "#{Mock::SESSION}/timeouts/implicit_wait") |
| 55 | + .with(body: { ms: 20_000 }.to_json) |
| 56 | + .to_return(headers: Mock::HEADER, status: 200, body: { value: nil }.to_json) |
| 57 | + |
| 58 | + driver = ::Appium::Core.for(self, { caps: CAPS.merge({ forceMjsonwp: true }), appium_lib: {} }).start_driver |
| 59 | + |
| 60 | + assert_requested(:post, 'http://127.0.0.1:4723/wd/hub/session', times: 1) |
| 61 | + assert_requested(:post, "#{Mock::SESSION}/timeouts/implicit_wait", body: { ms: 20_000 }.to_json, times: 1) |
| 62 | + driver |
| 63 | + end |
| 64 | + |
| 65 | + def test_create_session_force_mjsonwp_false |
| 66 | + response = { value: RESPONSE_BASE_VALUE }.to_json |
| 67 | + |
| 68 | + stub_request(:post, 'http://127.0.0.1:4723/wd/hub/session') |
| 69 | + .with(body: { desiredCapabilities: CAPS, |
| 70 | + capabilities: { alwaysMatch: APPIUM_PREFIX_CAPS, firstMatch: [{}] } }.to_json) |
| 71 | + .to_return(headers: Mock::HEADER, status: 200, body: response) |
| 72 | + |
| 73 | + stub_request(:post, "#{Mock::SESSION}/timeouts") |
| 74 | + .with(body: { implicit: 20_000 }.to_json) |
| 75 | + .to_return(headers: Mock::HEADER, status: 200, body: { value: nil }.to_json) |
| 76 | + |
| 77 | + driver = ::Appium::Core.for(self, { caps: CAPS.merge({ forceMjsonwp: false }), appium_lib: {} }).start_driver |
| 78 | + |
| 79 | + assert_requested(:post, 'http://127.0.0.1:4723/wd/hub/session', times: 1) |
| 80 | + assert_requested(:post, "#{Mock::SESSION}/timeouts", body: { implicit: 20_000 }.to_json, times: 1) |
| 81 | + driver |
| 82 | + end |
| 83 | + |
| 84 | + def test_create_session_w3c |
| 85 | + response = { value: RESPONSE_BASE_VALUE }.to_json |
| 86 | + |
| 87 | + stub_request(:post, 'http://127.0.0.1:4723/wd/hub/session') |
| 88 | + .with(body: { desiredCapabilities: CAPS, |
| 89 | + capabilities: { alwaysMatch: APPIUM_PREFIX_CAPS, firstMatch: [{}] } }.to_json) |
| 90 | + .to_return(headers: Mock::HEADER, status: 200, body: response) |
| 91 | + |
| 92 | + stub_request(:post, "#{Mock::SESSION}/timeouts") |
| 93 | + .with(body: { implicit: 20_000 }.to_json) |
| 94 | + .to_return(headers: Mock::HEADER, status: 200, body: { value: nil }.to_json) |
| 95 | + |
| 96 | + driver = ::Appium::Core.for(self, { caps: CAPS, appium_lib: {} }).start_driver |
| 97 | + |
| 98 | + assert_requested(:post, 'http://127.0.0.1:4723/wd/hub/session', times: 1) |
| 99 | + assert_requested(:post, "#{Mock::SESSION}/timeouts", body: { implicit: 20_000 }.to_json, times: 1) |
| 100 | + driver |
| 101 | + end |
| 102 | + |
11 | 103 | def test_add_appium_prefix_compatible_with_oss
|
12 | 104 | cap = {
|
13 | 105 | platformName: :ios,
|
|
0 commit comments