Skip to content

Commit 26a7fef

Browse files
authored
Ensure websearch field is focused (#860)
1 parent 59beb97 commit 26a7fef

7 files changed

+49
-34
lines changed

modules/page_object_about_pages.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,13 @@ def add_login(self, origin: str, username: str, password: str):
210210
password (str): The password to save
211211
"""
212212
self.click_add_login_button()
213-
self.create_new_login({
214-
"origin": origin,
215-
"username": username,
216-
"password": password,
217-
})
213+
self.create_new_login(
214+
{
215+
"origin": origin,
216+
"username": username,
217+
"password": password,
218+
}
219+
)
218220

219221
def export_passwords_csv(self, downloads_folder: str, filename: str):
220222
"""

modules/page_object_generics.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ def navigate_dialog_to_location(
5252
sleep(1)
5353
keyboard.tap(Key.enter)
5454

55-
def wait_for_reload_and_verify_empty_field(self, old_field, field_id: str, wait_time: int = 10):
55+
def wait_for_reload_and_verify_empty_field(
56+
self, old_field, field_id: str, wait_time: int = 10
57+
):
5658
"""
5759
Wait until the page reloads (staleness of old field) and verify that the
5860
new search field is visible and empty.
@@ -72,14 +74,20 @@ def wait_for_reload_and_verify_empty_field(self, old_field, field_id: str, wait_
7274
# Wait for the new one to appear and be visible
7375
new_field = self.wait.until(
7476
lambda d: (
75-
elem if (elem := d.find_element(By.ID, field_id)).is_displayed() else False
77+
elem
78+
if (elem := d.find_element(By.ID, field_id)).is_displayed()
79+
else False
7680
)
7781
)
7882

79-
assert new_field.get_attribute("value") == "", "Search field should be empty after reload"
83+
assert new_field.get_attribute("value") == "", (
84+
"Search field should be empty after reload"
85+
)
8086
return new_field
8187

82-
def fill_field_and_verify(self, field, text: str, clear_func, assert_nonempty: bool = True):
88+
def fill_field_and_verify(
89+
self, field, text: str, clear_func, assert_nonempty: bool = True
90+
):
8391
"""
8492
Clicks the field, clears it, fills with text, and optionally asserts the value.
8593

tests/menus/test_copy_paste_actions.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,58 +18,58 @@ def test_case():
1818
@pytest.mark.ci
1919
def test_login_form_copy_paste(driver: Firefox):
2020
"""C2264626 - Verify that copy and paste actions are displayed in the context menu and work as expected"""
21-
# instantiate objects
21+
# Instantiate objects
2222
login_fill = LoginAutofill(driver).open()
2323
context_menu = ContextMenu(driver)
2424
util = Utilities()
2525
random_text = util.generate_random_text("sentence")
2626

27-
# get the field and send text
27+
# Get the field and send text
2828
password_field = login_fill.get_element("input-field", labels=["current-password"])
2929
password_field.send_keys(random_text)
3030
logging.info(f"Sent the text {random_text} to the textarea.")
3131

32-
# triple click and copy text
32+
# Triple click and copy text
3333
login_fill.triple_click("input-field", labels=["current-password"])
3434
login_fill.context_click(password_field)
3535
context_menu.click_and_hide_menu("context-menu-copy")
3636

37-
# delete all text
37+
# Delete all text
3838
password_field.send_keys(Keys.BACK_SPACE)
3939
assert password_field.get_attribute("value") == ""
4040

4141
login_fill.context_click(password_field)
4242
context_menu.click_and_hide_menu("context-menu-paste")
4343

44-
# final assertion
44+
# Final assertion
4545
assert password_field.get_attribute("value") != random_text
4646

4747

4848
def test_text_area_copy_paste(driver: Firefox):
49-
# initialize objects
49+
# Initialize objects
5050
text_area_fill = TextAreaFormAutofill(driver).open()
5151
util = Utilities()
5252
context_menu = ContextMenu(driver)
5353
text_area = text_area_fill.get_element("street-address-textarea")
5454

55-
# send the text
55+
# Send the text
5656
random_text = util.generate_random_text("sentence")
5757
text_area.send_keys(random_text)
5858
logging.info(f"Sent the text {random_text} to the textarea.")
5959

60-
# copy the text
60+
# Copy the text
6161
text_area_fill.triple_click("street-address-textarea")
6262
text_area_fill.context_click(text_area)
6363
context_menu.click_and_hide_menu("context-menu-copy")
6464

65-
# delete all the text and paste
65+
# Delete all the text and paste
6666
text_area.send_keys(Keys.BACK_SPACE)
6767
assert text_area.get_attribute("value") == ""
6868

6969
text_area_fill.context_click(text_area)
7070
context_menu.click_and_hide_menu("context-menu-paste")
7171

72-
# check value
72+
# Check value
7373
assert text_area.get_attribute("value") == random_text
7474

7575

@@ -78,26 +78,27 @@ def test_search_field_copy_paste(driver: Firefox):
7878
google_search = GoogleSearch(driver).open()
7979
util = Utilities()
8080

81-
# send the text
81+
# Send the text
8282
random_text = util.generate_random_text("sentence")
8383
search_bar = google_search.get_search_bar_element()
8484
search_bar.send_keys(random_text)
8585
logging.info(f"Sent the text {random_text} to the search bar.")
8686

87-
# triple click the text to select all
87+
# Triple click the text to select all
88+
google_search.click_on("search-bar-textarea")
8889
google_search.triple_click("search-bar-textarea")
8990

90-
# context click
91+
# Context click
9192
google_search.context_click(search_bar)
9293
context_menu.click_and_hide_menu("context-menu-copy")
9394

94-
# delete the current text
95+
# Delete the current text
9596
search_bar.send_keys(Keys.BACK_SPACE)
9697
assert search_bar.get_attribute("value") == ""
9798

98-
# context click and paste the text back
99+
# Context click and paste the text back
99100
google_search.context_click(search_bar)
100101
context_menu.click_and_hide_menu("context-menu-paste")
101102

102-
# assert the value is correct
103+
# Assert the value is correct
103104
assert search_bar.get_attribute("value") == random_text

tests/password_manager/test_auto_saved_generated_password_context_menu.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ def test_auto_saved_generated_password_context_menu(driver: Firefox):
5050
)
5151

5252
# Verify the update doorhanger is displayed
53-
nav.expect(
54-
lambda _: nav.element_visible("password-notification-key")
55-
)
53+
nav.expect(lambda _: nav.element_visible("password-notification-key"))
5654
nav.click_on("password-notification-key")
5755
autofill_popup_panel.expect(
5856
lambda _: UPDATE_DOORHANGER_TEXT

tests/password_manager/test_password_csv_export.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
23
import pytest
34
from pynput.keyboard import Controller, Key
45

tests/tabs/test_open_new_bg_tab_via_mouse_and_keyboard.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from modules.page_object import ExamplePage
55

6-
76
TEST_URL = "https://www.iana.org/help/example-domains"
87

98

tests/tabs/test_reload_tab_via_keyboard.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import platform
2+
23
import pytest
34
from selenium.webdriver import Firefox
45
from selenium.webdriver.common.by import By
56
from selenium.webdriver.common.keys import Keys
7+
68
from modules.browser_object_navigation import Navigation
79
from modules.browser_object_tabbar import TabBar
810
from modules.page_object_generics import GenericPage
911
from modules.util import BrowserActions
1012

11-
1213
TEST_URL = "https://www.wikipedia.org/"
1314
TEST_TEXT = "test"
1415
SEARCH_FIELD_ID = "searchInput"
@@ -39,20 +40,25 @@ def test_reload_tab_via_keyboard(driver: Firefox, sys_platform: str):
3940
search_field = page.custom_wait(timeout=10).until(
4041
lambda d: driver.find_element(By.ID, SEARCH_FIELD_ID)
4142
)
42-
search_field = page.fill_field_and_verify(search_field, TEST_TEXT, ba.clear_and_fill)
43+
search_field = page.fill_field_and_verify(
44+
search_field, TEST_TEXT, ba.clear_and_fill
45+
)
4346

4447
# Perform Ctrl/Cmd+R from chrome context
4548
tabbar.reload_tab(nav, mod_key=mod_key, extra_key="r")
4649

4750
# Ensure page has reloaded and verify search field is empty
48-
search_field = page.wait_for_reload_and_verify_empty_field(search_field, SEARCH_FIELD_ID)
51+
search_field = page.wait_for_reload_and_verify_empty_field(
52+
search_field, SEARCH_FIELD_ID
53+
)
4954

5055
# Type "test" into the search field again
51-
search_field = page.fill_field_and_verify(search_field, TEST_TEXT, ba.clear_and_fill)
56+
search_field = page.fill_field_and_verify(
57+
search_field, TEST_TEXT, ba.clear_and_fill
58+
)
5259

5360
# Perform F5 from chrome context
5461
tabbar.reload_tab(nav, extra_key=Keys.F5)
5562

5663
# Ensure page has reloaded and verify search field is empty
5764
page.wait_for_reload_and_verify_empty_field(search_field, SEARCH_FIELD_ID)
58-

0 commit comments

Comments
 (0)