|
| 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 'base64' |
| 17 | + |
| 18 | +# $ rake test:func:ios TEST=test/functional/ios/ios/device_wda_attachment_test.rb |
| 19 | +class AppiumLibCoreTest |
| 20 | + module Ios |
| 21 | + class DeviceWDAAttachmentTest < AppiumLibCoreTest::Function::TestCase |
| 22 | + def setup |
| 23 | + # will add test ad an attachment |
| 24 | + ios_caps = Caps.ios.dup |
| 25 | + ios_caps[:caps][:useNewWDA] = true |
| 26 | + @core = ::Appium::Core.for(ios_caps) |
| 27 | + @driver = @core.start_driver |
| 28 | + end |
| 29 | + |
| 30 | + def teardown |
| 31 | + save_reports(@driver) |
| 32 | + end |
| 33 | + |
| 34 | + def test_localhost_wda_agent_url |
| 35 | + status = JSON.parse(Net::HTTP.get('localhost', '/status', @core.caps[:wdaLocalPort]))['value'] |
| 36 | + |
| 37 | + # Run with webDriverAgentUrl |
| 38 | + current_host = status['ios']['ip'] |
| 39 | + current_port = @core.caps[:wdaLocalPort] |
| 40 | + |
| 41 | + new_ios_caps = Caps.ios.dup |
| 42 | + new_ios_caps[:caps][:useNewWDA] = false |
| 43 | + new_ios_caps[:caps][:webDriverAgentUrl] = "http://#{current_host}:#{current_port}" |
| 44 | + new_ios_caps[:caps].delete :wdaLocalPort |
| 45 | + new_ios_caps[:caps].delete :derivedDataPath |
| 46 | + new_ios_caps[:caps].delete :bootstrapPath |
| 47 | + new_ios_caps[:caps].delete :useXctestrunFile |
| 48 | + |
| 49 | + new_core = ::Appium::Core.for(new_ios_caps) |
| 50 | + @driver = new_core.start_driver |
| 51 | + # Make sure if the driver works |
| 52 | + assert @driver.remote_status |
| 53 | + |
| 54 | + @driver.quit |
| 55 | + # WDA should not stop by `quit` if `webDriverAgentUrl` exists |
| 56 | + assert_equal status, JSON.parse(Net::HTTP.get(current_host, '/status', current_port))['value'] |
| 57 | + |
| 58 | + # Create the original driver again |
| 59 | + @driver = @core.start_driver |
| 60 | + status = JSON.parse(Net::HTTP.get('localhost', '/status', @core.caps[:wdaLocalPort]))['value'] |
| 61 | + current_host = status['ios']['ip'] |
| 62 | + current_port = @core.caps[:wdaLocalPort] |
| 63 | + |
| 64 | + @driver.quit |
| 65 | + |
| 66 | + # WDA should stop |
| 67 | + assert_raises Errno::ECONNREFUSED do |
| 68 | + JSON.parse(Net::HTTP.get(current_host, '/status', current_port))['value'] |
| 69 | + end |
| 70 | + end |
| 71 | + end |
| 72 | + end |
| 73 | +end |
0 commit comments