Webview camera permission

Signed-off-by: Serhy <sergii@status.im>
This commit is contained in:
Serhy 2021-02-05 13:29:35 +02:00
parent 0867b972c3
commit 9a51a46869
No known key found for this signature in database
GPG Key ID: 5D7C4B9E2B6F500B
6 changed files with 70 additions and 1 deletions

View File

@ -49,3 +49,4 @@ zbarlight==3.0
docker==4.4.0
influxdb==5.3.1
web3
imagehash

View File

@ -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

View File

@ -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

View File

@ -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*')

Binary file not shown.

After

Width:  |  Height:  |  Size: 383 B

View File

@ -1,6 +1,6 @@
import time
from views.base_element import EditBox, Button
from views.base_element import EditBox, Button, BaseElement
from views.base_view import BaseView
class BaseWebView(BaseView):
@ -24,6 +24,7 @@ class BaseWebView(BaseView):
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")
self.camera_image_in_dapp = BaseElement(self.driver, class_name="android.widget.Image")
# bookmarks management
self.add_remove_favorites_button = Button(self.driver, accessibility_id="add-remove-fav")