Skip to content

Commit 7f16047

Browse files
committed
Added BOM for expect text in page title. Also cleaned up all the other tests to use the new method
1 parent c7def5b commit 7f16047

File tree

5 files changed

+56
-44
lines changed

5 files changed

+56
-44
lines changed

modules/browser_object_tabbar.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ def expect_tab_sound_status(
106106
)
107107
return self
108108

109+
def expect_title_contains(self, text: str) -> BasePage:
110+
"""
111+
Check if the page title contains given text
112+
"""
113+
self.expect(EC.title_contains(text))
114+
return self
115+
109116
def open_all_tabs_list(self) -> BasePage:
110117
"""Click the Tab Visibility / List All Tabs button"""
111118
with self.driver.context(self.driver.CONTEXT_CHROME):
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
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

6-
from modules.browser_object import Navigation
5+
from modules.browser_object import Navigation, TabBar
76
from modules.page_object import AboutConfig
87

98

@@ -14,6 +13,11 @@ def add_prefs():
1413
]
1514

1615

16+
# Set constants
17+
SEARCH_BAR_PREF = "browser.search.widget.inNavBar"
18+
SEARCH_TERM = "saxophone"
19+
20+
1721
def test_search_bar_results(driver: Firefox):
1822
"""
1923
C1365213 - The Search Bar provides valid results for specific search terms
@@ -22,21 +26,19 @@ def test_search_bar_results(driver: Firefox):
2226
# Create objects
2327
nav = Navigation(driver).open()
2428
ac = AboutConfig(driver)
25-
26-
search_term = "saxophone"
29+
tab = TabBar(driver)
2730

2831
# Check Google results from a Search bar search
2932
# First enable search bar via about:config
30-
pref = "browser.search.widget.inNavBar"
31-
ac.toggle_true_false_config(pref)
33+
ac.toggle_true_false_config(SEARCH_BAR_PREF)
3234
nav.clear_awesome_bar()
3335

3436
# Then run search and check the results
35-
nav.search_bar_search(search_term)
37+
nav.search_bar_search(SEARCH_TERM)
3638
nav.set_content_context()
37-
nav.expect_in_content(EC.title_contains("Google Search"))
39+
tab.expect_title_contains("Google Search")
3840
search_url = driver.current_url
39-
assert search_term in search_url
41+
assert SEARCH_TERM in search_url
4042
content_searchbar = nav.find_element(By.NAME, "q")
4143
content_searchbar_text = content_searchbar.get_attribute("value")
42-
assert content_searchbar_text == search_term
44+
assert content_searchbar_text == SEARCH_TERM

tests/address_bar_and_search/test_search_code_google_non_us.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from selenium.webdriver.common.by import By
44
from selenium.webdriver.support import expected_conditions as ec
55

6-
from modules.browser_object import ContextMenu, Navigation
6+
from modules.browser_object import ContextMenu, Navigation, TabBar
77
from modules.page_object import AboutConfig
88

99

@@ -15,6 +15,10 @@ def add_prefs():
1515
]
1616

1717

18+
# Set constant
19+
FX_SEARCH_CODE = "client=firefox-b-d"
20+
21+
1822
def test_search_code_google_us(driver: Firefox):
1923
"""
2024
C1365269 - Default Search Code: Google - non-US
@@ -26,18 +30,18 @@ def test_search_code_google_us(driver: Firefox):
2630
nav = Navigation(driver).open()
2731
ac = AboutConfig(driver)
2832
context_menu = ContextMenu(driver)
33+
tab = TabBar(driver)
2934

3035
def search_code_assert():
3136
# Function to check the search code of a Google search in US region
32-
fx_code = "client=firefox-b-d"
3337
nav.set_content_context()
3438
search_url = driver.current_url
35-
assert fx_code in search_url
39+
assert FX_SEARCH_CODE in search_url
3640
nav.clear_awesome_bar()
3741

3842
# Check code generated from the Awesome bar search
3943
nav.search("soccer")
40-
nav.expect(ec.title_contains("Google Search"))
44+
tab.expect_title_contains("Google Search")
4145
search_code_assert()
4246

4347
# Check code generated from the Search bar search
@@ -48,7 +52,7 @@ def search_code_assert():
4852

4953
# Then run the code check
5054
nav.search_bar_search("soccer")
51-
nav.expect(ec.title_contains("Google Search"))
55+
tab.expect_title_contains("Google Search")
5256
search_code_assert()
5357

5458
# Check code generated from the context click of selected text
@@ -64,5 +68,5 @@ def search_code_assert():
6468
# Switch to the newly opened tab and run the code check
6569
window_handles = driver.window_handles
6670
driver.switch_to.window(window_handles[-1])
67-
nav.expect(ec.title_contains("Google Search"))
71+
tab.expect_title_contains("Google Search")
6872
search_code_assert()

tests/address_bar_and_search/test_search_code_google_us.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from selenium.webdriver.common.by import By
44
from selenium.webdriver.support import expected_conditions as EC
55

6-
from modules.browser_object import ContextMenu, Navigation
6+
from modules.browser_object import ContextMenu, Navigation, TabBar
77
from modules.page_object import AboutConfig
88

99

@@ -15,6 +15,10 @@ def add_prefs():
1515
]
1616

1717

18+
# Set constant
19+
FX_SEARCH_CODE = "client=firefox-b-1-d"
20+
21+
1822
def test_search_code_google_us(driver: Firefox):
1923
"""
2024
C1365268 - Default Search Code: Google - US
@@ -26,13 +30,13 @@ def test_search_code_google_us(driver: Firefox):
2630
nav = Navigation(driver).open()
2731
ac = AboutConfig(driver)
2832
context_menu = ContextMenu(driver)
33+
tab = TabBar(driver)
2934

3035
def search_code_assert():
3136
# Function to check the search code of a Google search in US region
32-
fx_code = "client=firefox-b-1-d"
3337
nav.set_content_context()
3438
search_url = driver.current_url
35-
assert fx_code in search_url
39+
assert FX_SEARCH_CODE in search_url
3640
nav.clear_awesome_bar()
3741

3842
# Check code generated from the Awesome bar search
@@ -48,7 +52,7 @@ def search_code_assert():
4852

4953
# Then run the code check
5054
nav.search_bar_search("soccer")
51-
nav.expect(EC.title_contains("Google Search"))
55+
tab.expect_title_contains("Google Search")
5256
search_code_assert()
5357

5458
# Check code generated from the context click of selected text
@@ -64,5 +68,5 @@ def search_code_assert():
6468
# Switch to the newly opened tab and run the code check
6569
window_handles = driver.window_handles
6670
driver.switch_to.window(window_handles[-1])
67-
nav.expect(EC.title_contains("Google Search"))
71+
tab.expect_title_contains("Google Search")
6872
search_code_assert()
Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import pytest
22
from selenium.webdriver import Firefox
3-
from selenium.webdriver.support import expected_conditions as EC
43

5-
from modules.browser_object import Navigation
6-
from modules.browser_object_tabbar import TabBar
4+
from modules.browser_object import Navigation, TabBar
75
from modules.page_object import AboutConfig
86

97

@@ -17,6 +15,13 @@ def add_prefs():
1715
]
1816

1917

18+
# Set constants
19+
FIRST_SEARCH = "cheetah"
20+
FIRST_RESULT = "https://www.google.com/search?client=firefox-b-1-d&q=cheetah"
21+
SECOND_SEARCH = "lion"
22+
SECOND_RESULT = "https://www.google.com/search?client=firefox-b-1-d&q=lion"
23+
24+
2025
def test_search_term_persists(driver: Firefox):
2126
"""
2227
C2153943 - Persist search term basic functionality
@@ -26,12 +31,6 @@ def test_search_term_persists(driver: Firefox):
2631
nav = Navigation(driver).open()
2732
tab = TabBar(driver)
2833

29-
# Set values
30-
search1 = "cheetah"
31-
result1 = "https://www.google.com/search?client=firefox-b-1-d&q=cheetah"
32-
search2 = "lion"
33-
result2 = "https://www.google.com/search?client=firefox-b-1-d&q=lion"
34-
3534
def toggle_old_search_bar():
3635
tab.new_tab_by_button()
3736
window_handles = driver.window_handles
@@ -45,41 +44,37 @@ def toggle_old_search_bar():
4544
driver.switch_to.window(window_handles[0])
4645

4746
# Perform a search using the URL bar.
48-
nav.search(search1)
49-
nav.expect(EC.title_contains("Google Search"))
47+
nav.search(FIRST_SEARCH)
48+
tab.expect_title_contains("Google Search")
5049
nav.set_chrome_context()
5150
address_bar_text = nav.get_element("awesome-bar").get_attribute("value")
52-
print("address bar value: ", address_bar_text)
53-
assert search1 == address_bar_text
51+
assert FIRST_SEARCH == address_bar_text
5452

5553
# Add the search bar to toolbar
5654
toggle_old_search_bar()
5755

5856
# Search term should be replaced with full url
5957
address_bar_text = nav.get_element("awesome-bar").get_attribute("value")
60-
print("address bar value: ", address_bar_text)
61-
assert result1 == address_bar_text
58+
assert FIRST_RESULT == address_bar_text
6259
nav.clear_awesome_bar()
6360

6461
# Perform a new awesome bar search, full url should be present
6562
# First, navigate away from Google
6663
nav.set_content_context()
6764
driver.get("about:robots")
6865
# Then perform another search
69-
nav.search(search2)
70-
nav.expect(EC.title_contains("Google Search"))
66+
nav.search(SECOND_SEARCH)
67+
tab.expect_title_contains("Google Search")
7168
nav.set_chrome_context()
7269
address_bar_text = nav.get_element("awesome-bar").get_attribute("value")
73-
print("address bar value: ", address_bar_text)
74-
assert result2 == address_bar_text
70+
assert SECOND_RESULT == address_bar_text
7571

7672
# Disable the old search bar
7773
toggle_old_search_bar()
7874

7975
# Again, perform a search using the URL bar.
80-
nav.search(search1)
81-
nav.expect(EC.title_contains("Google Search"))
76+
nav.search(FIRST_SEARCH)
77+
tab.expect_title_contains("Google Search")
8278
nav.set_chrome_context()
8379
address_bar_text = nav.get_element("awesome-bar").get_attribute("value")
84-
print("address bar value: ", address_bar_text)
85-
assert search1 == address_bar_text
80+
assert FIRST_SEARCH == address_bar_text

0 commit comments

Comments
 (0)