test(FavouriteSavedAddresses/Wallet): test toggle favourite for saved addresses

Also
- fix the other saved addresses that were relying on the order of
buttons and fail after adding the favourite button
- improve the rest of the tests
- improve debug buttons
- extend driver with helper functions

Closes: #6898
This commit is contained in:
Stefan 2022-08-24 10:23:43 +02:00 committed by Stefan Dunca
parent 7af95eaada
commit 6e78281d99
9 changed files with 127 additions and 76 deletions

View File

@ -14,3 +14,6 @@ def input_text(text: str, objName: str):
def object_not_enabled(objName: str):
verify_object_enabled(objName, 500, False)
def str_to_bool(string: str):
return string.lower() in ["yes", "true", "1", "y", "enabled"]

View File

@ -86,11 +86,7 @@ def get_child(obj, child_index=None):
# It executes the click action into the given object:
def click_obj(obj):
try:
squish.mouseClick(obj, squish.Qt.LeftButton)
return True
except LookupError:
return False
# It executes the right-click action into the given object:
def right_click_obj(obj):
@ -104,8 +100,8 @@ def get_obj(objName: str):
obj = squish.findObject(getattr(names, objName))
return obj
def wait_and_get_obj(objName: str):
obj = squish.waitForObject(getattr(names, objName))
def wait_and_get_obj(objName: str, timeout: int=_MAX_WAIT_OBJ_TIMEOUT):
obj = squish.waitForObject(getattr(names, objName), timeout)
return obj
def get_and_click_obj(obj_name: str):
@ -322,3 +318,24 @@ def verify_not_found(realNameVarName: str, message: str, timeoutMSec: int = 500)
def grabScreenshot_and_save(obj, imageName:str, delay:int = 0):
img = object.grabScreenshot(obj, {"delay": delay})
img.save(_SEARCH_IMAGES_PATH + imageName + ".png")
def wait_for_prop_value(object, propertyName, value, timeoutMSec: int = 2000):
start = time.time()
while(start + timeoutMSec / 1000 > time.time()):
propertyNames = propertyName.split('.')
objThenVal = object
for name in propertyNames:
objThenVal = getattr(objThenVal, name)
if objThenVal == value:
return
squish.snooze(0.1)
raise Exception(f'Failed to match value "{value}" for property "{propertyName}" before timeout {timeoutMSec}ms; actual value: "{objThenVal}"')
def get_child_item_with_object_name(item, objectName: str):
for index in range(item.components.count()):
if item.components.at(index).objectName == objectName:
return item.components.at(index)
raise Exception("Could not find child component with object name '{}'".format(objectName))
def sleep_test(seconds: float):
squish.snooze(seconds)

View File

@ -4,7 +4,7 @@ import sys
from drivers.SquishDriver import *
from drivers.SquishDriverVerification import *
from common.SeedUtils import *
from .StatusMainScreen import StatusMainScreen
class SigningPhrasePopUp(Enum):
OK_GOT_IT_BUTTON: str = "signPhrase_Ok_Button"
@ -30,6 +30,8 @@ class SavedAddressesScreen(Enum):
EDIT: str = "mainWallet_Saved_Addreses_More_Edit"
DELETE: str = "mainWallet_Saved_Addreses_More_Delete"
CONFIRM_DELETE: str = "mainWallet_Saved_Addreses_More_Confirm_Delete"
DELEGATE_MENU_BUTTON_OBJECT_NAME: str = "savedAddressView_Delegate_menuButton"
DELEGATE_FAVOURITE_BUTTON_OBJECT_NAME: str = "savedAddressView_Delegate_favouriteButton"
class AddSavedAddressPopup(Enum):
NAME_INPUT: str = "mainWallet_Saved_Addreses_Popup_Name_Input"
@ -192,39 +194,55 @@ class StatusWalletScreen:
type(AddSavedAddressPopup.ADDRESS_INPUT.value, address)
click_obj_by_name(AddSavedAddressPopup.ADD_BUTTON.value)
def edit_saved_address(self, name: str, new_name: str):
list = get_obj(SavedAddressesScreen.SAVED_ADDRESSES_LIST.value)
def _get_saved_address_delegate_item(self, name: str):
list = wait_and_get_obj(SavedAddressesScreen.SAVED_ADDRESSES_LIST.value)
found = -1
for index in range(list.count):
if list.itemAtIndex(index).objectName == name:
if list.itemAtIndex(index).objectName == f"savedAddressView_Delegate_{name}":
found = index
assert found != -1, "saved address not found"
return list.itemAtIndex(found)
# More icon is at index 2
time.sleep(1)
click_obj(list.itemAtIndex(found).components.at(2))
def _find_saved_address_and_open_menu(self, name: str):
item = self._get_saved_address_delegate_item(name)
obj = get_child_item_with_object_name(item, SavedAddressesScreen.DELEGATE_MENU_BUTTON_OBJECT_NAME.value)
click_obj(obj)
def edit_saved_address(self, name: str, new_name: str):
StatusMainScreen.wait_for_banner_to_disappear()
self._find_saved_address_and_open_menu(name)
click_obj_by_name(SavedAddressesScreen.EDIT.value)
type(AddSavedAddressPopup.NAME_INPUT.value, new_name)
click_obj_by_name(AddSavedAddressPopup.ADD_BUTTON.value)
def delete_saved_address(self, name: str):
list = get_obj(SavedAddressesScreen.SAVED_ADDRESSES_LIST.value)
found = -1
for index in range(list.count):
if list.itemAtIndex(index).objectName == name:
found = index
StatusMainScreen.wait_for_banner_to_disappear()
assert found != -1, "saved address not found"
# More icon is at index 2
time.sleep(1)
click_obj(list.itemAtIndex(found).components.at(2))
self._find_saved_address_and_open_menu(name)
click_obj_by_name(SavedAddressesScreen.DELETE.value)
click_obj_by_name(SavedAddressesScreen.CONFIRM_DELETE.value)
def toggle_favourite_for_saved_address(self, name: str):
StatusMainScreen.wait_for_banner_to_disappear()
# Find the saved address and click favourite to toggle
item = self._get_saved_address_delegate_item(name)
favouriteButton = get_child_item_with_object_name(item, SavedAddressesScreen.DELEGATE_FAVOURITE_BUTTON_OBJECT_NAME.value)
click_obj(favouriteButton)
def check_favourite_status_for_saved_address(self, name: str, favourite: bool):
# Find the saved address
item = self._get_saved_address_delegate_item(name)
favouriteButton = get_child_item_with_object_name(item, SavedAddressesScreen.DELEGATE_FAVOURITE_BUTTON_OBJECT_NAME.value)
# if favourite is true, check that the favourite shows "unfavourite" icon and vice versa
wait_for_prop_value(favouriteButton, "icon.name", ("unfavourite" if favourite else "favourite"))
wait_for_prop_value(item, "titleTextIcon", ("star-icon" if favourite else ""))
def toggle_network(self, network_name: str):
click_obj_by_name(MainWalletScreen.NETWORK_SELECTOR_BUTTON.value)
@ -250,18 +268,24 @@ class StatusWalletScreen:
assert False, "symbol not found"
def verify_saved_address_exists(self, name: str):
list = get_obj(SavedAddressesScreen.SAVED_ADDRESSES_LIST.value)
list = wait_and_get_obj(SavedAddressesScreen.SAVED_ADDRESSES_LIST.value)
for index in range(list.count):
if list.itemAtIndex(index).objectName == name:
if list.itemAtIndex(index).objectName == f"savedAddressView_Delegate_{name}":
return
assert False, "no saved address found"
verify_failure(f'FAIL: saved address {name} not found"')
def verify_saved_address_doesnt_exist(self, name: str):
list = get_obj(SavedAddressesScreen.SAVED_ADDRESSES_LIST.value)
# The list should be hidden when there are no saved addresses
try:
list = wait_and_get_obj(SavedAddressesScreen.SAVED_ADDRESSES_LIST.value, 250)
except LookupError:
return
list = wait_and_get_obj(SavedAddressesScreen.SAVED_ADDRESSES_LIST.value)
for index in range(list.count):
if list.itemAtIndex(index).objectName == name:
assert False, "saved address found"
if list.itemAtIndex(index).objectName == f"savedAddressView_Delegate_{name}":
verify_failure(f'FAIL: saved address {name} exists')
def verify_transaction(self):
print("TODO: fix notification and ensure there is one")

View File

@ -2,14 +2,15 @@
import squish
import object
import names
import test
def debugWaitForObject(objRealName: dict, timeoutMSec: int = 1000):
def wait_for_object(objRealName: dict, timeoutMSec: int = 1000):
return squish.waitForObject(objRealName, timeoutMSec)
def type_text(obj, text: str):
squish.type(obj, text)
def find_object(objRealName: dict):
obj = squish.findObject(objRealName)
return squish.findObject(objRealName)
def wait_for_object_exists(objRealName: dict, timeoutMSec: int = 1000):
return squish.waitForObjectExists(objRealName, timeoutMSec)

View File

@ -58,7 +58,7 @@ mainWallet_Add_Account_Popup_Footer_Add_Account = {"container": mainWallet_Add_A
# saved address view
mainWallet_Saved_Addreses_Add_Buttton = {"container": statusDesktop_mainWindow, "objectName": "addNewAddressBtn", "type": "StatusButton"}
mainWallet_Saved_Addreses_List = {"container": statusDesktop_mainWindow, "objectName": "savedAddresses", "type": "StatusListView"}
mainWallet_Saved_Addreses_List = {"container": statusDesktop_mainWindow, "objectName": "SavedAddressesView_savedAddresses", "type": "StatusListView"}
mainWallet_Saved_Addreses_More_Edit = {"container": statusDesktop_mainWindow, "objectName": "editSavedAddress", "type": "StatusMenuItemDelegate"}
mainWallet_Saved_Addreses_More_Delete = {"container": statusDesktop_mainWindow, "objectName": "deleteSavedAddress", "type": "StatusMenuItemDelegate"}
mainWallet_Saved_Addreses_More_Confirm_Delete = {"container": statusDesktop_mainWindow, "objectName": "confirmDeleteSavedAddress", "type": "StatusButton"}

View File

@ -1,5 +1,6 @@
from screens.StatusWalletScreen import StatusWalletScreen
from scripts.decorators import verify_screenshot
from common.Common import str_to_bool
_statusMain = StatusMainScreen()
_walletScreen = StatusWalletScreen()
@ -45,6 +46,14 @@ def step(context, name, new_name):
def step(context, name):
_walletScreen.delete_saved_address(name)
@When("the user toggles favourite for the saved address with name |any|")
def step(context, name):
_walletScreen.toggle_favourite_for_saved_address(name)
@Then("the saved address |any| has favourite status |any|")
def step(context, name, favourite):
_walletScreen.check_favourite_status_for_saved_address(name, str_to_bool(favourite))
@When("the user toggles the network |any|")
def step(context, network_name):
_walletScreen.toggle_network(network_name)

View File

@ -80,23 +80,16 @@ Feature: Status Desktop Wallet
| name | address |
| one | 0x8397bc3c5a60a1883174f722403d63a8833312b7 |
Scenario Outline: User can edit a saved address
Scenario Outline: User can toggle favourite for a saved address
When the user adds a saved address named <name> and address <address>
And the user edits a saved address with name <name> to <new_name>
Then the name <new_name><name> is in the list of saved addresses
Examples:
| name | address | new_name |
| bar | 0x8397bc3c5a60a1883174f722403d63a8833312b7 | foo |
Scenario Outline: User can delete a saved address
When the user adds a saved address named <name> and address <address>
And the user deletes the saved address with name <name>
Then the name <name> is not in the list of saved addresses
And the user toggles favourite for the saved address with name <name>
Then the saved address <name> has favourite status true
When the user toggles favourite for the saved address with name <name>
Then the saved address <name> has favourite status false
Examples:
| name | address |
| one | 0x8397bc3c5a60a1883174f722403d63a8833312b7 |
| favourite | 0x8397bc3c5a60a1883174f722403d63a8833312b7 |
@mayfail
Scenario: User can toggle network and see balances
@ -120,7 +113,7 @@ Feature: Status Desktop Wallet
| new_name | new_color |
| Default | #FFCA0F |
Scenario Outline: Can see collectibles for an account
Scenario Outline: Can see collectibles for an account
When the user adds watch only account with <account_name> and <address>
Then the collectibles are listed for the <account_name>

View File

@ -94,7 +94,7 @@ Item {
StatusListView {
id: listView
objectName: "savedAddresses"
objectName: "SavedAddressesView_savedAddresses"
anchors.top: errorMessage.bottom
anchors.topMargin: Style.current.padding
anchors.bottom: parent.bottom
@ -105,6 +105,8 @@ Item {
spacing: 5
model: RootStore.savedAddresses
delegate: SavedAddressesDelegate {
objectName: "savedAddressView_Delegate_" + name
name: model.name
address: model.address
favourite: model.favourite

View File

@ -56,6 +56,7 @@ StatusListItem {
textToCopy: root.address
},
StatusRoundButton {
objectName: "savedAddressView_Delegate_favouriteButton"
icon.color: root.showButtons ? Theme.palette.directColor1 : Theme.palette.baseColor1
type: StatusRoundButton.Type.Tertiary
icon.name: root.favourite ? "unfavourite" : "favourite"
@ -64,6 +65,7 @@ StatusListItem {
}
},
StatusRoundButton {
objectName: "savedAddressView_Delegate_menuButton"
visible: !!root.name
icon.color: root.showButtons ? Theme.palette.directColor1 : Theme.palette.baseColor1
type: StatusRoundButton.Type.Tertiary