Skip to content

Commit 6d6618a

Browse files
test: Update flutter tests to canonic pytest format
1 parent 3677e0c commit 6d6618a

7 files changed

Lines changed: 320 additions & 242 deletions

File tree

test/functional/flutter_integration/commands_test.py

Lines changed: 103 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -13,122 +13,136 @@
1313
# limitations under the License.
1414

1515
import os
16+
from typing import TYPE_CHECKING
1617

1718
from appium.webdriver.common.appiumby import AppiumBy
1819
from appium.webdriver.extensions.flutter_integration.flutter_finder import FlutterFinder
1920
from appium.webdriver.extensions.flutter_integration.scroll_directions import ScrollDirection
20-
from test.functional.flutter_integration.helper.test_helper import BaseTestCase
2121

22+
if TYPE_CHECKING:
23+
from appium.webdriver.extensions.flutter_integration.flutter_commands import FlutterCommand
24+
from appium.webdriver.webdriver import WebDriver
2225

23-
class TestFlutterCommands(BaseTestCase):
24-
def test_wait_command(self) -> None:
25-
self.__open_screen('Lazy Loading')
2626

27-
message_field_finder = FlutterFinder.by_key('message_field')
28-
toggle_button_finder = FlutterFinder.by_key('toggle_button')
27+
def _open_screen(driver: 'WebDriver', flutter_command: 'FlutterCommand', screen_name: str) -> None:
28+
"""Helper function to open a specific screen in the Flutter app."""
29+
driver.find_element(AppiumBy.FLUTTER_INTEGRATION_TEXT, 'Login').click()
30+
element = flutter_command.scroll_till_visible(FlutterFinder.by_text(screen_name))
31+
element.click()
2932

30-
message_field = self.driver.find_element(*message_field_finder.as_args())
31-
toggle_button = self.driver.find_element(*toggle_button_finder.as_args())
32-
assert message_field.is_displayed() == True
33-
assert message_field.text == 'Hello world'
3433

35-
toggle_button.click()
36-
self.flutter_command.wait_for_invisible(message_field_finder)
37-
assert len(self.driver.find_elements(*message_field_finder.as_args())) == 0
34+
def test_wait_command(driver: 'WebDriver', flutter_command: 'FlutterCommand') -> None:
35+
"""Test Flutter wait commands for element visibility."""
36+
_open_screen(driver, flutter_command, 'Lazy Loading')
3837

39-
toggle_button.click()
40-
self.flutter_command.wait_for_visible(message_field)
41-
assert len(self.driver.find_elements(*message_field_finder.as_args())) == 1
38+
message_field_finder = FlutterFinder.by_key('message_field')
39+
toggle_button_finder = FlutterFinder.by_key('toggle_button')
4240

43-
def test_scroll_till_visible_command(self) -> None:
44-
self.__open_screen('Vertical Swiping')
41+
message_field = driver.find_element(*message_field_finder.as_args())
42+
toggle_button = driver.find_element(*toggle_button_finder.as_args())
43+
assert message_field.is_displayed() == True
44+
assert message_field.text == 'Hello world'
4545

46-
java_text_finder = FlutterFinder.by_text('Java')
47-
protractor_text_finder = FlutterFinder.by_text('Protractor')
46+
toggle_button.click()
47+
flutter_command.wait_for_invisible(message_field_finder)
48+
assert len(driver.find_elements(*message_field_finder.as_args())) == 0
4849

49-
first_element = self.flutter_command.scroll_till_visible(java_text_finder)
50-
assert first_element.get_attribute('displayed') == 'true'
50+
toggle_button.click()
51+
flutter_command.wait_for_visible(message_field)
52+
assert len(driver.find_elements(*message_field_finder.as_args())) == 1
5153

52-
second_element = self.flutter_command.scroll_till_visible(protractor_text_finder)
53-
assert second_element.get_attribute('displayed') == 'true'
54-
assert first_element.get_attribute('displayed') == 'false'
5554

56-
first_element = self.flutter_command.scroll_till_visible(java_text_finder, ScrollDirection.UP)
57-
assert second_element.get_attribute('displayed') == 'false'
58-
assert first_element.get_attribute('displayed') == 'true'
55+
def test_scroll_till_visible_command(driver: 'WebDriver', flutter_command: 'FlutterCommand') -> None:
56+
"""Test Flutter scroll till visible command."""
57+
_open_screen(driver, flutter_command, 'Vertical Swiping')
5958

60-
def test_scroll_till_visible_with_scroll_params_command(self) -> None:
61-
self.__open_screen('Vertical Swiping')
59+
java_text_finder = FlutterFinder.by_text('Java')
60+
protractor_text_finder = FlutterFinder.by_text('Protractor')
6261

63-
scroll_params = {
64-
'scrollView': FlutterFinder.by_type('Scrollable').to_dict(),
65-
'delta': 30,
66-
'maxScrolls': 30,
67-
'settleBetweenScrollsTimeout': 5000,
68-
'dragDuration': 35,
69-
}
70-
first_element = self.flutter_command.scroll_till_visible(
71-
FlutterFinder.by_text('Playwright'), scroll_direction=ScrollDirection.DOWN, **scroll_params
72-
)
73-
assert first_element.get_attribute('displayed') == 'true'
62+
first_element = flutter_command.scroll_till_visible(java_text_finder)
63+
assert first_element.get_attribute('displayed') == 'true'
7464

75-
def test_double_click_command(self) -> None:
76-
self.__open_screen('Double Tap')
65+
second_element = flutter_command.scroll_till_visible(protractor_text_finder)
66+
assert second_element.get_attribute('displayed') == 'true'
67+
assert first_element.get_attribute('displayed') == 'false'
7768

78-
double_tap_button = self.driver.find_element(AppiumBy.FLUTTER_INTEGRATION_KEY, 'double_tap_button').find_element(
79-
AppiumBy.FLUTTER_INTEGRATION_TEXT, 'Double Tap'
80-
)
81-
assert double_tap_button.text == 'Double Tap'
69+
first_element = flutter_command.scroll_till_visible(java_text_finder, ScrollDirection.UP)
70+
assert second_element.get_attribute('displayed') == 'false'
71+
assert first_element.get_attribute('displayed') == 'true'
8272

83-
self.flutter_command.perform_double_click(double_tap_button)
84-
assert (
85-
self.driver.find_element(AppiumBy.FLUTTER_INTEGRATION_TEXT_CONTAINING, 'Successful').text == 'Double Tap Successful'
86-
)
8773

88-
self.driver.find_element(AppiumBy.FLUTTER_INTEGRATION_TEXT, 'Ok').click()
89-
self.flutter_command.perform_double_click(double_tap_button, (10, 2))
90-
assert (
91-
self.driver.find_element(AppiumBy.FLUTTER_INTEGRATION_TEXT_CONTAINING, 'Successful').text == 'Double Tap Successful'
92-
)
74+
def test_scroll_till_visible_with_scroll_params_command(driver: 'WebDriver', flutter_command: 'FlutterCommand') -> None:
75+
"""Test Flutter scroll till visible command with custom scroll parameters."""
76+
_open_screen(driver, flutter_command, 'Vertical Swiping')
9377

94-
self.driver.find_element(AppiumBy.FLUTTER_INTEGRATION_TEXT, 'Ok').click()
78+
scroll_params = {
79+
'scrollView': FlutterFinder.by_type('Scrollable').to_dict(),
80+
'delta': 30,
81+
'maxScrolls': 30,
82+
'settleBetweenScrollsTimeout': 5000,
83+
'dragDuration': 35,
84+
}
85+
first_element = flutter_command.scroll_till_visible(
86+
FlutterFinder.by_text('Playwright'), scroll_direction=ScrollDirection.DOWN, **scroll_params
87+
)
88+
assert first_element.get_attribute('displayed') == 'true'
9589

96-
def test_long_press_command(self) -> None:
97-
self.__open_screen('Long Press')
9890

99-
long_press_button = self.driver.find_element(AppiumBy.FLUTTER_INTEGRATION_KEY, 'long_press_button')
100-
self.flutter_command.perform_long_press(long_press_button)
91+
def test_double_click_command(driver: 'WebDriver', flutter_command: 'FlutterCommand') -> None:
92+
"""Test Flutter double click command."""
93+
_open_screen(driver, flutter_command, 'Double Tap')
10194

102-
success_pop_up = self.driver.find_element(AppiumBy.FLUTTER_INTEGRATION_TEXT, 'It was a long press')
103-
assert success_pop_up.text == 'It was a long press'
104-
assert success_pop_up.is_displayed() == True
95+
double_tap_button = driver.find_element(AppiumBy.FLUTTER_INTEGRATION_KEY, 'double_tap_button').find_element(
96+
AppiumBy.FLUTTER_INTEGRATION_TEXT, 'Double Tap'
97+
)
98+
assert double_tap_button.text == 'Double Tap'
10599

106-
def test_drag_and_drop_command(self) -> None:
107-
self.__open_screen('Drag & Drop')
100+
flutter_command.perform_double_click(double_tap_button)
101+
assert driver.find_element(AppiumBy.FLUTTER_INTEGRATION_TEXT_CONTAINING, 'Successful').text == 'Double Tap Successful'
108102

109-
drag_element = self.driver.find_element(AppiumBy.FLUTTER_INTEGRATION_KEY, 'drag_me')
110-
drop_element = self.driver.find_element(AppiumBy.FLUTTER_INTEGRATION_KEY, 'drop_zone')
111-
self.flutter_command.perform_drag_and_drop(drag_element, drop_element)
112-
assert self.driver.find_element(AppiumBy.FLUTTER_INTEGRATION_TEXT, 'The box is dropped').is_displayed() == True
103+
driver.find_element(AppiumBy.FLUTTER_INTEGRATION_TEXT, 'Ok').click()
104+
flutter_command.perform_double_click(double_tap_button, (10, 2))
105+
assert driver.find_element(AppiumBy.FLUTTER_INTEGRATION_TEXT_CONTAINING, 'Successful').text == 'Double Tap Successful'
113106

114-
def test_camera_mocking(self) -> None:
115-
self.__open_screen('Image Picker')
107+
driver.find_element(AppiumBy.FLUTTER_INTEGRATION_TEXT, 'Ok').click()
116108

117-
success_qr_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'file', 'success_qr.png')
118-
second_qr_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'file', 'second_qr.png')
119109

120-
image_id = self.flutter_command.inject_mock_image(success_qr_file_path)
121-
self.flutter_command.inject_mock_image(second_qr_file_path)
122-
self.driver.find_element(AppiumBy.FLUTTER_INTEGRATION_KEY, 'capture_image').click()
123-
self.driver.find_element(AppiumBy.FLUTTER_INTEGRATION_TEXT, 'PICK').click()
124-
assert self.driver.find_element(AppiumBy.FLUTTER_INTEGRATION_TEXT, 'SecondInjectedImage').is_displayed() == True
125-
126-
self.flutter_command.activate_injected_image(image_id)
127-
self.driver.find_element(AppiumBy.FLUTTER_INTEGRATION_KEY, 'capture_image').click()
128-
self.driver.find_element(AppiumBy.FLUTTER_INTEGRATION_TEXT, 'PICK').click()
129-
assert self.driver.find_element(AppiumBy.FLUTTER_INTEGRATION_TEXT, 'Success!').is_displayed() == True
130-
131-
def __open_screen(self, screen_name: str) -> None:
132-
self.driver.find_element(AppiumBy.FLUTTER_INTEGRATION_TEXT, 'Login').click()
133-
element = self.flutter_command.scroll_till_visible(FlutterFinder.by_text(screen_name))
134-
element.click()
110+
def test_long_press_command(driver: 'WebDriver', flutter_command: 'FlutterCommand') -> None:
111+
"""Test Flutter long press command."""
112+
_open_screen(driver, flutter_command, 'Long Press')
113+
114+
long_press_button = driver.find_element(AppiumBy.FLUTTER_INTEGRATION_KEY, 'long_press_button')
115+
flutter_command.perform_long_press(long_press_button)
116+
117+
success_pop_up = driver.find_element(AppiumBy.FLUTTER_INTEGRATION_TEXT, 'It was a long press')
118+
assert success_pop_up.text == 'It was a long press'
119+
assert success_pop_up.is_displayed() == True
120+
121+
122+
def test_drag_and_drop_command(driver: 'WebDriver', flutter_command: 'FlutterCommand') -> None:
123+
"""Test Flutter drag and drop command."""
124+
_open_screen(driver, flutter_command, 'Drag & Drop')
125+
126+
drag_element = driver.find_element(AppiumBy.FLUTTER_INTEGRATION_KEY, 'drag_me')
127+
drop_element = driver.find_element(AppiumBy.FLUTTER_INTEGRATION_KEY, 'drop_zone')
128+
flutter_command.perform_drag_and_drop(drag_element, drop_element)
129+
assert driver.find_element(AppiumBy.FLUTTER_INTEGRATION_TEXT, 'The box is dropped').is_displayed() == True
130+
131+
132+
def test_camera_mocking(driver: 'WebDriver', flutter_command: 'FlutterCommand') -> None:
133+
"""Test Flutter camera mocking functionality."""
134+
_open_screen(driver, flutter_command, 'Image Picker')
135+
136+
success_qr_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'file', 'success_qr.png')
137+
second_qr_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'file', 'second_qr.png')
138+
139+
image_id = flutter_command.inject_mock_image(success_qr_file_path)
140+
flutter_command.inject_mock_image(second_qr_file_path)
141+
driver.find_element(AppiumBy.FLUTTER_INTEGRATION_KEY, 'capture_image').click()
142+
driver.find_element(AppiumBy.FLUTTER_INTEGRATION_TEXT, 'PICK').click()
143+
assert driver.find_element(AppiumBy.FLUTTER_INTEGRATION_TEXT, 'SecondInjectedImage').is_displayed() == True
144+
145+
flutter_command.activate_injected_image(image_id)
146+
driver.find_element(AppiumBy.FLUTTER_INTEGRATION_KEY, 'capture_image').click()
147+
driver.find_element(AppiumBy.FLUTTER_INTEGRATION_TEXT, 'PICK').click()
148+
assert driver.find_element(AppiumBy.FLUTTER_INTEGRATION_TEXT, 'Success!').is_displayed() == True

test/functional/flutter_integration/finder_test.py

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,45 +12,58 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from typing import TYPE_CHECKING
16+
1517
from appium.webdriver.common.appiumby import AppiumBy
1618
from appium.webdriver.extensions.flutter_integration.flutter_finder import FlutterFinder
17-
from test.functional.flutter_integration.helper.test_helper import BaseTestCase
19+
20+
if TYPE_CHECKING:
21+
from appium.webdriver.extensions.flutter_integration.flutter_commands import FlutterCommand
22+
from appium.webdriver.webdriver import WebDriver
1823

1924
LOGIN_BUTTON_FINDER = FlutterFinder.by_text('Login')
2025

2126

22-
class TestFlutterFinders(BaseTestCase):
23-
def test_by_flutter_key(self) -> None:
24-
user_name_field_finder = FlutterFinder.by_key('username_text_field')
25-
user_name_field = self.driver.find_element(*user_name_field_finder.as_args())
26-
assert user_name_field.text == 'admin'
27-
28-
user_name_field.clear()
29-
user_name_field = self.driver.find_element(*user_name_field_finder.as_args()).send_keys('admin123')
30-
assert user_name_field.text == 'admin123'
31-
32-
def test_by_flutter_type(self) -> None:
33-
login_button = self.driver.find_element(AppiumBy.FLUTTER_INTEGRATION_TYPE, 'ElevatedButton')
34-
assert login_button.find_element(AppiumBy.FLUTTER_INTEGRATION_TYPE, 'Text').text == 'Login'
35-
36-
def test_by_flutter_text(self) -> None:
37-
login_button = self.driver.find_element(*LOGIN_BUTTON_FINDER.as_args())
38-
assert login_button.text == 'Login'
39-
40-
login_button.click()
41-
slider = self.driver.find_elements(AppiumBy.FLUTTER_INTEGRATION_TEXT, 'Slider')
42-
assert len(slider) == 1
43-
44-
def test_by_flutter_text_containing(self) -> None:
45-
login_button = self.driver.find_element(*LOGIN_BUTTON_FINDER.as_args())
46-
login_button.click()
47-
vertical_swipe_label = self.driver.find_element(AppiumBy.FLUTTER_INTEGRATION_TEXT_CONTAINING, 'Vertical')
48-
assert vertical_swipe_label.text == 'Vertical Swiping'
49-
50-
def test_by_flutter_semantics_label(self) -> None:
51-
login_button = self.driver.find_element(*LOGIN_BUTTON_FINDER.as_args())
52-
login_button.click()
53-
element = self.flutter_command.scroll_till_visible(FlutterFinder.by_text('Lazy Loading'))
54-
element.click()
55-
message_field = self.driver.find_element(AppiumBy.FLUTTER_INTEGRATION_SEMANTICS_LABEL, 'message_field')
56-
assert message_field.text == 'Hello world'
27+
def test_by_flutter_key(driver: 'WebDriver') -> None:
28+
"""Test finding elements by Flutter key."""
29+
user_name_field_finder = FlutterFinder.by_key('username_text_field')
30+
user_name_field = driver.find_element(*user_name_field_finder.as_args())
31+
assert user_name_field.text == 'admin'
32+
33+
user_name_field.clear()
34+
user_name_field = driver.find_element(*user_name_field_finder.as_args()).send_keys('admin123')
35+
assert user_name_field.text == 'admin123'
36+
37+
38+
def test_by_flutter_type(driver: 'WebDriver') -> None:
39+
"""Test finding elements by Flutter type."""
40+
login_button = driver.find_element(AppiumBy.FLUTTER_INTEGRATION_TYPE, 'ElevatedButton')
41+
assert login_button.find_element(AppiumBy.FLUTTER_INTEGRATION_TYPE, 'Text').text == 'Login'
42+
43+
44+
def test_by_flutter_text(driver: 'WebDriver') -> None:
45+
"""Test finding elements by Flutter text."""
46+
login_button = driver.find_element(*LOGIN_BUTTON_FINDER.as_args())
47+
assert login_button.text == 'Login'
48+
49+
login_button.click()
50+
slider = driver.find_elements(AppiumBy.FLUTTER_INTEGRATION_TEXT, 'Slider')
51+
assert len(slider) == 1
52+
53+
54+
def test_by_flutter_text_containing(driver: 'WebDriver') -> None:
55+
"""Test finding elements by Flutter text containing."""
56+
login_button = driver.find_element(*LOGIN_BUTTON_FINDER.as_args())
57+
login_button.click()
58+
vertical_swipe_label = driver.find_element(AppiumBy.FLUTTER_INTEGRATION_TEXT_CONTAINING, 'Vertical')
59+
assert vertical_swipe_label.text == 'Vertical Swiping'
60+
61+
62+
def test_by_flutter_semantics_label(driver: 'WebDriver', flutter_command: 'FlutterCommand') -> None:
63+
"""Test finding elements by Flutter semantics label."""
64+
login_button = driver.find_element(*LOGIN_BUTTON_FINDER.as_args())
65+
login_button.click()
66+
element = flutter_command.scroll_till_visible(FlutterFinder.by_text('Lazy Loading'))
67+
element.click()
68+
message_field = driver.find_element(AppiumBy.FLUTTER_INTEGRATION_SEMANTICS_LABEL, 'message_field')
69+
assert message_field.text == 'Hello world'

test/functional/flutter_integration/helper/desired_capabilities.py

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)