|
| 1 | +#!/usr/bin/env python |
| 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 | +import json |
| 16 | + |
| 17 | +import httpretty |
| 18 | + |
| 19 | +from appium.webdriver.extensions.flutter_integration.flutter_commands import ( |
| 20 | + FlutterCommand, |
| 21 | +) |
| 22 | +from test.unit.helper.test_helper import ( |
| 23 | + appium_command, |
| 24 | + flutter_w3c_driver, |
| 25 | + get_httpretty_request_body, |
| 26 | +) |
| 27 | + |
| 28 | + |
| 29 | +class TestFlutterRenderTree: |
| 30 | + @httpretty.activate |
| 31 | + def test_get_render_tree_with_all_filters(self): |
| 32 | + expected_body = [{'<partial_tree>': 'LoginButton'}] |
| 33 | + httpretty.register_uri( |
| 34 | + httpretty.POST, |
| 35 | + appium_command('/session/1234567890/execute/sync'), |
| 36 | + body=json.dumps({'value': expected_body}), |
| 37 | + ) |
| 38 | + |
| 39 | + driver = flutter_w3c_driver() |
| 40 | + flutter = FlutterCommand(driver) |
| 41 | + |
| 42 | + result = flutter.get_render_tree(widget_type='ElevatedButton', key='LoginButton', text='Login') |
| 43 | + |
| 44 | + request_body = get_httpretty_request_body(httpretty.last_request()) |
| 45 | + assert request_body['script'] == 'flutter: renderTree' |
| 46 | + assert request_body['args'] == [ |
| 47 | + { |
| 48 | + 'widgetType': 'ElevatedButton', |
| 49 | + 'key': 'LoginButton', |
| 50 | + 'text': 'Login', |
| 51 | + } |
| 52 | + ] |
| 53 | + |
| 54 | + assert result == expected_body |
| 55 | + |
| 56 | + @httpretty.activate |
| 57 | + def test_get_render_tree_with_partial_filters(self): |
| 58 | + expected_body = [{'<partial_tree>': 'LoginScreen'}] |
| 59 | + |
| 60 | + httpretty.register_uri( |
| 61 | + httpretty.POST, |
| 62 | + appium_command('/session/1234567890/execute/sync'), |
| 63 | + body=json.dumps({'value': expected_body}), |
| 64 | + ) |
| 65 | + |
| 66 | + driver = flutter_w3c_driver() |
| 67 | + flutter = FlutterCommand(driver) |
| 68 | + |
| 69 | + result = flutter.get_render_tree(widget_type='LoginScreen') |
| 70 | + |
| 71 | + request_body = get_httpretty_request_body(httpretty.last_request()) |
| 72 | + assert request_body['script'] == 'flutter: renderTree' |
| 73 | + assert request_body['args'] == [{'widgetType': 'LoginScreen'}] |
| 74 | + |
| 75 | + assert result == expected_body |
| 76 | + |
| 77 | + @httpretty.activate |
| 78 | + def test_get_render_tree_with_no_filters(self): |
| 79 | + expected_body = [{'<full_tree>': 'RootWidget'}] |
| 80 | + httpretty.register_uri( |
| 81 | + httpretty.POST, |
| 82 | + appium_command('/session/1234567890/execute/sync'), |
| 83 | + body=json.dumps({'value': expected_body}), |
| 84 | + ) |
| 85 | + |
| 86 | + driver = flutter_w3c_driver() |
| 87 | + flutter = FlutterCommand(driver) |
| 88 | + |
| 89 | + result = flutter.get_render_tree() |
| 90 | + |
| 91 | + request_body = get_httpretty_request_body(httpretty.last_request()) |
| 92 | + assert request_body['script'] == 'flutter: renderTree' |
| 93 | + assert request_body['args'] == [{}] |
| 94 | + |
| 95 | + assert result == expected_body |
0 commit comments