Skip to content

Commit 5419ead

Browse files
authored
Merge branch 'main' into as/add-on-suggestion
2 parents 3c064ef + 11aaf4d commit 5419ead

15 files changed

+279
-14
lines changed

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ requests = "*"
1313
pytest-xdist = "*"
1414
pytest-html = "*"
1515
pypom = "*"
16+
jsonpath-ng = "*"
1617
pillow = "*"
1718

1819
[dev-packages]

conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,8 @@ def version(driver: webdriver.Firefox):
214214
@pytest.fixture(scope="session", autouse=True)
215215
def faker_seed():
216216
return 19980331
217+
218+
219+
@pytest.fixture(scope="session")
220+
def fillable_pdf_url():
221+
return "https://www.uscis.gov/sites/default/files/document/forms/i-9.pdf"

modules/browser_object_find_toolbar.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ def open(self) -> BasePage:
2020
self.wait_for_page_to_load()
2121
return self
2222

23+
def open_with_key_combo(self) -> BasePage:
24+
"""Use Cmd/Ctrl + F to open the Find Toolbar, wait for load"""
25+
with self.driver.context(self.driver.CONTEXT_CHROME):
26+
if self.sys_platform() == "Darwin":
27+
mod_key = Keys.COMMAND
28+
else:
29+
mod_key = Keys.CONTROL
30+
self.perform_key_combo(mod_key, "f")
31+
self.wait_for_page_to_load()
32+
return self
33+
2334
def find(self, term: str) -> BasePage:
2435
"""Use the Find Toolbar to search"""
2536
with self.driver.context(self.driver.CONTEXT_CHROME):
@@ -46,8 +57,33 @@ def next_match(self) -> BasePage:
4657
"""Click the Next Match button"""
4758
with self.driver.context(self.driver.CONTEXT_CHROME):
4859
self.get_element("next-match-button").click()
60+
return self
4961

5062
def previous_match(self) -> BasePage:
5163
"""Click the Previous Match button"""
5264
with self.driver.context(self.driver.CONTEXT_CHROME):
5365
self.get_element("previous-match-button").click()
66+
return self
67+
68+
def rewind_to_first_match(self) -> BasePage:
69+
"""Go back to match 1 of n"""
70+
with self.driver.context(self.driver.CONTEXT_CHROME):
71+
position = self.get_match_args()["current"]
72+
total = self.get_match_args()["total"]
73+
while position != 1:
74+
if position < total // 2:
75+
self.previous_match()
76+
else:
77+
self.next_match()
78+
position = self.get_match_args()["current"]
79+
return self
80+
81+
def navigate_matches_by_keys(self, backwards=False) -> BasePage:
82+
"""Use F3 and Shift+F3 to navigate matches"""
83+
with self.driver.context(self.driver.CONTEXT_CHROME):
84+
if backwards:
85+
self.perform_key_combo(Keys.SHIFT, Keys.F3)
86+
else:
87+
logging.info(f"sending {Keys.F3.encode()}")
88+
self.actions.send_keys(Keys.F3).perform()
89+
return self
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"category-raw": {
3+
"selectorData": "category-raw",
4+
"strategy": "id",
5+
"groups": []
6+
},
7+
8+
"rawdata-tab": {
9+
"selectorData": "//li[@class='tabs-menu-item rawdata ']//a[@id='rawdata-tab']",
10+
"strategy": "xpath",
11+
"groups": []
12+
}
13+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"text-layer": {
3+
"selectorData": "textLayer",
4+
"strategy": "class",
5+
"groups": [
6+
"requiredForPage"
7+
]
8+
},
9+
10+
"highlighted-text": {
11+
"selectorData": ".textLayer .highlight.selected.appended",
12+
"strategy": "css",
13+
"groups": [
14+
"doNotCache"
15+
]
16+
}
17+
}

modules/data/navigation.components.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
]
1010
},
1111

12+
"results-dropdown": {
13+
"selectorData": "urlbar-results",
14+
"strategy": "id",
15+
"groups": [
16+
"doNotCache"
17+
]
18+
},
19+
1220
"tab-to-search-text-span": {
1321
"selectorData": "urlbarView-dynamic-onboardTabToSearch-text-container",
1422
"strategy": "class",
@@ -107,7 +115,7 @@
107115
"groups": []
108116
},
109117

110-
118+
111119
"add-extra-search-engine": {
112120
"selectorData": "[id*=urlbar-engine-one-off-item-engine--1][tooltiptext*='{0}']",
113121
"strategy": "css",
@@ -132,4 +140,11 @@
132140
"groups": []
133141
}
134142

143+
"search-suggestion-list": {
144+
"selectorData": "div.urlbarView-row[type='search_engine'] span.urlbarView-title",
145+
"strategy": "css",
146+
"groups": [
147+
"doNotCache"
148+
]
149+
}
135150
}

modules/page_base.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,14 @@ def get_elements(self, name: str, labels=[]):
306306
"""
307307
return self.get_element(name, multiple=True, labels=labels)
308308

309+
def get_parent_of(self, name: str, labels=[]) -> WebElement:
310+
"""
311+
Given a name (and labels if needed), return the direct parent node of the element.
312+
"""
313+
314+
child = self.get_element(name, labels=labels)
315+
return child.find_element(By.XPATH, "..")
316+
309317
def element_exists(self, name: str, labels=[]) -> Page:
310318
"""Expect helper: wait until element exists or timeout"""
311319
self.expect(
@@ -345,6 +353,15 @@ def element_selected(self, name: str, labels=[]) -> Page:
345353
)
346354
return self
347355

356+
def element_has_text(self, name: str, text: str, labels=[]) -> Page:
357+
"""Expect helper: wait until element has given text"""
358+
self.expect(
359+
EC.text_to_be_present_in_element(
360+
self.get_selector(name, labels=labels), text
361+
)
362+
)
363+
return self
364+
348365
def url_contains(self, url_part: str) -> Page:
349366
"""Expect helper: wait until driver URL contains given text or timeout"""
350367
self.expect(EC.url_contains(url_part))
@@ -456,3 +473,8 @@ def loaded(self):
456473
pass
457474
self.set_content_context()
458475
return _loaded
476+
477+
def switch_tab(self):
478+
"""Get list of all window handles, switch to the newly opened tab"""
479+
handles = self.driver.window_handles
480+
self.driver.switch_to.window(handles[-1])

modules/page_object.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@
99
from modules.page_object_autofill_credit_card import *
1010
from modules.page_object_autofill_test_basic import *
1111
from modules.page_object_example_page import *
12+
from modules.page_object_generic_pdf import *
1213
from modules.page_object_google_search import *
1314
from modules.page_object_wiki_firefox_logo import *
15+
from modules.page_object_about_telemetry import *
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from modules.page_base import BasePage
2+
3+
4+
class AboutTelemetry(BasePage):
5+
"""
6+
The POM for the about:telemetry page
7+
8+
Attributes
9+
----------
10+
driver: selenium.webdriver.Firefox
11+
WebDriver object under test
12+
"""
13+
14+
URL_TEMPLATE = "about:telemetry"

modules/page_object_generic_pdf.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from modules.page_base import BasePage
2+
3+
4+
class GenericPdf(BasePage):
5+
"""
6+
Generic POM for any page with an open PDF in it.
7+
"""
8+
9+
URL_TEMPLATE = "{pdf_url}"
10+
11+
def get_green_highlighted_text(self) -> str:
12+
return self.get_element("highlighted-text").get_attribute("innerText")

0 commit comments

Comments
 (0)