From 2dca95a146b12b01b0a2d4f6652ff45360f159df Mon Sep 17 00:00:00 2001 From: NissimHadar Date: Thu, 26 Jul 2018 14:12:44 -0700 Subject: [PATCH] Working on TestRail, adding sections --- tools/auto-tester/src/TestRailInterface.cpp | 158 +++++++++++------- tools/auto-tester/src/TestRailInterface.h | 12 +- tools/auto-tester/src/ui/TestRailSelector.ui | 147 ---------------- .../src/ui/TestRailSelectorWindow.cpp | 52 ++++++ .../src/ui/TestRailSelectorWindow.h | 38 +++++ .../src/ui/TestRailSelectorWindow.ui | 151 +++++++++++++++++ 6 files changed, 350 insertions(+), 208 deletions(-) delete mode 100644 tools/auto-tester/src/ui/TestRailSelector.ui create mode 100644 tools/auto-tester/src/ui/TestRailSelectorWindow.cpp create mode 100644 tools/auto-tester/src/ui/TestRailSelectorWindow.h create mode 100644 tools/auto-tester/src/ui/TestRailSelectorWindow.ui diff --git a/tools/auto-tester/src/TestRailInterface.cpp b/tools/auto-tester/src/TestRailInterface.cpp index 5f597734f6..7077b02aac 100644 --- a/tools/auto-tester/src/TestRailInterface.cpp +++ b/tools/auto-tester/src/TestRailInterface.cpp @@ -11,11 +11,20 @@ #include "TestRailInterface.h" #include "Test.h" +#include "ui/TestRailSelectorWindow.h" + #include #include #include #include +TestRailInterface::TestRailInterface() { + _testRailSelectorWindow.setModal(true); + + _testRailSelectorWindow.setURL("https://highfidelity.testrail.net/"); + _testRailSelectorWindow.setUser("@highfidelity.io"); +} + void TestRailInterface::createTestRailDotPyScript(const QString& outputDirectory) { // Create the testrail.py script // This is the file linked to from http://docs.gurock.com/testrail-api2/bindings-python @@ -124,6 +133,34 @@ void TestRailInterface::createTestRailDotPyScript(const QString& outputDirectory } void TestRailInterface::requestDataFromUser() { + _testRailSelectorWindow.exec(); + + if (_testRailSelectorWindow.getUserCancelled()) { + return; + } + + _url = _testRailSelectorWindow.getURL(); + _user = _testRailSelectorWindow.getUser(); + _password = _testRailSelectorWindow.getPassword(); +} + +void TestRailInterface::createAddSectionsPythonScript(const QString& outputDirectory) { + QFile file(outputDirectory + "/addSections.py"); + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { + QMessageBox::critical(0, "Internal error: " + QString(__FILE__) + ":" + QString::number(__LINE__), + "Could not create \'addSections.py\'"); + exit(-1); + } + + QTextStream stream(&file); + + // Code to access TestRail + stream << "from testrail import *\n"; + stream << "client = APIClient(\'" << _url.toStdString().c_str() << "\')\n"; + stream << "client.user = \'" << _user << "\'\n"; + stream << "client.password = \'" << _password << "\'\n\n"; + + file.close(); } void TestRailInterface::createTestSuitePython(const QString& testDirectory, @@ -133,6 +170,7 @@ void TestRailInterface::createTestSuitePython(const QString& testDirectory, createTestRailDotPyScript(outputDirectory); requestDataFromUser(); + createAddSectionsPythonScript(outputDirectory); } void TestRailInterface::createTestSuiteXML(const QString& testDirectory, @@ -140,20 +178,20 @@ void TestRailInterface::createTestSuitePython(const QString& testDirectory, const QString& user, const QString& branch) { - QDomProcessingInstruction instruction = document.createProcessingInstruction("xml", "version='1.0' encoding='UTF-8'"); - document.appendChild(instruction); + QDomProcessingInstruction instruction = _document.createProcessingInstruction("xml", "version='1.0' encoding='UTF-8'"); + _document.appendChild(instruction); // We create a single section, within sections - QDomElement root = document.createElement("sections"); - document.appendChild(root); + QDomElement root = _document.createElement("sections"); + _document.appendChild(root); - QDomElement topLevelSection = document.createElement("section"); + QDomElement topLevelSection = _document.createElement("section"); - QDomElement suiteName = document.createElement("name"); - suiteName.appendChild(document.createTextNode("Test Suite - " + QDateTime::currentDateTime().toString())); + QDomElement suiteName = _document.createElement("name"); + suiteName.appendChild(_document.createTextNode("Test Suite - " + QDateTime::currentDateTime().toString())); topLevelSection.appendChild(suiteName); - QDomElement secondLevelSections = document.createElement("sections"); + QDomElement secondLevelSections = _document.createElement("sections"); topLevelSection.appendChild(processDirectory(testDirectory, user, branch, secondLevelSections)); topLevelSection.appendChild(secondLevelSections); @@ -168,7 +206,7 @@ void TestRailInterface::createTestSuitePython(const QString& testDirectory, } QTextStream stream(&file); - stream << document.toString(); + stream << _document.toString(); file.close(); @@ -195,22 +233,22 @@ QDomElement TestRailInterface::processDirectory(const QString& directory, const // Create a section and process it - QDomElement sectionElement = document.createElement("section"); + QDomElement sectionElement = _document.createElement("section"); - QDomElement sectionElementName = document.createElement("name"); - sectionElementName.appendChild(document.createTextNode(objectName)); + QDomElement sectionElementName = _document.createElement("name"); + sectionElementName.appendChild(_document.createTextNode(objectName)); sectionElement.appendChild(sectionElementName); - QDomElement testsElement = document.createElement("sections"); + QDomElement testsElement = _document.createElement("sections"); sectionElement.appendChild(processDirectory(nextDirectory, user, branch, testsElement)); result.appendChild(sectionElement); } else if (objectName == "test.js" || objectName == "testStory.js") { - QDomElement sectionElement = document.createElement("section"); - QDomElement sectionElementName = document.createElement("name"); - sectionElementName.appendChild(document.createTextNode("all")); + QDomElement sectionElement = _document.createElement("section"); + QDomElement sectionElementName = _document.createElement("name"); + sectionElementName.appendChild(_document.createTextNode("all")); sectionElement.appendChild(sectionElementName); - sectionElement.appendChild(processTest(nextDirectory, objectName, user, branch, document.createElement("cases"))); + sectionElement.appendChild(processTest(nextDirectory, objectName, user, branch, _document.createElement("cases"))); result.appendChild(sectionElement); } } @@ -221,9 +259,9 @@ QDomElement TestRailInterface::processDirectory(const QString& directory, const QDomElement TestRailInterface::processTest(const QString& fullDirectory, const QString& test, const QString& user, const QString& branch, const QDomElement& element) { QDomElement result = element; - QDomElement caseElement = document.createElement("case"); + QDomElement caseElement = _document.createElement("case"); - caseElement.appendChild(document.createElement("id")); + caseElement.appendChild(_document.createElement("id")); // The name of the test is derived from the full path. // The first term is the first word after "tests" @@ -244,83 +282,83 @@ QDomElement TestRailInterface::processTest(const QString& fullDirectory, const Q title += " / " + words[i]; } - QDomElement titleElement = document.createElement("title"); - titleElement.appendChild(document.createTextNode(title)); + QDomElement titleElement = _document.createElement("title"); + titleElement.appendChild(_document.createTextNode(title)); caseElement.appendChild(titleElement); - QDomElement templateElement = document.createElement("template"); - templateElement.appendChild(document.createTextNode("Test Case (Steps)")); + QDomElement templateElement = _document.createElement("template"); + templateElement.appendChild(_document.createTextNode("Test Case (Steps)")); caseElement.appendChild(templateElement); - QDomElement typeElement = document.createElement("type"); - typeElement.appendChild(document.createTextNode("3 - Regression")); + QDomElement typeElement = _document.createElement("type"); + typeElement.appendChild(_document.createTextNode("3 - Regression")); caseElement.appendChild(typeElement); - QDomElement priorityElement = document.createElement("priority"); - priorityElement.appendChild(document.createTextNode("Medium")); + QDomElement priorityElement = _document.createElement("priority"); + priorityElement.appendChild(_document.createTextNode("Medium")); caseElement.appendChild(priorityElement); - QDomElement estimateElementName = document.createElement("estimate"); - estimateElementName.appendChild(document.createTextNode("60")); + QDomElement estimateElementName = _document.createElement("estimate"); + estimateElementName.appendChild(_document.createTextNode("60")); caseElement.appendChild(estimateElementName); - caseElement.appendChild(document.createElement("references")); + caseElement.appendChild(_document.createElement("references")); - QDomElement customElement = document.createElement("custom"); + QDomElement customElement = _document.createElement("custom"); - QDomElement tester_countElement = document.createElement("tester_count"); - tester_countElement.appendChild(document.createTextNode("1")); + QDomElement tester_countElement = _document.createElement("tester_count"); + tester_countElement.appendChild(_document.createTextNode("1")); customElement.appendChild(tester_countElement); - QDomElement domain_bot_loadElement = document.createElement("domain_bot_load"); - QDomElement domain_bot_loadElementId = document.createElement("id"); - domain_bot_loadElementId.appendChild(document.createTextNode("1")); + QDomElement domain_bot_loadElement = _document.createElement("domain_bot_load"); + QDomElement domain_bot_loadElementId = _document.createElement("id"); + domain_bot_loadElementId.appendChild(_document.createTextNode("1")); domain_bot_loadElement.appendChild(domain_bot_loadElementId); - QDomElement domain_bot_loadElementValue = document.createElement("value"); - domain_bot_loadElementValue.appendChild(document.createTextNode(" Without Bots (hifiqa-rc / hifi-qa-stable / hifiqa-master)")); + QDomElement domain_bot_loadElementValue = _document.createElement("value"); + domain_bot_loadElementValue.appendChild(_document.createTextNode(" Without Bots (hifiqa-rc / hifi-qa-stable / hifiqa-master)")); domain_bot_loadElement.appendChild(domain_bot_loadElementValue); customElement.appendChild(domain_bot_loadElement); - QDomElement automation_typeElement = document.createElement("automation_type"); - QDomElement automation_typeElementId = document.createElement("id"); - automation_typeElementId.appendChild(document.createTextNode("0")); + QDomElement automation_typeElement = _document.createElement("automation_type"); + QDomElement automation_typeElementId = _document.createElement("id"); + automation_typeElementId.appendChild(_document.createTextNode("0")); automation_typeElement.appendChild(automation_typeElementId); - QDomElement automation_typeElementValue = document.createElement("value"); - automation_typeElementValue.appendChild(document.createTextNode("None")); + QDomElement automation_typeElementValue = _document.createElement("value"); + automation_typeElementValue.appendChild(_document.createTextNode("None")); automation_typeElement.appendChild(automation_typeElementValue); customElement.appendChild(automation_typeElement); - QDomElement added_to_releaseElement = document.createElement("added_to_release"); - QDomElement added_to_releaseElementId = document.createElement("id"); - added_to_releaseElementId.appendChild(document.createTextNode("4")); + QDomElement added_to_releaseElement = _document.createElement("added_to_release"); + QDomElement added_to_releaseElementId = _document.createElement("id"); + added_to_releaseElementId.appendChild(_document.createTextNode("4")); added_to_releaseElement.appendChild(added_to_releaseElementId); - QDomElement added_to_releaseElementValue = document.createElement("value"); - added_to_releaseElementValue.appendChild(document.createTextNode(branch)); + QDomElement added_to_releaseElementValue = _document.createElement("value"); + added_to_releaseElementValue.appendChild(_document.createTextNode(branch)); added_to_releaseElement.appendChild(added_to_releaseElementValue); customElement.appendChild(added_to_releaseElement); - QDomElement precondsElement = document.createElement("preconds"); - precondsElement.appendChild(document.createTextNode("Tester is in an empty region of a domain in which they have edit rights\n\n*Note: Press 'n' to advance test script")); + QDomElement precondsElement = _document.createElement("preconds"); + precondsElement.appendChild(_document.createTextNode("Tester is in an empty region of a domain in which they have edit rights\n\n*Note: Press 'n' to advance test script")); customElement.appendChild(precondsElement); QString testMDName = QString("https://github.com/") + user + "/hifi_tests/blob/" + branch + "/tests/content/entity/light/point/create/test.md"; - QDomElement steps_seperatedElement = document.createElement("steps_separated"); - QDomElement stepElement = document.createElement("step"); - QDomElement stepIndexElement = document.createElement("index"); - stepIndexElement.appendChild(document.createTextNode("1")); + QDomElement steps_seperatedElement = _document.createElement("steps_separated"); + QDomElement stepElement = _document.createElement("step"); + QDomElement stepIndexElement = _document.createElement("index"); + stepIndexElement.appendChild(_document.createTextNode("1")); stepElement.appendChild(stepIndexElement); - QDomElement stepContentElement = document.createElement("content"); - stepContentElement.appendChild(document.createTextNode(QString("Execute instructions in [THIS TEST](") + testMDName + ")")); + QDomElement stepContentElement = _document.createElement("content"); + stepContentElement.appendChild(_document.createTextNode(QString("Execute instructions in [THIS TEST](") + testMDName + ")")); stepElement.appendChild(stepContentElement); - QDomElement stepExpectedElement = document.createElement("expected"); - stepExpectedElement.appendChild(document.createTextNode("Refer to the expected result in the linked description.")); + QDomElement stepExpectedElement = _document.createElement("expected"); + stepExpectedElement.appendChild(_document.createTextNode("Refer to the expected result in the linked description.")); stepElement.appendChild(stepExpectedElement); steps_seperatedElement.appendChild(stepElement); customElement.appendChild(steps_seperatedElement); - QDomElement notesElement = document.createElement("notes"); - notesElement.appendChild(document.createTextNode(testMDName)); + QDomElement notesElement = _document.createElement("notes"); + notesElement.appendChild(_document.createTextNode(testMDName)); customElement.appendChild(notesElement); caseElement.appendChild(customElement); diff --git a/tools/auto-tester/src/TestRailInterface.h b/tools/auto-tester/src/TestRailInterface.h index eb562fa7c9..6c98ddf430 100644 --- a/tools/auto-tester/src/TestRailInterface.h +++ b/tools/auto-tester/src/TestRailInterface.h @@ -11,12 +11,15 @@ #ifndef hifi_test_testrail_interface_h #define hifi_test_testrail_interface_h +#include "ui/TestRailSelectorWindow.h" #include #include #include class TestRailInterface { public: + TestRailInterface(); + void createTestSuiteXML(const QString& testDirectory, const QString& outputDirectory, const QString& user, @@ -36,9 +39,16 @@ public: void createTestRailDotPyScript(const QString& outputDirectory); void requestDataFromUser(); + void createAddSectionsPythonScript(const QString& outputDirectory); private: - QDomDocument document; + QDomDocument _document; + + TestRailSelectorWindow _testRailSelectorWindow; + + QString _url; + QString _user; + QString _password; }; #endif \ No newline at end of file diff --git a/tools/auto-tester/src/ui/TestRailSelector.ui b/tools/auto-tester/src/ui/TestRailSelector.ui deleted file mode 100644 index 695b374a50..0000000000 --- a/tools/auto-tester/src/ui/TestRailSelector.ui +++ /dev/null @@ -1,147 +0,0 @@ - - - AutoTesterClass - - - - 0 - 0 - 314 - 259 - - - - AutoTester - - - - - - 20 - 130 - 101 - 40 - - - - OK - - - - - - 20 - 65 - 81 - 16 - - - - - 10 - - - - TestRail Branch - - - - - - 20 - 25 - 81 - 16 - - - - - 10 - - - - TestRail User - - - - - - 110 - 22 - 140 - 24 - - - - - - - 110 - 60 - 140 - 24 - - - - - - - 170 - 130 - 101 - 40 - - - - Cancel - - - - - - - 0 - 0 - 314 - 21 - - - - - File - - - - - - Help - - - - - - - - - TopToolBarArea - - - false - - - - - - Close - - - - - About - - - - - - - diff --git a/tools/auto-tester/src/ui/TestRailSelectorWindow.cpp b/tools/auto-tester/src/ui/TestRailSelectorWindow.cpp new file mode 100644 index 0000000000..ff3cf05ed4 --- /dev/null +++ b/tools/auto-tester/src/ui/TestRailSelectorWindow.cpp @@ -0,0 +1,52 @@ +// +// TestRailSelectorWindow.cpp +// +// Created by Nissim Hadar on 26 Jul 2017. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +#include "TestRailSelectorWindow.h" + +#include + +#include + +TestRailSelectorWindow::TestRailSelectorWindow(QWidget *parent) { + setupUi(this); +} + +void TestRailSelectorWindow::on_OKButton_clicked() { + userCancelled = false; + close(); +} + +void TestRailSelectorWindow::on_cancelButton_clicked() { + userCancelled = true; + close(); +} + +bool TestRailSelectorWindow::getUserCancelled() { + return userCancelled; +} + +void TestRailSelectorWindow::setURL(const QString& user) { + URLTextEdit->setText(user); +} + +QString TestRailSelectorWindow::getURL() { + return URLTextEdit->toPlainText(); +} + +void TestRailSelectorWindow::setUser(const QString& user) { + UserTextEdit->setText(user); +} + +QString TestRailSelectorWindow::getUser() { + return UserTextEdit->toPlainText(); +} + +QString TestRailSelectorWindow::getPassword() { + return passwordLineEdit->text(); +} \ No newline at end of file diff --git a/tools/auto-tester/src/ui/TestRailSelectorWindow.h b/tools/auto-tester/src/ui/TestRailSelectorWindow.h new file mode 100644 index 0000000000..587e3401b8 --- /dev/null +++ b/tools/auto-tester/src/ui/TestRailSelectorWindow.h @@ -0,0 +1,38 @@ +// +// TestRailSelectorWindow.h +// +// Created by Nissim Hadar on 26 Jul 2017. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +#ifndef hifi_TestRailSelectorWindow_h +#define hifi_TestRailSelectorWindow_h + +#include "ui_TestRailSelectorWindow.h" + +class TestRailSelectorWindow : public QDialog, public Ui::TestRailSelectorWindow { + Q_OBJECT + +public: + TestRailSelectorWindow(QWidget* parent = Q_NULLPTR); + + bool getUserCancelled(); + + void setURL(const QString& user); + QString getURL(); + + void setUser(const QString& user); + QString getUser(); + + QString getPassword(); + + bool userCancelled{ false }; + +private slots: + void on_OKButton_clicked(); + void on_cancelButton_clicked(); +}; + +#endif \ No newline at end of file diff --git a/tools/auto-tester/src/ui/TestRailSelectorWindow.ui b/tools/auto-tester/src/ui/TestRailSelectorWindow.ui new file mode 100644 index 0000000000..e05e2b6370 --- /dev/null +++ b/tools/auto-tester/src/ui/TestRailSelectorWindow.ui @@ -0,0 +1,151 @@ + + + TestRailSelectorWindow + + + + 0 + 0 + 489 + 312 + + + + MismatchWindow + + + + + 30 + 850 + 500 + 28 + + + + + 12 + + + + similarity + + + + + + 70 + 115 + 121 + 20 + + + + + 10 + + + + TestRail Password + + + + + + 70 + 25 + 121 + 20 + + + + + 10 + + + + TestRail URL + + + + + + 200 + 25 + 231 + 24 + + + + + + + 120 + 200 + 93 + 28 + + + + OK + + + + + + 280 + 200 + 93 + 28 + + + + Cancel + + + + + + 200 + 115 + 231 + 24 + + + + QLineEdit::Password + + + + + + 200 + 70 + 231 + 24 + + + + + + + 70 + 70 + 121 + 20 + + + + + 10 + + + + TestRail User + + + + + + +