From 9a51a46869a5395e686d4cb6dae2eafbf4db91f8 Mon Sep 17 00:00:00 2001 From: Serhy Date: Fri, 5 Feb 2021 13:29:35 +0200 Subject: [PATCH] Webview camera permission Signed-off-by: Serhy --- test/appium/requirements.txt | 1 + .../atomic/dapps_and_browsing/test_dapps.py | 53 ++++++++++++++++++ test/appium/views/base_element.py | 11 ++++ test/appium/views/base_view.py | 3 + .../elements_templates/blank_camera_image.png | Bin 0 -> 383 bytes test/appium/views/web_views/base_web_view.py | 3 +- 6 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 test/appium/views/elements_templates/blank_camera_image.png diff --git a/test/appium/requirements.txt b/test/appium/requirements.txt index c2e44cdcd5..d5e8c309cd 100644 --- a/test/appium/requirements.txt +++ b/test/appium/requirements.txt @@ -49,3 +49,4 @@ zbarlight==3.0 docker==4.4.0 influxdb==5.3.1 web3 +imagehash diff --git a/test/appium/tests/atomic/dapps_and_browsing/test_dapps.py b/test/appium/tests/atomic/dapps_and_browsing/test_dapps.py index 380120d91f..67d05a8c7c 100644 --- a/test/appium/tests/atomic/dapps_and_browsing/test_dapps.py +++ b/test/appium/tests/atomic/dapps_and_browsing/test_dapps.py @@ -36,6 +36,59 @@ class TestDApps(SingleDeviceTestCase): if not status_test_dapp.element_by_text(user['public_key']).is_element_displayed(): self.driver.fail('Public key is not returned') + + @marks.testrail_id(6635) + @marks.medium + def test_webview_camera_permission(self): + web_view_camera_url = 'https://simpledapp.status.im/webviewtest/webviewcamera.html' + home = SignInView(self.driver).create_user() + self.driver.set_clipboard_text(web_view_camera_url) + dapp = home.dapp_tab_button.click() + dapp.enter_url_editbox.click() + dapp.paste_text() + dapp.confirm() + + from views.web_views.base_web_view import BaseWebView + camera_dapp = BaseWebView(self.driver) + camera_dapp.just_fyi("Check camera request blocked (because it's not enabled in app yet)") + camera_request_blocked = home.get_translation_by_key("page-camera-request-blocked") + if not dapp.element_by_text_part(camera_request_blocked).is_element_displayed(): + self.driver.fail("There is no pop-up notifying that camera access need to be granted in app") + camera_dapp.swipe_down() + if not camera_dapp.camera_image_in_dapp.is_element_image_similar_to_template('blank_camera_image.png'): + self.driver.fail("Even camera permissions not allowed - acccess to camera granted") + + profile = home.profile_button.click() + profile.privacy_and_security_button.click() + + camera_dapp.just_fyi("Enable camera requests in Dapps") + camera_permission_requests = home.get_translation_by_key("webview-camera-permission-requests") + if profile.element_by_text_part(camera_permission_requests).is_element_displayed(): + profile.element_by_text_part('Webview camera permission requests').click() + home.dapp_tab_button.click(desired_element_text='webview') + + camera_dapp.just_fyi("Check DApp asks now to allow camera aceess but Deny in DApp") + camera_dapp.browser_refresh_page_button.click() + camera_dapp.deny_button.click() + if not camera_dapp.camera_image_in_dapp.is_element_image_similar_to_template('blank_camera_image.png'): + self.driver.fail("Even camera access Denied to Dapp, - acccess to camera granted") + + camera_dapp.just_fyi("Check DApp asks now to allow camera aceess and Allow access to DApp") + camera_dapp.browser_refresh_page_button.click() + camera_dapp.allow_button.click() + if camera_dapp.camera_image_in_dapp.is_element_image_similar_to_template('blank_camera_image.png'): + camera_dapp.camera_image_in_dapp.save_new_screenshot_of_element('blank_camera_image3.png') + self.driver.fail("Even camera access Accepted to Dapp, - camera view is not shown") + + camera_dapp.just_fyi("Relogin and check camera access still needs to be allowed") + home.profile_button.click() + profile.relogin() + home.dapp_tab_button.click() + camera_dapp.open_tabs_button.click() + dapp.element_by_text_part("https").click() + if not camera_dapp.allow_button.is_element_displayed(): + self.driver.fail("No request to camera access after relogin") + @marks.testrail_id(6323) @marks.medium @marks.flaky diff --git a/test/appium/views/base_element.py b/test/appium/views/base_element.py index fd499a74b9..8c00e5006c 100644 --- a/test/appium/views/base_element.py +++ b/test/appium/views/base_element.py @@ -11,6 +11,7 @@ from selenium.common.exceptions import NoSuchElementException from selenium.common.exceptions import TimeoutException from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support import expected_conditions +import imagehash from tests import transl @@ -26,6 +27,7 @@ class BaseElement(object): self.prefix='' self.suffix = None self.id = None + self.class_name = None self.webview = None self.__dict__.update(kwargs) @@ -47,6 +49,9 @@ class BaseElement(object): elif self.id: self.by = MobileBy.ID self.locator = self.id + elif self.class_name: + self.by = MobileBy.CLASS_NAME + self.locator = self.class_name elif self.webview: self.locator = '//*[@text="{0}"] | //*[@content-desc="{desc}"]'.format(self.webview, desc=self.webview) if self.prefix: @@ -201,6 +206,12 @@ class BaseElement(object): self.template = file_name return not ImageChops.difference(self.image, self.template).getbbox() + def is_element_image_similar_to_template(self, template_path: str = ''): + image_template = os.sep.join(__file__.split(os.sep)[:-1]) + '/elements_templates/%s' % template_path + template = imagehash.average_hash(Image.open(image_template)) + element_image = imagehash.average_hash(self.image) + return not bool(template-element_image) + def swipe_left_on_element(self): element = self.find_element() location, size = element.location, element.size diff --git a/test/appium/views/base_view.py b/test/appium/views/base_view.py index 3efed21003..99836d23bb 100644 --- a/test/appium/views/base_view.py +++ b/test/appium/views/base_view.py @@ -90,6 +90,8 @@ class DappTabButton(TabButton): from views.dapps_view import DappsView if desired_element_text == 'enter_url': self.click_until_presence_of_element(DappsView(self.driver).enter_url_editbox) + if desired_element_text == 'webview': + self.find_element().click() else: base_view = BaseView(self.driver) self.click_until_presence_of_element(base_view.element_by_text_part(desired_element_text)) @@ -312,6 +314,7 @@ class BaseView(object): def just_fyi(self, string): self.driver.info('=========================================================================') self.driver.info(string) + self.driver.info('=========================================================================') def click_system_back_button(self, times=1): self.driver.info('*Click system back button*') diff --git a/test/appium/views/elements_templates/blank_camera_image.png b/test/appium/views/elements_templates/blank_camera_image.png new file mode 100644 index 0000000000000000000000000000000000000000..1d6891597c1cd0ec456e1dd89f2dad50ce6baea5 GIT binary patch literal 383 zcmeAS@N?(olHy`uVBq!ia0vp^r9fQH!3HF4&+u<&U|@9fba4!+nDh4HLCzKf28M%k zo=l$p_4Y#5AD?G&aGdsG<^H{U-D}w;XMXQH9`*V)pV_SJwT1JZUzg1(sgXTUw~TG3 qR7%!_m5w8nVKV=@