2018-08-01 00:16:33 +00:00
|
|
|
import time
|
2017-10-05 19:41:17 +00:00
|
|
|
|
2021-02-05 11:29:35 +00:00
|
|
|
from views.base_element import EditBox, Button, BaseElement
|
2018-08-01 00:16:33 +00:00
|
|
|
from views.base_view import BaseView
|
|
|
|
|
2018-01-03 09:34:40 +00:00
|
|
|
class BaseWebView(BaseView):
|
2017-10-05 19:41:17 +00:00
|
|
|
|
|
|
|
def __init__(self, driver):
|
2021-01-25 16:35:40 +00:00
|
|
|
super().__init__(driver)
|
2017-10-05 19:41:17 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
self.progress_bar_icon = Button(self.driver, xpath="//android.widget.ProgressBar")
|
|
|
|
self.url_edit_box_lock_icon = Button(self.driver, xpath="'(//android.view.ViewGroup[@content-desc='icon'])[2]")
|
2021-06-30 13:45:15 +00:00
|
|
|
self.policy_summary = Button(self.driver, xpath="//*[@content-desc='Status Privacy Policy'] | //*[@text='Status Privacy Policyy']")
|
2021-07-05 19:28:55 +00:00
|
|
|
self.terms_of_use_summary = Button(self.driver, xpath="//*[@content-desc='Status App Terms of Use']")
|
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
self.browser_previous_page_button = Button(self.driver, accessibility_id="previous-page-button")
|
|
|
|
self.browser_next_page_button = Button(self.driver, accessibility_id="next-page-button")
|
2018-02-13 17:22:41 +00:00
|
|
|
|
2021-01-25 16:35:40 +00:00
|
|
|
self.web_view_browser = Button(self.driver, xpath="//*[contains(@text,'WebView Browser Tester')]")
|
|
|
|
self.always_button = Button(self.driver, xpath="//*[contains(@text,'ALWAYS')]")
|
|
|
|
self.browser_refresh_page_button = Button(self.driver, accessibility_id="refresh-page-button")
|
|
|
|
self.share_url_button = Button(self.driver, accessibility_id="share")
|
|
|
|
self.go_back_button = Button(self.driver, translation_id="browsing-site-blocked-go-back")
|
|
|
|
self.options_button = Button(self.driver, accessibility_id="browser-options")
|
2021-03-19 14:51:23 +00:00
|
|
|
self.connect_account_button = Button(self.driver, accessibility_id="connect-account")
|
|
|
|
self.connected_account_button = Button(self.driver, accessibility_id="connected-account")
|
|
|
|
self.open_chat_from_dapp_button = Button(self.driver, accessibility_id="open-chat")
|
|
|
|
self.new_tab_button = Button(self.driver, accessibility_id="new-tab")
|
2021-01-25 16:35:40 +00:00
|
|
|
self.continue_anyway_button = Button(self.driver, translation_id="continue-anyway")
|
|
|
|
self.open_tabs_button = Button(self.driver, accessibility_id="browser-open-tabs")
|
|
|
|
self.close_all_button = Button(self.driver, accessibility_id="close-all")
|
2021-06-14 17:52:58 +00:00
|
|
|
self.empty_tab_button = Button(self.driver, accessibility_id="tab-itemEmpty tab")
|
2021-02-05 11:29:35 +00:00
|
|
|
self.camera_image_in_dapp = BaseElement(self.driver, class_name="android.widget.Image")
|
2021-06-30 13:45:15 +00:00
|
|
|
self.close_privacy_policy_button = Button(self.driver, xpath="//androidx.appcompat.widget.LinearLayoutCompat")
|
2021-06-14 17:52:58 +00:00
|
|
|
|
2020-12-21 13:06:48 +00:00
|
|
|
# bookmarks management
|
2021-01-25 16:35:40 +00:00
|
|
|
self.add_remove_favorites_button = Button(self.driver, accessibility_id="add-remove-fav")
|
|
|
|
self.bookmark_name_input = EditBox(self.driver, accessibility_id="bookmark-input")
|
|
|
|
self.save_bookmark_button = Button(self.driver, accessibility_id="save-bookmark")
|
2020-12-21 13:06:48 +00:00
|
|
|
|
2018-02-07 13:18:55 +00:00
|
|
|
def wait_for_d_aap_to_load(self, wait_time=35):
|
2021-01-25 16:35:40 +00:00
|
|
|
self.driver.info("**Waiting %ss for dapp to load**" % wait_time)
|
2017-10-05 19:41:17 +00:00
|
|
|
counter = 0
|
|
|
|
while self.progress_bar_icon.is_element_present(5):
|
|
|
|
time.sleep(1)
|
|
|
|
counter += 1
|
|
|
|
if counter > wait_time:
|
2018-08-15 12:51:52 +00:00
|
|
|
self.driver.fail("Page is not loaded during %s seconds" % wait_time)
|
2018-07-06 11:10:48 +00:00
|
|
|
|
|
|
|
def open_in_webview(self):
|
2021-01-25 16:35:40 +00:00
|
|
|
self.driver.info("**Opening in webview**")
|
2020-01-21 13:59:01 +00:00
|
|
|
if self.web_view_browser.is_element_displayed():
|
|
|
|
self.web_view_browser.click()
|
2018-10-08 13:10:00 +00:00
|
|
|
if self.always_button.is_element_displayed():
|
|
|
|
self.always_button.click()
|
2020-01-21 13:59:01 +00:00
|
|
|
|
2020-12-11 17:06:40 +00:00
|
|
|
def remove_tab(self, name='', clear_all=False):
|
|
|
|
self.open_tabs_button.click()
|
|
|
|
if clear_all:
|
2021-01-25 16:35:40 +00:00
|
|
|
self.driver.info("**Closing all tabs**")
|
2020-12-11 17:06:40 +00:00
|
|
|
self.close_all_button.click()
|
|
|
|
else:
|
2021-01-25 16:35:40 +00:00
|
|
|
self.driver.info("**Removing '%s' from recent websites**")
|
|
|
|
close_button = Button(self.driver, xpath="//*[contains(@text, '%s')]/../../../../*[@content-desc='empty-tab']"% name)
|
2020-12-11 17:06:40 +00:00
|
|
|
close_button.scroll_to_element()
|
|
|
|
close_button.click()
|
|
|
|
|
2020-12-21 13:06:48 +00:00
|
|
|
def edit_bookmark_name(self, name):
|
2021-01-25 16:35:40 +00:00
|
|
|
self.driver.info("**Editing bookmark name to '%s'**" % name)
|
2020-12-21 13:06:48 +00:00
|
|
|
self.bookmark_name_input.clear()
|
|
|
|
self.bookmark_name_input.send_keys(name)
|
|
|
|
self.save_bookmark_button.click()
|
|
|
|
|
|
|
|
def add_to_bookmarks(self, name=''):
|
2021-01-25 16:35:40 +00:00
|
|
|
self.driver.info("**Adding '%s' to bookmarks**" % name)
|
2020-12-21 13:06:48 +00:00
|
|
|
self.options_button.click()
|
|
|
|
self.add_remove_favorites_button.click()
|
|
|
|
if name:
|
|
|
|
self.edit_bookmark_name(name)
|
|
|
|
bookmark_name = name
|
|
|
|
else:
|
|
|
|
bookmark_name = self.bookmark_name_input.text
|
|
|
|
self.save_bookmark_button.click()
|
|
|
|
return bookmark_name
|
|
|
|
|