Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a new test to click on the signout button #1022

Merged
merged 5 commits into from May 13, 2020

Conversation

kushaldas
Copy link
Contributor

Description

This will only work inside of xvfb-run as set the size of the
display screen, and then click on the screen based on location.

To run only this test use the following command:
xvfb-run --server-args="-screen 0, 1680x1050x24" python -m pytest -v tests/functional/test_user_icon_click.py

While developing a similar test, if one wants to see the status of
the screen, use pyautogui.screenshot(filename) to a screenshot
and then verify manually where to click/type.

Test Plan

  • make sure you xvfb installed.
  • xvfb-run --server-args="-screen 0, 1680x1050x24" python -m pytest -v tests/functional/test_user_icon_click.py
  • `make test-functional

Checklist

If these changes modify code paths involving cryptography, the opening of files in VMs or network (via the RPC service) traffic, Qubes testing in the staging environment is required. For fine tuning of the graphical user interface, testing in any environment in Qubes is required. Please check as applicable:

  • I have tested these changes in the appropriate Qubes environment
  • I do not have an appropriate Qubes OS workstation set up (the reviewer will need to test these changes)
  • These changes should not need testing in Qubes

If these changes add or remove files other than client code, packaging logic (e.g., the AppArmor profile) may need to be updated. Please check as applicable:

  • I have submitted a separate PR to the packaging repo
  • No update to the packaging logic (e.g., AppArmor profile) is required for these changes
  • I don't know and would appreciate guidance

@kushaldas
Copy link
Contributor Author

Now, pyautogui also provides screenshot matching to find the right place to click, https://pyautogui.readthedocs.io/en/latest/screenshot.html#the-locate-functions , but the screenshot tool (I could not find a single one) can not capture the signout menu/action. That is why this current PR clicks on a fixed position based on the fixed display size.

@eloquence eloquence added this to In Development in SecureDrop Team Board Mar 31, 2020
@redshiftzero redshiftzero moved this from In Development to Ready for Review in SecureDrop Team Board Apr 1, 2020
Copy link
Contributor

@redshiftzero redshiftzero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pyautogui seems like a nice tool, dropping a couple of initial thoughts in here

test-functional.sh Show resolved Hide resolved
tests/functional/test_user_icon_click.py Outdated Show resolved Hide resolved
@eloquence
Copy link
Member

eloquence commented Apr 23, 2020

Given the scope of required changes, we've agreed to defer this to the next sprint or later for now, after the current (4/22-5/6) sprint.

@eloquence eloquence moved this from Ready for Review to Near Term - SD Workstation in SecureDrop Team Board Apr 23, 2020
@eloquence eloquence moved this from Near Term - SD Workstation to Nominated for next sprint in SecureDrop Team Board May 5, 2020
@eloquence eloquence moved this from Nominated for next sprint to Sprint #50 - 5/6-5/20 in SecureDrop Team Board May 6, 2020
@kushaldas
Copy link
Contributor Author

Did a timeboxed work on it.

QAction is not a QWidget, QMenu is, but it is returning 0,0 for the widget location. Means we can not click on it :(

diff --git a/tests/functional/test_user_icon_click.py b/tests/functional/test_user_icon_click.py
index 11c8f85..af8550f 100644
--- a/tests/functional/test_user_icon_click.py
+++ b/tests/functional/test_user_icon_click.py
@@ -7,8 +7,9 @@ https://github.com/freedomofpress/securedrop-client/wiki/Test-plan#basic-client-
 import pytest
 import time
 import pyautogui
+from PyQt5.QtCore import QPoint
 
-from .utils import get_safe_tempdir, get_logged_in_test_context
+from .utils import get_safe_tempdir, get_logged_in_test_context, get_clicking_point
 
 
 @pytest.mark.vcr()
@@ -31,11 +32,14 @@ def test_user_icon_click(qtbot, mocker):
 
     qtbot.wait(5000)
     # Now instead of clicking via qtbot, we can click via mouse
-    pyautogui.click(25, 70)
+    point = gui.left_pane.user_profile.user_icon.mapToGlobal(QPoint(0,0))
+    pyautogui.click(get_clicking_point(point))
     # # Now we should have the menu open
     # Also means qtbot if of no use right now
-    time.sleep(0.5)
+    # QMenu returns 0,0 as point
+    # QAction is not a QWidget
+    point = gui.left_pane.user_profile.user_button.menu.mapToGlobal(QPoint(0,0))
     # Let us click on the signout button
-    pyautogui.click(87, 100)
+    pyautogui.click(get_clicking_point(point))
     # Here the eventloop is back with qtbot
     qtbot.waitUntil(check_login_button, timeout=10000)
diff --git a/tests/functional/utils.py b/tests/functional/utils.py
index 55378a8..6456a1a 100644
--- a/tests/functional/utils.py
+++ b/tests/functional/utils.py
@@ -44,6 +44,10 @@ USERNAME = "journalist"
 PASSWORD = "correct horse battery staple profanity oil chewy"
 
 
+def get_clicking_point(point):
+    "returns a tuple of x, y co-ordinates to click"
+    return point.x() + 5, point.y() + 5
+
 def get_safe_tempdir():
     """
     Return the tempdir to be used to isolate each run of the app in a test.

``

kushaldas and others added 5 commits May 12, 2020 17:26
This will only work inside of xvfb-run as set the size of the
display screen, and then click on the screen based on location.

To run only this test use the following command:
xvfb-run --server-args="-screen 0, 1680x1050x24" python -m pytest -v tests/functional/test_user_icon_click.py

While developing a similar test, if one wants to see the status of
the screen, use `pyautogui.screenshot(filename)` to a screenshot
and then verify manually where to click/type.
@redshiftzero redshiftzero marked this pull request as ready for review May 12, 2020 21:48
Copy link
Contributor

@redshiftzero redshiftzero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approving this as my comments are addressed, but not merging to give you an opportunity to take issue with any of my commits @kushaldas (feel free to dismiss my review or drop commits if so)

@redshiftzero redshiftzero moved this from Sprint #50 - 5/6-5/20 to Under Review in SecureDrop Team Board May 12, 2020
@kushaldas
Copy link
Contributor Author

On Linux we will have to add a separate dependency to the scrot package (for screenshot related work). I will wait before if you want it to be added here. Rest worked perfectly.

@redshiftzero
Copy link
Contributor

Ah, let's bring in that additional dependency if/when we use that functionality

@redshiftzero redshiftzero merged commit 1af137c into master May 13, 2020
SecureDrop Team Board automation moved this from Under Review to Done May 13, 2020
@redshiftzero redshiftzero deleted the functional_with_more_clicks branch May 13, 2020 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants