From 859bd8d6d87a0c3c63652e3acb471451459dbe6e Mon Sep 17 00:00:00 2001 From: lakshyacis Date: Sat, 1 Feb 2020 18:16:52 +0530 Subject: [PATCH] Graphical Qt Testing Initial --- src/bitmessageqt/__init__.py | 5 ++ src/bitmessageqt/address_dialogs.py | 8 +++ src/gtesting.py | 7 +++ src/qttest.py | 82 +++++++++++++++++++++++++++++ src/state.py | 2 + 5 files changed, 104 insertions(+) create mode 100644 src/gtesting.py create mode 100644 src/qttest.py diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 440d36b2..1b9f0290 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -4160,4 +4160,9 @@ def run(): if not BMConfigParser().getboolean('bitmessagesettings', 'startintray'): myapp.show() + if state.qttesting: + import qttest + qttest.Testing().label_generation(myapp) + qttest.Testing().senf_functionality(myapp) + sys.exit(app.exec_()) diff --git a/src/bitmessageqt/address_dialogs.py b/src/bitmessageqt/address_dialogs.py index 60c10369..e88ba023 100644 --- a/src/bitmessageqt/address_dialogs.py +++ b/src/bitmessageqt/address_dialogs.py @@ -128,6 +128,14 @@ class NewAddressDialog(QtGui.QDialog, RetranslateMixin): self.groupBoxDeterministic.setHidden(True) QtGui.QWidget.resize(self, QtGui.QWidget.sizeHint(self)) self.show() + import state + if state.qttesting: + import qttest + from PyQt4.QtCore import Qt + from PyQt4.QtTest import QTest + self.newaddresslabel.setText(qttest.Testing().address_autofill()) + qttest.Testing().sleeper() + self.accept() def accept(self): """accept callback""" diff --git a/src/gtesting.py b/src/gtesting.py new file mode 100644 index 00000000..4523df74 --- /dev/null +++ b/src/gtesting.py @@ -0,0 +1,7 @@ +from bitmessagemain import main +import state + +if __name__ == '__main__': + state.qttesting = True + print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~QT GRAPHICAL TESTING~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") + main() \ No newline at end of file diff --git a/src/qttest.py b/src/qttest.py new file mode 100644 index 00000000..81303eb8 --- /dev/null +++ b/src/qttest.py @@ -0,0 +1,82 @@ +from PyQt4.QtGui import QApplication +from PyQt4.QtCore import Qt +from PyQt4 import QtGui +from PyQt4.QtTest import QTest +from PyQt4 import QtTest +from random import choice +from string import ascii_lowercase, ascii_uppercase +from helper_sql import sqlQuery, sqlExecute +from bmconfigparser import BMConfigParser +import random + + +class Testing: + def __init__(self): + self.inbox_length = sqlQuery("Select msgid from inbox") + + def label_generation(self, myapp): + self.sleeper() + myapp.ui.pushButtonNewAddress.setStyleSheet('QPushButton {background-color: red; color: white;}') + QtTest.QTest.qWait(70) + myapp.ui.pushButtonNewAddress.setStyleSheet("") + QTest.mouseClick(myapp.ui.pushButtonNewAddress, Qt.LeftButton) + self.sleeper() + + def address_autofill(self): + self.sleeper() + return choice(ascii_uppercase) + (''.join(choice(ascii_lowercase) for i in range(14))) + + def senf_functionality(self, myapp): + myapp.ui.tabWidget.setCurrentWidget(myapp.ui.send) + self.sleeper() + if BMConfigParser().addresses(): + addresses = BMConfigParser().addresses() + len_addresses = len(addresses) + a = "" + rand_var = random.randrange(1, len_addresses + 1) + rand_address = random.choice(addresses) + myapp.ui.comboBoxSendFrom.setCurrentIndex(rand_var) + self.sleeper() + for x in range(len(rand_address)): + a = a + rand_address[x] + myapp.ui.lineEditTo.setText(a) + QtTest.QTest.qWait(1) + self.sleeper() + a = "" + for x in range(40): + a = a + choice(ascii_lowercase) + myapp.ui.lineEditSubject.setText(a) + QtTest.QTest.qWait(1) + self.sleeper() + a = "" + for x in range(200): + a = a + choice(ascii_lowercase) + myapp.ui.textEditMessage.setText(a) + QtTest.QTest.qWait(1) + self.sleeper() + QTest.mouseClick(myapp.ui.pushButtonSend, Qt.LeftButton) + self.sleeper() + myapp.ui.tabWidget.setCurrentWidget(myapp.ui.inbox) + QtTest.QTest.qWait(4000) + new_msg_index = len(self.inbox_length) + 1 + inbox_length = sqlQuery("Select msgid from inbox") + if len(inbox_length) == new_msg_index: + msg = QtGui.QMessageBox() + msg.setText("SUCESS!!~~") + msg.setInformativeText("MESSAGE RECEIVED!") + msg.setWindowTitle("MessageBox demo") + msg.setDetailedText("The details are as follows:") + msg.setStandardButtons(QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel) + msg.show() + print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~GOT MESSAGE!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") + else: + print("TEST FAILED!!") + print("DONE!!") + + def subscriptions(self, myapp): + self.sleeper() + myapp.ui.tabWidget.setCurrentWidget(myapp.ui.subscriptions) + QTest.mouseClick(myapp.ui.pushButtonAddSubscription, Qt.LeftButton) + + def sleeper(self): + QtTest.QTest.qWait(1200) diff --git a/src/state.py b/src/state.py index 58e1106a..7869aa7f 100644 --- a/src/state.py +++ b/src/state.py @@ -54,4 +54,6 @@ testmode = False kivy = False +qttesting = False + association = ''