Can detect device.

This commit is contained in:
NissimHadar 2019-01-23 14:05:32 -08:00
parent d4fac770ff
commit 0c6d3be037
8 changed files with 134 additions and 32 deletions

View file

@ -93,7 +93,7 @@ void Nitpick::setup() {
if (_testRunnerMobile) {
delete _testRunnerMobile;
}
_testRunnerMobile = new TestRunnerMobile(_ui.workingFolderRunOnMobileLabel, _ui.readDeviceButton);
_testRunnerMobile = new TestRunnerMobile(_ui.workingFolderRunOnMobileLabel, _ui.connectDeviceButton, _ui.pullFolderButton, _ui.detectedDeviceLabel);
}
void Nitpick::startTestsEvaluation(const bool isRunningFromCommandLine,
@ -327,6 +327,10 @@ void Nitpick::on_setWorkingFolderRunOnMobileButton_clicked() {
_testRunnerMobile->setWorkingFolderAndEnableControls();
}
void Nitpick::on_readDeviceButton_clicked() {
_testRunnerMobile->readDevice();
void Nitpick::on_connectDeviceButton_clicked() {
_testRunnerMobile->connectDevice();
}
void Nitpick::on_pullFolderButton_clicked() {
_testRunnerMobile->pullFolder();
}

View file

@ -96,7 +96,8 @@ private slots:
void content();
void on_setWorkingFolderRunOnMobileButton_clicked();
void on_readDeviceButton_clicked();
void on_connectDeviceButton_clicked();
void on_pullFolderButton_clicked();
private:
Ui::NitpickClass _ui;

View file

@ -31,7 +31,7 @@ PythonInterface::PythonInterface() {
#elif defined Q_OS_MAC
_pythonCommand = "/usr/local/bin/python3";
if (!QFile::exists(_pythonCommand)) {
QMessageBox::critical(0, "PYTHON_PATH not defined",
QMessageBox::critical(0, "python not found",
"python3 not found at " + _pythonCommand);
exit(-1);
}

View file

@ -30,3 +30,14 @@ void TestRunner::setWorkingFolder(QLabel* workingFolderLabel) {
workingFolderLabel->setText(QDir::toNativeSeparators(_workingFolder));
}
void Worker::setCommandLine(const QString& commandLine) {
_commandLine = commandLine;
}
int Worker::runCommand() {
int result = system(_commandLine.toStdString().c_str());
emit commandComplete();
return result;
}

View file

@ -803,13 +803,3 @@ void TestRunnerDesktop::parseBuildInformation() {
exit(-1);
}
}
void Worker::setCommandLine(const QString& commandLine) {
_commandLine = commandLine;
}
int Worker::runCommand() {
int result = system(_commandLine.toStdString().c_str());
emit commandComplete();
return result;
}

View file

@ -16,9 +16,13 @@
#include "Nitpick.h"
extern Nitpick* nitpick;
TestRunnerMobile::TestRunnerMobile(QLabel* workingFolderLabel, QPushButton *readDeviceButton, QObject* parent) : QObject(parent) {
TestRunnerMobile::TestRunnerMobile(QLabel* workingFolderLabel, QPushButton *conectDeviceButton, QPushButton *pullFolderButton, QLabel* detectedDeviceLabel, QObject* parent)
: QObject(parent)
{
_workingFolderLabel = workingFolderLabel;
_readDeviceButton = readDeviceButton;
_connectDeviceButton = conectDeviceButton;
_pullFolderButton = pullFolderButton;
_detectedDeviceLabel = detectedDeviceLabel;
}
TestRunnerMobile::~TestRunnerMobile() {
@ -27,9 +31,63 @@ TestRunnerMobile::~TestRunnerMobile() {
void TestRunnerMobile::setWorkingFolderAndEnableControls() {
setWorkingFolder(_workingFolderLabel);
_readDeviceButton->setEnabled(true);
_connectDeviceButton->setEnabled(true);
// Find ADB (Android Debugging Bridge) before continuing
#ifdef Q_OS_WIN
if (QProcessEnvironment::systemEnvironment().contains("ADB_PATH")) {
QString adbExePath = QProcessEnvironment::systemEnvironment().value("ADB_PATH") + "/platform-tools";
if (!QFile::exists(adbExePath + "/" + _adbExe)) {
QMessageBox::critical(0, _adbExe, QString("Python executable not found in ") + adbExePath);
exit(-1);
}
_adbCommand = adbExePath + "/" + _adbExe;
} else {
QMessageBox::critical(0, "PYTHON_PATH not defined",
"Please set PYTHON_PATH to directory containing the Python executable");
exit(-1);
}
#elif defined Q_OS_MAC
_adbCommand = "/usr/local/bin/adb";
if (!QFile::exists(_adbCommand)) {
QMessageBox::critical(0, "adb not found",
"python3 not found at " + _adbCommand);
exit(-1);
}
#endif
}
void TestRunnerMobile::readDevice() {
void TestRunnerMobile::connectDevice() {
QString devicesFullFilename{ _workingFolder + "/devices.txt" };
QString command = _adbCommand + " devices > " + devicesFullFilename;
int result = system(command.toStdString().c_str());
if (!QFile::exists(devicesFullFilename)) {
QMessageBox::critical(0, "Internal error", "devicesFullFilename not found");
exit (-1);
}
// Device should be in second line
QFile devicesFile(devicesFullFilename);
devicesFile.open(QIODevice::ReadOnly | QIODevice::Text);
QString line1 = devicesFile.readLine();
QString line2 = devicesFile.readLine();
const QString DEVICE{ "device" };
if (line2.contains(DEVICE)) {
// Make sure only 1 device
QString line3 = devicesFile.readLine();
if (line3.contains(DEVICE)) {
QMessageBox::critical(0, "Too many devices detected", "Tests will run only if a single device is attached");
} else {
_pullFolderButton->setEnabled(true);
_detectedDeviceLabel->setText(line2.remove(DEVICE));
}
}
}
void TestRunnerMobile::pullFolder() {
QString command = _adbCommand + " devices > " + _workingFolder + "/devices.txt";
}

View file

@ -20,15 +20,27 @@
class TestRunnerMobile : public QObject, public TestRunner {
Q_OBJECT
public:
explicit TestRunnerMobile(QLabel* workingFolderLabel, QPushButton *readDeviceButton, QObject* parent = 0);
explicit TestRunnerMobile(QLabel* workingFolderLabel, QPushButton *connectDeviceButton, QPushButton *pullFolderButton, QLabel* detectedDeviceLabel, QObject* parent = 0);
~TestRunnerMobile();
void setWorkingFolderAndEnableControls();
void readDevice();
void connectDevice();
void pullFolder();
private:
QLabel* _workingFolderLabel;
QString _workingFolder;
QPushButton* _readDeviceButton;
QPushButton* _connectDeviceButton;
QPushButton* _pullFolderButton;
QLabel* _detectedDeviceLabel;
#ifdef Q_OS_WIN
const QString _adbExe{ "adb.exe" };
#else
// Both Mac and Linux use "adb"
const QString _adbExe{ "adb" };
#endif
QString _adbCommand;
};
#endif

View file

@ -187,7 +187,7 @@
</widget>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Run on Desktop</string>
<string>Test on Desktop</string>
</attribute>
<widget class="QPushButton" name="runNowButton">
<property name="enabled">
@ -549,31 +549,31 @@
</widget>
<widget class="QWidget" name="tab_5">
<attribute name="title">
<string>Run on Device</string>
<string>Test on Device</string>
</attribute>
<widget class="QPushButton" name="readDeviceButton">
<widget class="QPushButton" name="connectDeviceButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>10</x>
<y>100</y>
<y>90</y>
<width>160</width>
<height>30</height>
</rect>
</property>
<property name="text">
<string>Read Device</string>
<string>Connect Device</string>
</property>
</widget>
<widget class="QLabel" name="label">
<widget class="QLabel" name="detectedDeviceLabel">
<property name="geometry">
<rect>
<x>190</x>
<y>100</y>
<width>230</width>
<height>20</height>
<y>96</y>
<width>320</width>
<height>30</height>
</rect>
</property>
<property name="text">
@ -606,6 +606,32 @@
<string>(not set...)</string>
</property>
</widget>
<widget class="QPushButton" name="pullFolderButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>200</x>
<y>170</y>
<width>160</width>
<height>30</height>
</rect>
</property>
<property name="text">
<string>Pull folder</string>
</property>
</widget>
<widget class="QLineEdit" name="folderLineEdit">
<property name="geometry">
<rect>
<x>10</x>
<y>170</y>
<width>161</width>
<height>31</height>
</rect>
</property>
</widget>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">