77
88GOOGLE_CHROME_PACKAGE = 'com.android.chrome'
99
10- @supported_version ("124 .0.6367.219 " )
10+ @supported_version ("139 .0.7258.62 " )
1111class 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 ):
0 commit comments