Skip to content

Commit ad9a8c3

Browse files
authored
Merge pull request #115 from NetherlandsForensicInstitute/113-bookmarks
Fix for bookmarking pages and creating and switching to new tabs
2 parents dee8334 + a401975 commit ad9a8c3

4 files changed

Lines changed: 48 additions & 10 deletions

File tree

RELEASE_NOTES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Version 2.9.1
2+
-------------
3+
113. Fix for bookmarking and creating a new tab in Chrome
4+
15
Version 2.9.0
26
-------------
37
110. Add ground truth logging

puma/apps/android/google_chrome/google_chrome.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
GOOGLE_CHROME_PACKAGE = 'com.android.chrome'
99

10-
@supported_version("124.0.6367.219")
10+
@supported_version("139.0.7258.62")
1111
class GoogleChromeActions(AndroidAppiumActions):
1212
def __init__(self,
1313
device_udid,
@@ -34,10 +34,11 @@ def go_to(self, url_string: str, new_tab: bool = False):
3434
self.driver.find_element(by=AppiumBy.XPATH, value=search_box_xpath).click()
3535

3636
if new_tab:
37-
switch_tab_xpath = '//android.widget.ImageButton[contains(@content-desc, "Switch")]'
38-
new_tab_xpath = '//android.widget.TextView[@resource-id="com.android.chrome:id/new_tab_view_desc"]'
37+
switch_tab_xpath = '//android.widget.ImageButton[@resource-id="com.android.chrome:id/tab_switcher_button"]'
38+
new_tab_xpath = '//android.widget.Button[contains(@content-desc, "tab")]'
3939
self.driver.find_element(by=AppiumBy.XPATH, value=switch_tab_xpath).click()
4040
self.driver.find_element(by=AppiumBy.XPATH, value=new_tab_xpath).click()
41+
self.is_present(xpath=switch_tab_xpath, implicit_wait=1)
4142
self.driver.find_element(by=AppiumBy.XPATH, value=search_box_xpath).click()
4243

4344
url_bar_xpath = '//android.widget.EditText[@resource-id="com.android.chrome:id/url_bar"]'
@@ -50,11 +51,37 @@ def go_to(self, url_string: str, new_tab: bool = False):
5051
def bookmark_page(self):
5152
"""
5253
Bookmarks the current page.
54+
:return: True if bookmark has been added, False if it already existed.
5355
"""
5456
three_dots_xpath = '//android.widget.ImageButton[@content-desc="Customize and control Google Chrome"]'
55-
bookmark_xpath = '//android.widget.ImageButton[lower-case(@content-desc)="bookmark"]'
57+
bookmark_xpath = '//android.widget.Button[lower-case(@content-desc)="bookmark"]'
58+
edit_bookmark_xpath = '//android.widget.Button[lower-case(@content-desc)="edit bookmark"]'
5659
self.driver.find_element(by=AppiumBy.XPATH, value=three_dots_xpath).click()
57-
self.driver.find_element(by=AppiumBy.XPATH, value=bookmark_xpath).click()
60+
if self.is_present(edit_bookmark_xpath):
61+
self.back()
62+
return False
63+
else:
64+
self.driver.find_element(by=AppiumBy.XPATH, value=bookmark_xpath).click()
65+
return True
66+
67+
@log_action
68+
def delete_bookmark(self):
69+
"""
70+
Delete the current bookmark.
71+
:return: True if bookmark has been deleted, False if it wasn't bookmarked.
72+
"""
73+
three_dots_xpath = '//android.widget.ImageButton[@content-desc="Customize and control Google Chrome"]'
74+
bookmark_xpath = '//android.widget.Button[lower-case(@content-desc)="bookmark"]'
75+
edit_bookmark_xpath = '//android.widget.Button[lower-case(@content-desc)="edit bookmark"]'
76+
delete_bookmark_xpath = '//android.widget.Button[lower-case(@content-desc)="delete bookmarks"]'
77+
self.driver.find_element(by=AppiumBy.XPATH, value=three_dots_xpath).click()
78+
if self.is_present(bookmark_xpath):
79+
self.back()
80+
return False
81+
else:
82+
self.driver.find_element(by=AppiumBy.XPATH, value=edit_bookmark_xpath).click()
83+
self.driver.find_element(by=AppiumBy.XPATH, value=delete_bookmark_xpath).click()
84+
return True
5885

5986
@log_action
6087
def load_bookmark(self):

puma/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version = "2.9.0"
1+
version = "2.9.1"

test_scripts/test_google_chrome.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,20 @@ def test_go_to(self):
3232
def test_new_tab(self):
3333
self.alice.go_to("www.google.com", new_tab=True)
3434

35-
def test_save_bookmark(self):
36-
self.alice.bookmark_page()
35+
def test_bookmarks(self):
36+
self.alice.go_to("www.wikipedia.com")
37+
# Clean up at the start, so we can be sure that both saving and deleting are properly tested.
38+
self.alice.delete_bookmark()
3739

38-
def test_load_bookmark(self):
40+
self.assertTrue(self.alice.bookmark_page())
41+
self.assertFalse(self.alice.bookmark_page())
3942
self.alice.load_bookmark()
43+
self.assertTrue(self.alice.delete_bookmark())
44+
self.assertFalse(self.alice.delete_bookmark())
4045

41-
def test_incognito(self):
46+
# This test contains 'zzz' to make sure it runs last. This should be fixed later.
47+
# Other tests fail if Chrome is left in incognito mode. This should be made more robust.
48+
def test_zzz_incognito(self):
4249
self.alice.go_to_incognito("www.wikipedia.com")
4350

4451

0 commit comments

Comments
 (0)