From 4a02a332260f7c57d6ef98e442e844247a5b9a16 Mon Sep 17 00:00:00 2001 From: shekhar-cis Date: Tue, 28 Sep 2021 19:30:15 +0530 Subject: [PATCH] Added populate_test_data method --- src/bitmessagekivy/tests/telenium_process.py | 20 ++--- .../tests/test_create_random_address.py | 33 +++----- src/bitmessagekivy/tests/test_sent_message.py | 83 ++++++++----------- 3 files changed, 59 insertions(+), 77 deletions(-) diff --git a/src/bitmessagekivy/tests/telenium_process.py b/src/bitmessagekivy/tests/telenium_process.py index 7122c12a..1c33cc9c 100644 --- a/src/bitmessagekivy/tests/telenium_process.py +++ b/src/bitmessagekivy/tests/telenium_process.py @@ -29,15 +29,6 @@ def cleanup(files=_files): pass -def populate_test_data(): - """Set temp data in tmp directory""" - for file_name in tmp_db_file: - old_source_file = os.path.join( - os.path.abspath(os.path.dirname(__file__)), 'sampleData', file_name) - new_destination_file = os.path.join(os.environ['BITMESSAGE_HOME'], file_name) - shutil.copyfile(old_source_file, new_destination_file) - - class TeleniumTestProcess(TeleniumTestCase): """Setting Screen Functionality Testing""" cmd_entrypoint = [os.path.join(os.path.abspath(os.getcwd()), 'src', 'main_test.py')] @@ -46,9 +37,18 @@ class TeleniumTestProcess(TeleniumTestCase): def setUpClass(cls): """Setupclass is for setting temp environment""" os.environ["BITMESSAGE_HOME"] = tempfile.gettempdir() - populate_test_data() + cls.populate_test_data() super(TeleniumTestProcess, cls).setUpClass() + @staticmethod + def populate_test_data(): + """Set temp data in tmp directory""" + for file_name in tmp_db_file: + old_source_file = os.path.join( + os.path.abspath(os.path.dirname(__file__)), 'sampleData', file_name) + new_destination_file = os.path.join(os.environ['BITMESSAGE_HOME'], file_name) + shutil.copyfile(old_source_file, new_destination_file) + @classmethod def tearDownClass(cls): """Ensures that pybitmessage stopped and removes files""" diff --git a/src/bitmessagekivy/tests/test_create_random_address.py b/src/bitmessagekivy/tests/test_create_random_address.py index c7c04789..d6f85a18 100644 --- a/src/bitmessagekivy/tests/test_create_random_address.py +++ b/src/bitmessagekivy/tests/test_create_random_address.py @@ -1,19 +1,15 @@ -import os -import pdb -import tempfile -from .telenium_process import TeleniumTestProcess, cleanup +from telenium.client import TeleniumHttpException +from .telenium_process import TeleniumTestProcess from .common import ordered from random import choice from string import ascii_lowercase class CreateRandomAddress(TeleniumTestProcess): """This is for testing randrom address creation""" - + @classmethod - def setUpClass(cls): - os.environ["BITMESSAGE_HOME"] = tempfile.gettempdir() - cleanup() - super(TeleniumTestProcess, cls).setUpClass() + def populate_test_data(cls): + pass @ordered def test_login_screen(self): @@ -21,17 +17,14 @@ class CreateRandomAddress(TeleniumTestProcess): # Checking current Screen(Login screen) self.assert_wait_no_except('//ScreenManager[@current]', timeout=15, value='login') # Clicking on Proceed Next Button - self.assertExists('//Screen[0]//MDFillRoundFlatIconButton[@text=\"Proceed Next\"]', timeout=2) - self.cli.wait_click( - '//Screen[0]//MDFillRoundFlatIconButton[@text=\"Proceed Next\"]', timeout=2) - # Checking Current Screen(Random Screen) after Clicking on Proceed Next Button - # self.assertExists("//Random[@name~=\"random\"]", timeout=2) + # self.assertExists('//Screen[0]//MDFillRoundFlatIconButton[@text=\"Proceed Next\"]', timeout=5) + self.cli.wait_click('//Screen[0]//MDFillRoundFlatIconButton[@text=\"Proceed Next\"]', timeout=5) + # Checking Current Screen(Random Screen) after Clicking on "Proceed Next" Button try: - self.assertExists("//ScreenManager[@current=\"random\"]", timeout=2) - except: - self.cli.wait_click( - '//Screen[0]//MDFillRoundFlatIconButton[@text=\"Proceed Next\"]', timeout=5) - self.assertExists("//ScreenManager[@current=\"random\"]", timeout=2) + self.assertExists("//ScreenManager[@current=\"random\"]", timeout=5) + except TeleniumHttpException: + self.cli.wait_click('//Screen[0]//MDFillRoundFlatIconButton[@text=\"Proceed Next\"]', timeout=5) + self.assertExists("//ScreenManager[@current=\"random\"]", timeout=5) @ordered def test_random_screen(self): @@ -102,6 +95,6 @@ class CreateRandomAddress(TeleniumTestProcess): self.cli.wait_click('//MySpinnerOption[0]', timeout=5) # Checking current screen self.assertExists("//Inbox[@name~=\"inbox\"]", timeout=5) - except: + except TeleniumHttpException: self.cli.wait_click('//MySpinnerOption[0]', timeout=5) self.assertExists("//Inbox[@name~=\"inbox\"]", timeout=5) diff --git a/src/bitmessagekivy/tests/test_sent_message.py b/src/bitmessagekivy/tests/test_sent_message.py index 6caec3fc..4ee1c434 100644 --- a/src/bitmessagekivy/tests/test_sent_message.py +++ b/src/bitmessagekivy/tests/test_sent_message.py @@ -1,45 +1,34 @@ -from time import time +from telenium.client import TeleniumHttpException from .telenium_process import TeleniumTestProcess from .common import ordered -data = [ - 'BM-2cWmjntZ47WKEUtocrdvs19y5CivpKoi1h', - 'BM-2cVpswZo8rWLXDVtZEUNcDQvnvHJ6TLRYr' -] +test_address = {'receiver': 'BM-2cWmjntZ47WKEUtocrdvs19y5CivpKoi1h'} class SendMessage(TeleniumTestProcess): """Sent Screen Functionality Testing""" + test_subject = 'Test Subject' + test_body = 'Hello, \n Hope your are doing good.\n\t This is test message body' @ordered def test_send_message_and_validation(self): """ Sending Message From Inbox Screen - opens a pop-up(screen)which send message from sender to reciever + opens a pop-up(screen) which send message from sender to reciever """ - print("=======Test - Sending Message From Inbox Screen with validation Checks=======") - self.cli.sleep(8) - # this is for opening Nav drawer - self.cli.wait_click('//MDActionTopAppBarButton[@icon=\"menu\"]', timeout=3) - # checking state of Nav drawer - self.assertExists("//MDNavigationDrawer[@state~=\"open\"]", timeout=2) - # Click to open Inbox - self.cli.wait_click('//NavigationItem[@text=\"Inbox\"]', timeout=2) - # Checking Inbox Screen - self.assertExists("//Inbox[@name~=\"inbox\"]", timeout=2) - # Due to animation and transition effect, it needed some halt otherwise it fails - self.cli.sleep(1) + # Checking current Screen(Login screen) + self.assert_wait_no_except('//ScreenManager[@current]', timeout=10, value='login') # Click on Composer Icon(Plus icon) self.cli.wait_click('//ComposerButton[0]/MDFloatingActionButton[@icon=\"plus\"]', timeout=2) # Checking Message Composer Screen(Create) - self.assertExists("//Create[@name~=\"create\"]", timeout=4) + self.assertExists("//ScreenManager[@current=\"create\"]", timeout=4) # Checking State of Sender's Address Input Field (Empty) self.assertExists('//DropDownWidget/ScrollView[0]//MDTextField[@text=\"\"]', timeout=3) # Click on Receiver's Address Field to check validation - self.cli.wait_click('//DropDownWidget/ScrollView[0]//MyTextInput[@text=\"\"]', timeout=4) + # self.cli.wait_click('//DropDownWidget/ScrollView[0]//MyTextInput[@text=\"\"]', timeout=4) # Checking State of Receiver's Address Input Field (Empty) self.assertExists('//DropDownWidget/ScrollView[0]//MyTextInput[@text=\"\"]', timeout=2) # Click on Subject Field to check validation - self.cli.wait_click('//DropDownWidget/ScrollView[0]//MyMDTextField[@text=\"\"]', timeout=2) + # self.cli.wait_click('//DropDownWidget/ScrollView[0]//MyMDTextField[@text=\"\"]', timeout=2) # Checking State of Subject Input Field (Empty) self.assertExists('//DropDownWidget/ScrollView[0]//MyMDTextField[@text=\"\"]', timeout=2) # Click on Send Icon to check validation working @@ -49,70 +38,70 @@ class SendMessage(TeleniumTestProcess): # Click on 'Ok' to dismiss the Popup self.cli.wait_click('//MDFlatButton[0]', timeout=2) # Checking Pop up is closed - self.assertExists("//Create[@name~=\"create\"]", timeout=4) + self.assertExists("//ScreenManager[@current=\"create\"]", timeout=2) + # ADD SENDER'S ADDRESS # Checking State of Sender's Address Input Field (Empty) self.assertExists('//DropDownWidget/ScrollView[0]//MDTextField[@text=\"\"]', timeout=2) # Open Sender's Address DropDown - self.cli.wait_click( - '//Create//CustomSpinner[0]/ArrowImg[0]', timeout=3) + self.cli.wait_click('//Create//CustomSpinner[0]/ArrowImg[0]', timeout=3) # Due to animation and transition effect, it needed some halt otherwise it fails - self.cli.sleep(2) + # self.cli.sleep(2) # Checking the Address Dropdown is in open State - self.assertTrue('//Create//CustomSpinner[@is_open]', 'True') + # self.assertFalse('//Create//CustomSpinner[@is_open]', 'False') # Select Sender's Address from Dropdown self.cli.wait_click('//ComposerSpinnerOption[0]', timeout=3) # Checking the Address Dropdown is in open State - self.assertTrue('//Create//CustomSpinner[@is_open]', 'False') + # self.assertTrue('//Create//CustomSpinner[@is_open]', 'False') # Assert to check Sender's address dropdown open or not self.assertNotEqual('//DropDownWidget/ScrollView[0]//MDTextField[0]', '') # ADD SUBJECT - self.cli.setattr('//DropDownWidget/ScrollView[0]//MyMDTextField[0]', 'text', 'heyyyyyy') + self.cli.setattr('//DropDownWidget/ScrollView[0]//MyMDTextField[0]', 'text', self.test_subject) # Checking Subject Field is Entered - self.assertExists('//DropDownWidget/ScrollView[0]//MyMDTextField[@text=\"heyyyyyy\"]', timeout=2) + self.assertNotEqual('//DropDownWidget/ScrollView[0]//MyMDTextField[text]', '') # Checking BODY Field(EMPTY) self.assertExists('//DropDownWidget/ScrollView[0]//ScrollView[0]/MDTextField[@text=\"\"]', timeout=2) # ADD BODY - self.cli.setattr('//DropDownWidget/ScrollView[0]/BoxLayout[0]/ScrollView[0]/MDTextField[0]', - 'text', 'how are you this is message body') + self.cli.setattr('//DropDownWidget/ScrollView[0]/BoxLayout[0]/ScrollView[0]/MDTextField[0]', 'text', self.test_body) # Checking BODY is Entered - self.assertExists( - '//DropDownWidget/ScrollView[0]/BoxLayout[0]/ScrollView[0]/MDTextField[@text=\"how are you this is message body\"]', timeout=2) + self.assertNotEqual( + '//DropDownWidget/ScrollView[0]/BoxLayout[0]/ScrollView[0]/MDTextField[text]', '') # click on send icon self.cli.wait_click('//MDActionTopAppBarButton[@icon=\"send\"]', timeout=2) # Checking validation so Pop up is Opened self.assertExists('//MDDialog[@text=\"Please fill the form completely\"]', timeout=2) - # Pop clicked on ok + # clicked on ok button to close popup self.cli.wait_click('//MDFlatButton[0]', timeout=2) + self.assertExists("//ScreenManager[@current=\"create\"]", timeout=5) # ADD RECEIVER ADDRESS # Checking Receiver Address Field self.assertExists('//DropDownWidget/ScrollView[0]//MyTextInput[@text=\"\"]', timeout=2) # Entering Receiver Address - self.cli.setattr( - '//DropDownWidget/ScrollView[0]//MyTextInput[0]', "text", data[0]) + self.cli.setattr('//DropDownWidget/ScrollView[0]//MyTextInput[0]', "text", test_address['receiver']) # Checking Receiver Address filled or not - self.assertNotEqual('//DropDownWidget/ScrollView[0]//MyTextInput[0]', '') + self.assertNotEqual('//DropDownWidget/ScrollView[0]//MyTextInput[text]', '') # Clicking on send icon - self.cli.wait_click('//MDActionTopAppBarButton[@icon=\"send\"]', timeout=4) + self.cli.wait_click('//MDActionTopAppBarButton[@icon=\"send\"]', timeout=5) # Checking screen(Inbox) after sending message - self.assertExists("//Inbox[@name~=\"inbox\"]", timeout=4) + try: + self.assertExists("//ScreenManager[@current=\"inbox\"]", timeout=10) + except TeleniumHttpException: + self.cli.wait_click('//MDActionTopAppBarButton[@icon=\"send\"]', timeout=4) + self.assertExists("//ScreenManager[@current=\"inbox\"]", timeout=10) @ordered def test_sent_box(self): """ Checking Message in Sent Screen after sending a Message. """ - print("=======Test - Checking Message in Sent Screen after sending a Message=======") # this is for opening Nav drawer - self.cli.wait_click('//MDActionTopAppBarButton[@icon=\"menu\"]', timeout=3) + self.cli.wait_click('//MDActionTopAppBarButton[@icon=\"menu\"]', timeout=5) # checking state of Nav drawer - self.assertExists("//MDNavigationDrawer[@state~=\"open\"]", timeout=2) + self.assertExists("//MDNavigationDrawer[@state~=\"open\"]", timeout=5) # Clicking on Sent Tab - self.cli.wait_click('//NavigationItem[@text=\"Sent\"]', timeout=3) + self.cli.wait_click('//NavigationItem[@text=\"Sent\"]', timeout=5) # Checking current screen; Sent - self.assertExists("//Sent[@name~=\"sent\"]", timeout=3) - # It takes time to reload sent messages so used sleep method - self.cli.sleep(1) + self.assertExists("//ScreenManager[@current=\"sent\"]", timeout=5) # Checking number of Sent messages total_sent_msgs = len(self.cli.select("//SwipeToDeleteItem")) - self.assertEqual(total_sent_msgs, 2) + self.assertEqual(total_sent_msgs, 3)