Test your websites with this simple GUI based scripted webtester. Generate simple testscripts directly from surfng on the webpage, enhance them with your commands, with variables, loops, checks, … and finally run automated web tests.
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.9 KiB
71 lines
1.9 KiB
9 years ago
|
/*! @file
|
||
|
|
||
|
@id $Id$
|
||
|
*/
|
||
|
// 1 2 3 4 5 6 7 8
|
||
|
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
||
|
#ifndef WEBPAGE_HXX
|
||
|
#define WEBPAGE_HXX
|
||
|
|
||
|
#include <exceptions.hxx>
|
||
|
#include <networkaccessmanager.hxx>
|
||
|
#include <QWebPage>
|
||
|
#include <QWebFrame>
|
||
|
#include <QWidget>
|
||
|
#include <QFileDialog>
|
||
|
#include <QFile>
|
||
|
|
||
|
#include <cassert>
|
||
|
#ifndef LOG
|
||
|
#include <iostream>
|
||
|
#define LOG(X) std::clog<<X<<std::endl;
|
||
|
inline std::ostream& operator<<(std::ostream& o, const QString& s) {
|
||
|
return o<<s.toStdString();
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
class TestWebPage: public QWebPage {
|
||
|
Q_OBJECT;
|
||
|
public:
|
||
|
TestWebPage(QObject* parent = 0, bool unattended = false):
|
||
|
QWebPage(parent),
|
||
|
_unattended(unattended) {
|
||
|
setNetworkAccessManager(new NetworkAccessManager(this));
|
||
|
}
|
||
|
virtual ~TestWebPage() {
|
||
|
if (!_nextFile.isEmpty() && !std::uncaught_exception())
|
||
|
throw LastFileNotUploaded(_nextFile);
|
||
|
}
|
||
|
void setNextUploadFile(QString nextFile) {
|
||
|
if (!_unattended) throw NotUnattended();
|
||
|
if (!_nextFile.isEmpty()) throw LastFileNotUploaded(_nextFile);
|
||
|
if (nextFile.isEmpty()) throw EmptyUploadFile();
|
||
|
_nextFile = nextFile;
|
||
|
}
|
||
|
bool uploadPrepared() {
|
||
|
return !_nextFile.isEmpty();
|
||
|
}
|
||
|
Q_SIGNALS:
|
||
|
void uploadFile(QString filename);
|
||
|
protected:
|
||
|
virtual QString chooseFile(QWebFrame* frame, const QString&) {
|
||
|
if (_unattended) {
|
||
|
if (_nextFile.isEmpty()) throw NoUploadFile();
|
||
|
if (!QFile(_nextFile).exists()) throw FileNotFound(_nextFile);
|
||
|
QString filename(_nextFile);
|
||
|
_nextFile.clear();
|
||
|
return filename;
|
||
|
} else {
|
||
|
QString filename(QFileDialog::getOpenFileName
|
||
|
(frame->page()->view(), tr("File to Upload")));
|
||
|
if (filename.size()) uploadFile(filename);
|
||
|
return filename;
|
||
|
}
|
||
|
}
|
||
|
private:
|
||
|
bool _unattended;
|
||
|
QString _nextFile;
|
||
|
};
|
||
|
|
||
|
#endif
|