forked from Bitcoin-ABC/bitcoin-abc
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'issue_438' into 'master'
[test] Add test harness for UI tests Closes Bitcoin-ABC#438 See merge request bitcoin-cash-node/bitcoin-cash-node!1623
- Loading branch information
Showing
6 changed files
with
222 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
from PyQt5 import QtCore, QtWidgets | ||
from PyQt5.QtWidgets import QMainWindow, QTextEdit, QGridLayout, QWidget, QHBoxLayout | ||
from PyQt5.QtWidgets import QPushButton | ||
from PyQt5.QtCore import QSize, Qt | ||
|
||
from .util import wait_until | ||
|
||
class MainWindow(QMainWindow): | ||
def __init__(self, app, steps): | ||
self.app = app | ||
self.steps = steps | ||
self.currentStep = 0 | ||
self.maxReachedStep = 0 | ||
|
||
QMainWindow.__init__(self) | ||
|
||
screenrect = app.primaryScreen().geometry() | ||
self.move(screenrect.left(), screenrect.top()) | ||
self.setMinimumSize(QSize(300, 260)) | ||
self.resize(QSize(300, 260)) | ||
self.setWindowTitle("Bitcoin Cash Node - UI Test Plan") | ||
self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) | ||
|
||
|
||
self.horizontalGroupBox = QWidget(self) | ||
self.horizontalGroupBox.resize(self.size()) | ||
|
||
layout = QGridLayout() | ||
layout.setRowStretch(1, 1) | ||
|
||
self.stepDescription = QTextEdit() | ||
self.stepDescription.setText("Step 1/6") | ||
self.stepDescription.setReadOnly(True) | ||
# self.stepDescription.setStyleSheet("background: red") | ||
layout.addWidget(self.stepDescription, 0,0,0,3, Qt.AlignTop) | ||
|
||
|
||
buttons = QWidget() | ||
hLayout = QHBoxLayout() | ||
|
||
self.backButton = QPushButton('Back', self) | ||
self.backButton.setEnabled(False) | ||
self.backButton.clicked.connect(self.back) | ||
hLayout.addWidget(self.backButton) | ||
|
||
self.advanceButton = QPushButton('Advance', self) | ||
self.advanceButton.clicked.connect(self.advance) | ||
hLayout.addWidget(self.advanceButton) | ||
|
||
buttons.setLayout(hLayout) | ||
layout.addWidget(buttons,1,0,1,3, Qt.AlignBottom) | ||
|
||
self.horizontalGroupBox.setLayout(layout) | ||
|
||
self.setCentralWidget(self.horizontalGroupBox) | ||
|
||
self.updateUI() | ||
|
||
def updateUI(self): | ||
step = self.steps[self.currentStep] | ||
|
||
self.stepDescription.setText(f"Step {self.currentStep+1}/{len(self.steps)}\n{step['description']}") | ||
self.backButton.setEnabled(self.currentStep > 0) | ||
self.advanceButton.setText("Finish" if self.currentStep+1 == len(self.steps) else "Advance") | ||
|
||
def advance(self): | ||
self.currentStep += 1 | ||
if (self.currentStep > self.maxReachedStep): | ||
self.maxReachedStep = self.currentStep | ||
|
||
if (self.currentStep >= len(self.steps)): | ||
self.close() | ||
else: | ||
self.updateUI() | ||
|
||
def back(self): | ||
if (self.currentStep > 0): | ||
self.currentStep -= 1 | ||
self.updateUI() | ||
|
||
def waitUntilMaxReachedStep(self, step): | ||
def process(): | ||
self.app.processEvents() | ||
return self.maxReachedStep >= step | ||
wait_until(lambda: process(), timeout=1e10) | ||
|
||
def RunTestPlan(steps, framework): | ||
app = QtWidgets.QApplication(['']) | ||
mainWindow = MainWindow(app, steps) | ||
framework.testPlan = mainWindow | ||
mainWindow.show() | ||
framework.main() | ||
app.exec() | ||
return mainWindow | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) 2021-2022 The Bitcoin Cash Node developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
""" Example UI test plan boilerplate code """ | ||
|
||
from test_framework.test_framework import BitcoinTestFramework | ||
from test_framework.ui import RunTestPlan | ||
|
||
class UITestFramework(BitcoinTestFramework): | ||
def set_test_params(self): | ||
self.num_nodes = 1 | ||
self.extra_args = [["-splash=0", "-ui"]] | ||
|
||
def run_test(self): | ||
# self.meaninfulWork() | ||
self.testPlan.waitUntilMaxReachedStep(1) | ||
|
||
# self.moreMeaningfulWork() | ||
self.testPlan.waitUntilMaxReachedStep(2) | ||
|
||
if __name__ == '__main__': | ||
steps = [{ | ||
'description': "Be a good guy" | ||
}, { | ||
'description': "Have a nice day" | ||
}] | ||
|
||
framework = UITestFramework() | ||
RunTestPlan(steps, framework) |