Skip to content

Commit 20fee93

Browse files
committed
Added BOM for getting awesome bar text. Also addressed additional review comments
1 parent 7f16047 commit 20fee93

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

modules/browser_object_navigation.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ def get_awesome_bar(self) -> WebElement:
3737
self.set_awesome_bar()
3838
return self.awesome_bar
3939

40+
def get_awesome_bar_text(self):
41+
"""
42+
Get the text directly from the awesome bar.
43+
This is different from 'driver.current_url' which pulls from href
44+
"""
45+
self.set_chrome_context()
46+
awesome_bar = self.get_element("awesome-bar").get_attribute("value")
47+
return awesome_bar
48+
4049
def clear_awesome_bar(self) -> BasePage:
4150
"""Clear the Awesome Bar. Prefer this over get_element("awesome-bar").clear()"""
4251
self.set_awesome_bar()

tests/address_bar_and_search/test_search_code_google_non_us.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import pytest
22
from selenium.webdriver import Firefox
33
from selenium.webdriver.common.by import By
4-
from selenium.webdriver.support import expected_conditions as ec
54

65
from modules.browser_object import ContextMenu, Navigation, TabBar
76
from modules.page_object import AboutConfig
@@ -15,8 +14,9 @@ def add_prefs():
1514
]
1615

1716

18-
# Set constant
17+
# Set constants
1918
FX_SEARCH_CODE = "client=firefox-b-d"
19+
SEARCH_BAR_PREF = "browser.search.widget.inNavBar"
2020

2121

2222
def test_search_code_google_us(driver: Firefox):
@@ -46,8 +46,7 @@ def search_code_assert():
4646

4747
# Check code generated from the Search bar search
4848
# First enable search bar via about:config
49-
pref = "browser.search.widget.inNavBar"
50-
ac.toggle_true_false_config(pref)
49+
ac.toggle_true_false_config(SEARCH_BAR_PREF)
5150
nav.clear_awesome_bar()
5251

5352
# Then run the code check

tests/address_bar_and_search/test_search_code_google_us.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def add_prefs():
1717

1818
# Set constant
1919
FX_SEARCH_CODE = "client=firefox-b-1-d"
20+
SEARCH_BAR_PREF = "browser.search.widget.inNavBar"
2021

2122

2223
def test_search_code_google_us(driver: Firefox):
@@ -46,8 +47,7 @@ def search_code_assert():
4647

4748
# Check code generated from the Search bar search
4849
# First enable search bar via about:config
49-
pref = "browser.search.widget.inNavBar"
50-
ac.toggle_true_false_config(pref)
50+
ac.toggle_true_false_config(SEARCH_BAR_PREF)
5151
nav.clear_awesome_bar()
5252

5353
# Then run the code check

tests/address_bar_and_search/test_search_term_persists.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def add_prefs():
2020
FIRST_RESULT = "https://www.google.com/search?client=firefox-b-1-d&q=cheetah"
2121
SECOND_SEARCH = "lion"
2222
SECOND_RESULT = "https://www.google.com/search?client=firefox-b-1-d&q=lion"
23+
SEARCH_BAR_PREF = "browser.search.widget.inNavBar"
2324

2425

2526
def test_search_term_persists(driver: Firefox):
@@ -31,13 +32,16 @@ def test_search_term_persists(driver: Firefox):
3132
nav = Navigation(driver).open()
3233
tab = TabBar(driver)
3334

34-
def toggle_old_search_bar():
35+
def toggle_legacy_search_bar():
36+
# This test requires that the old search bar is added while retaining search results.
37+
# First, open a new tab and switch to it
3538
tab.new_tab_by_button()
3639
window_handles = driver.window_handles
3740
driver.switch_to.window(window_handles[-1])
41+
# Then, toggle the old search bar via about:config
3842
ac = AboutConfig(driver)
39-
pref = "browser.search.widget.inNavBar"
40-
ac.toggle_true_false_config(pref)
43+
ac.toggle_true_false_config(SEARCH_BAR_PREF)
44+
# Finally, close the about:config tab and switch context back to the original tab
4145
nav.set_chrome_context()
4246
x_icon = tab.get_element("tab-x-icon", multiple=True)
4347
x_icon[1].click()
@@ -47,14 +51,14 @@ def toggle_old_search_bar():
4751
nav.search(FIRST_SEARCH)
4852
tab.expect_title_contains("Google Search")
4953
nav.set_chrome_context()
50-
address_bar_text = nav.get_element("awesome-bar").get_attribute("value")
54+
address_bar_text = nav.get_awesome_bar_text()
5155
assert FIRST_SEARCH == address_bar_text
5256

5357
# Add the search bar to toolbar
54-
toggle_old_search_bar()
58+
toggle_legacy_search_bar()
5559

5660
# Search term should be replaced with full url
57-
address_bar_text = nav.get_element("awesome-bar").get_attribute("value")
61+
address_bar_text = nav.get_awesome_bar_text()
5862
assert FIRST_RESULT == address_bar_text
5963
nav.clear_awesome_bar()
6064

@@ -65,16 +69,15 @@ def toggle_old_search_bar():
6569
# Then perform another search
6670
nav.search(SECOND_SEARCH)
6771
tab.expect_title_contains("Google Search")
68-
nav.set_chrome_context()
69-
address_bar_text = nav.get_element("awesome-bar").get_attribute("value")
72+
address_bar_text = nav.get_awesome_bar_text()
7073
assert SECOND_RESULT == address_bar_text
7174

7275
# Disable the old search bar
73-
toggle_old_search_bar()
76+
toggle_legacy_search_bar()
7477

7578
# Again, perform a search using the URL bar.
7679
nav.search(FIRST_SEARCH)
7780
tab.expect_title_contains("Google Search")
7881
nav.set_chrome_context()
79-
address_bar_text = nav.get_element("awesome-bar").get_attribute("value")
82+
address_bar_text = nav.get_awesome_bar_text()
8083
assert FIRST_SEARCH == address_bar_text

0 commit comments

Comments
 (0)