tests refactored for faster runs, updated scenarios for transactions in one-to-one chats

This commit is contained in:
Anton Danchenko 2017-10-13 11:41:30 +03:00
parent 3b824d1821
commit 6c7ca9648f
6 changed files with 193 additions and 190 deletions

View File

@ -7,6 +7,7 @@ from views.home import HomeView
@pytest.mark.all
class TestChats(MultiplyDeviceTestCase):
@pytest.mark.chat
def test_one_to_one_chat(self):
device_1, device_2 = HomeView(self.driver_1), HomeView(self.driver_2)
@ -44,3 +45,76 @@ class TestChats(MultiplyDeviceTestCase):
chats_d2.send_message_button.click()
chats_d1.find_full_text(message_2)
@pytest.mark.chat
def test_group_chat_send_receive_messages_and_remove_user(self):
device_1, device_2 = HomeView(self.driver_1), \
HomeView(self.driver_2)
set_password_as_new_user(device_2, device_1)
device_1.back_button.click()
chats_d1 = device_1.get_chats()
chats_d1.profile_button.click()
profile_d1 = chats_d1.profile_icon.click()
key = profile_d1.public_key_text.text
device_2.back_button.click()
chats_d2 = device_2.get_chats()
chats_d2.plus_button.click()
chats_d2.add_new_contact.click()
chats_d2.public_key_edit_box.send_keys(key)
chats_d2.confirm()
chats_d2.confirm_public_key_button.click()
user_name_d1 = chats_d2.user_name_text.text
device_2.back_button.click()
chats_d2.new_group_chat_button.click()
user_contact = chats_d2.element_by_text(user_name_d1, 'button')
user_contact.scroll_to_element()
user_contact.click()
chats_d2.next_button.click()
chat_name = 'new_chat'
message_1 = 'first SOMETHING'
message_2 = 'second SOMETHING'
message_3 = 'third SOMETHING'
chats_d2.name_edit_box.send_keys(chat_name)
chats_d2.save_button.click()
# send_and_receive_messages
chats_d2.chat_message_input.send_keys(message_1)
chats_d2.send_message_button.click()
profile_d1.back_button.click()
chats_d1 = profile_d1.get_chats()
chats_d1.find_full_text(message_1)
group_chat_d1 = chats_d1.element_by_text(chat_name, 'button')
group_chat_d1.click()
chats_d2.chat_message_input.send_keys(message_2)
chats_d2.send_message_button.click()
chats_d1.find_full_text(message_2)
# remove_user
chats_d2.group_chat_options.click()
chats_d2.chat_settings.click()
chats_d2.confirm()
chats_d2.user_options.click()
chats_d2.remove_button.click()
device_2.back_button.click()
# chats_d2.find_full_text("You\'ve removed " + user_name_d1)
chats_d2.chat_message_input.send_keys(message_3)
chats_d2.send_message_button.click()
chats_d1.find_text_part("removed you from group chat")
message_text = chats_d1.element_by_text(message_3, 'text')
if message_text.is_element_present(20):
pytest.fail('Message is shown for the user which has been removed from the GroupChat', False)

View File

@ -1,81 +0,0 @@
import pytest
from tests.basetestcase import MultiplyDeviceTestCase
from tests.preconditions import set_password_as_new_user
from views.home import HomeView
@pytest.mark.all
class TestGroupChats(MultiplyDeviceTestCase):
@pytest.mark.chat
def test_group_chat_send_receive_messages_and_remove_user(self):
device_1, device_2 = HomeView(self.driver_1), \
HomeView(self.driver_2)
set_password_as_new_user(device_2, device_1)
device_1.back_button.click()
chats_d1 = device_1.get_chats()
chats_d1.profile_button.click()
profile_d1 = chats_d1.profile_icon.click()
key = profile_d1.public_key_text.text
device_2.back_button.click()
chats_d2 = device_2.get_chats()
chats_d2.plus_button.click()
chats_d2.add_new_contact.click()
chats_d2.public_key_edit_box.send_keys(key)
chats_d2.confirm()
chats_d2.confirm_public_key_button.click()
user_name_d1 = chats_d2.user_name_text.text
device_2.back_button.click()
chats_d2.new_group_chat_button.click()
user_contact = chats_d2.element_by_text(user_name_d1, 'button')
user_contact.scroll_to_element()
user_contact.click()
chats_d2.next_button.click()
chat_name = 'new_chat'
message_1 = 'first SOMETHING'
message_2 = 'second SOMETHING'
message_3 = 'third SOMETHING'
chats_d2.name_edit_box.send_keys(chat_name)
chats_d2.save_button.click()
# send_and_receive_messages
chats_d2.chat_message_input.send_keys(message_1)
chats_d2.send_message_button.click()
profile_d1.back_button.click()
chats_d1 = profile_d1.get_chats()
chats_d1.find_full_text(message_1)
group_chat_d1 = chats_d1.element_by_text(chat_name, 'button')
group_chat_d1.click()
chats_d2.chat_message_input.send_keys(message_2)
chats_d2.send_message_button.click()
chats_d1.find_full_text(message_2)
# remove_user
chats_d2.group_chat_options.click()
chats_d2.chat_settings.click()
chats_d2.confirm()
chats_d2.user_options.click()
chats_d2.remove_button.click()
device_2.back_button.click()
# chats_d2.find_full_text("You\'ve removed " + user_name_d1)
chats_d2.chat_message_input.send_keys(message_3)
chats_d2.send_message_button.click()
chats_d1.find_text_part("removed you from group chat")
message_text = chats_d1.element_by_text(message_3, 'text')
if message_text.is_element_present(20):
pytest.fail('Message is shown for the user which has been removed from the GroupChat', False)

View File

@ -1,4 +1,5 @@
import pytest
from itertools import combinations_with_replacement
from tests.basetestcase import MultiplyDeviceTestCase, SingleDeviceTestCase
from tests.preconditions import set_password_as_new_user
from views.home import HomeView
@ -27,21 +28,13 @@ class TestNetwork(SingleDeviceTestCase):
class TestNetworkChats(MultiplyDeviceTestCase):
networks = [['Ropsten', 'Ropsten with upstream RPC'], ['Ropsten', 'Rinkeby'],
['Ropsten', 'Rinkeby with upstream RPC'], ['Ropsten', 'Mainnet'],
['Ropsten', 'Mainnet with upstream RPC'], ['Ropsten', 'Ropsten'],
['Ropsten with upstream RPC', 'Ropsten with upstream RPC'], ['Ropsten with upstream RPC', 'Rinkeby'],
['Ropsten with upstream RPC', 'Rinkeby with upstream RPC'], ['Ropsten with upstream RPC', 'Mainnet'],
['Ropsten with upstream RPC', 'Mainnet with upstream RPC'], ['Rinkeby', 'Rinkeby'],
['Rinkeby', 'Rinkeby with upstream RPC'], ['Rinkeby', 'Mainnet'],
['Rinkeby', 'Mainnet with upstream RPC'], ['Rinkeby with upstream RPC', 'Rinkeby with upstream RPC'],
['Rinkeby with upstream RPC', 'Mainnet'], ['Rinkeby with upstream RPC', 'Mainnet with upstream RPC'],
['Mainnet', 'Mainnet'], ['Mainnet', 'Mainnet with upstream RPC'],
['Mainnet with upstream RPC', 'Mainnet with upstream RPC']]
network_combinations = list(combinations_with_replacement(
['Ropsten', 'Rinkeby', 'Mainnet',
'Rinkeby with upstream RPC', 'Mainnet with upstream RPC', 'Rinkeby with upstream RPC'], 2))
@pytest.mark.network_chat
@pytest.mark.parametrize("network", networks,
ids=[i[0] + ' & ' + i[1] for i in networks])
@pytest.mark.parametrize("network", network_combinations,
ids=[i[0] + ' & ' + i[1] for i in network_combinations])
def test_one_to_one_chat_between(self, network):
device_1, device_2 = HomeView(self.driver_1), HomeView(self.driver_2)
set_password_as_new_user(device_1, device_2)

View File

@ -2,8 +2,8 @@ import pytest
import time
from tests.basetestcase import SingleDeviceTestCase
from views.home import HomeView
from tests.preconditions import set_password_as_new_user, recover_access
from tests import basic_user, transaction_users
from tests.preconditions import set_password_as_new_user
from tests import basic_user
@pytest.mark.all
@ -62,96 +62,3 @@ class TestAccess(SingleDeviceTestCase):
home.chat_request_input.send_keys("qwerty1234")
home.confirm()
home.find_full_text(verifications[verification]["outcome"])
@pytest.mark.transaction
@pytest.mark.parametrize("test, recipient, sender", [('group_chat', 'A_USER', 'B_USER'),
('one_to_one_chat', 'B_USER', 'A_USER'),
('wrong_password', 'A_USER', 'B_USER')],
ids=['group_chat', 'one_to_one_chat', 'wrong_password'])
def test_send_transaction(self, test, recipient, sender):
home = HomeView(self.driver)
set_password_as_new_user(home)
chats = home.get_chats()
recover_access(chats,
transaction_users[sender]['passphrase'],
transaction_users[sender]['password'],
transaction_users[sender]['username'])
chats.wait_for_syncing_complete()
sender_address = transaction_users[sender]['address']
recipient_address = transaction_users[recipient]['address']
recipient_key = transaction_users[recipient]['public_key']
initial_balance_recipient = chats.get_balance(recipient_address)
if chats.get_balance(sender_address) < 1000000000000000000:
chats.get_donate(sender_address)
chats.plus_button.click()
chats.add_new_contact.click()
chats.public_key_edit_box.send_keys(recipient_key)
chats.confirm()
chats.confirm_public_key_button.click()
if test == 'group_chat':
user_name = chats.user_name_text.text
chats.back_button.click()
chats.new_group_chat_button.click()
user_contact = chats.element_by_text(user_name, 'button')
user_contact.scroll_to_element()
user_contact.click()
chats.next_button.click()
chats.name_edit_box.send_keys('chat_send_transaction')
chats.save_button.click()
chats.send_funds_button.click()
chats.first_recipient_button.click()
chats.send_as_keyevent('0,1')
chats.send_message_button.click()
chats.sign_transaction_button.wait_for_element(20)
chats.sign_transaction_button.click()
if test == 'wrong_password':
chats.enter_password_input.send_keys('invalid')
chats.sign_transaction_button.click()
chats.find_full_text('Wrong password', 20)
else:
chats.enter_password_input.send_keys(transaction_users[recipient]['password'])
chats.sign_transaction_button.click()
chats.find_full_text('0.1')
chats.find_full_text('Sent', 60)
if test == 'group_chat':
chats.find_full_text('to ' + transaction_users[recipient]['username'], 60)
chats.verify_balance_is_updated(initial_balance_recipient, recipient_address)
@pytest.mark.transaction
def test_send_transaction_from_daap(self):
home = HomeView(self.driver)
set_password_as_new_user(home)
chats = home.get_chats()
address = transaction_users['B_USER']['address']
initial_balance = chats.get_balance(address)
recover_access(chats,
transaction_users['B_USER']['passphrase'],
transaction_users['B_USER']['password'],
transaction_users['B_USER']['username'])
if chats.get_balance(address) < 1000000000000000000:
chats.get_donate(address)
contacts = chats.contacts_button.click()
auction_house = contacts.auction_house_button.click()
auction_house.toggle_navigation_button.click()
auction_house.new_auction_button.click()
auction_house.name_to_reserve_input.click()
auction_name = time.strftime('%Y-%m-%d-%H-%M')
auction_house.send_as_keyevent(auction_name)
auction_house.register_name_button.click()
chats.sign_transaction_button.wait_for_element(20)
chats.sign_transaction_button.click()
chats.enter_password_input.send_keys(transaction_users['B_USER']['password'])
chats.sign_transaction_button.click()
auction_house.find_full_text('You are the proud owner of the name: ' + auction_name, 120)
chats.verify_balance_is_updated(initial_balance, address)

View File

@ -0,0 +1,106 @@
import pytest
import time
from tests.basetestcase import SingleDeviceTestCase
from views.home import HomeView
from tests.preconditions import set_password_as_new_user, recover_access
from tests import transaction_users
@pytest.mark.all
class TestTransactions(SingleDeviceTestCase):
@pytest.mark.transaction
@pytest.mark.parametrize("test, recipient, sender", [('group_chat', 'A_USER', 'B_USER'),
('one_to_one_chat', 'B_USER', 'A_USER'),
('wrong_password', 'A_USER', 'B_USER')],
ids=['group_chat', 'one_to_one_chat', 'wrong_password'])
def test_send_transaction(self, test, recipient, sender):
home = HomeView(self.driver)
set_password_as_new_user(home)
chats = home.get_chats()
recover_access(chats,
transaction_users[sender]['passphrase'],
transaction_users[sender]['password'],
transaction_users[sender]['username'])
chats.wait_for_syncing_complete()
sender_address = transaction_users[sender]['address']
recipient_address = transaction_users[recipient]['address']
recipient_key = transaction_users[recipient]['public_key']
initial_balance_recipient = chats.get_balance(recipient_address)
if chats.get_balance(sender_address) < 1000000000000000000:
chats.get_donate(sender_address)
chats.plus_button.click()
chats.add_new_contact.click()
chats.public_key_edit_box.send_keys(recipient_key)
chats.confirm()
chats.confirm_public_key_button.click()
if test == 'group_chat':
user_name = chats.user_name_text.text
chats.back_button.click()
chats.new_group_chat_button.click()
user_contact = chats.element_by_text(user_name, 'button')
user_contact.scroll_to_element()
user_contact.click()
chats.next_button.click()
chats.name_edit_box.send_keys('chat_send_transaction')
chats.save_button.click()
chats.send_funds_button.click()
if test == 'group_chat':
chats.first_recipient_button.click()
chats.send_as_keyevent('0,1')
else:
chats.send_as_keyevent('0,1')
chats.send_message_button.click()
chats.sign_transaction_button.wait_for_element(20)
chats.sign_transaction_button.click()
if test == 'wrong_password':
chats.enter_password_input.send_keys('invalid')
chats.sign_transaction_button.click()
chats.find_full_text('Wrong password', 20)
else:
chats.enter_password_input.send_keys(transaction_users[recipient]['password'])
chats.sign_transaction_button.click()
chats.find_full_text('0.1')
chats.find_full_text('Sent', 60)
if test == 'group_chat':
chats.find_full_text('to ' + transaction_users[recipient]['username'], 60)
chats.verify_balance_is_updated(initial_balance_recipient, recipient_address)
@pytest.mark.transaction
def test_send_transaction_from_daap(self):
home = HomeView(self.driver)
set_password_as_new_user(home)
chats = home.get_chats()
address = transaction_users['B_USER']['address']
initial_balance = chats.get_balance(address)
recover_access(chats,
transaction_users['B_USER']['passphrase'],
transaction_users['B_USER']['password'],
transaction_users['B_USER']['username'])
if chats.get_balance(address) < 1000000000000000000:
chats.get_donate(address)
contacts = chats.contacts_button.click()
auction_house = contacts.auction_house_button.click()
auction_house.toggle_navigation_button.click()
auction_house.new_auction_button.click()
auction_house.name_to_reserve_input.click()
auction_name = time.strftime('%Y-%m-%d-%H-%M')
auction_house.send_as_keyevent(auction_name)
auction_house.register_name_button.click()
chats.sign_transaction_button.wait_for_element(20)
chats.sign_transaction_button.click()
chats.enter_password_input.send_keys(transaction_users['B_USER']['password'])
chats.sign_transaction_button.click()
auction_house.find_full_text('You are the proud owner of the name: ' + auction_name, 120)
chats.verify_balance_is_updated(initial_balance, address)

View File

@ -79,7 +79,11 @@ class BaseViewObject(object):
def get_balance(self, address):
url = 'http://ropsten.etherscan.io/api?module=account&action=balance&address=0x%s&tag=latest' % address
return int(requests.request('GET', url).json()["result"])
for i in range(5):
try:
return int(requests.request('GET', url).json()["result"])
except ValueError:
pass
def get_donate(self, address, wait_time=300):
initial_balance = self.get_balance(address)