even better js dialog support
This commit is contained in:
parent
7c6db7b036
commit
5d0babe89e
@ -38,6 +38,14 @@ Current supported options:
|
|||||||
|
|
||||||
These options can also be placed into a `.jasmine-headless-webkit` file in your project root.
|
These options can also be placed into a `.jasmine-headless-webkit` file in your project root.
|
||||||
|
|
||||||
|
### JavaScript Dialogs
|
||||||
|
|
||||||
|
You can call `alert()` and `confirm()` in your code. `alert()` will print the message to the console, and
|
||||||
|
`confirm()` will always return true. There's no way right now to respond to `confirm()`, so it's best to
|
||||||
|
mock that call:
|
||||||
|
|
||||||
|
spyOn(window, 'confirm').andReturn(false);
|
||||||
|
|
||||||
### Autotest Integration
|
### Autotest Integration
|
||||||
|
|
||||||
`jasmine-headless-webkit` can integrate with Autotest. Your `jasmine.yml` file needs to be in the default
|
`jasmine-headless-webkit` can integrate with Autotest. Your `jasmine.yml` file needs to be in the default
|
||||||
|
@ -34,6 +34,7 @@ class HeadlessSpecRunnerPage: public QWebPage
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
signals:
|
signals:
|
||||||
void consoleLog(const QString &msg, int lineNumber, const QString &sourceID);
|
void consoleLog(const QString &msg, int lineNumber, const QString &sourceID);
|
||||||
|
void internalLog(const QString ¬e, const QString &msg);
|
||||||
protected:
|
protected:
|
||||||
void javaScriptConsoleMessage(const QString & message, int lineNumber, const QString & sourceID);
|
void javaScriptConsoleMessage(const QString & message, int lineNumber, const QString & sourceID);
|
||||||
bool javaScriptConfirm(QWebFrame *frame, const QString &msg);
|
bool javaScriptConfirm(QWebFrame *frame, const QString &msg);
|
||||||
@ -47,15 +48,13 @@ void HeadlessSpecRunnerPage::javaScriptConsoleMessage(const QString &message, in
|
|||||||
|
|
||||||
bool HeadlessSpecRunnerPage::javaScriptConfirm(QWebFrame *frame, const QString &msg)
|
bool HeadlessSpecRunnerPage::javaScriptConfirm(QWebFrame *frame, const QString &msg)
|
||||||
{
|
{
|
||||||
std::cout << "[TODO] ";
|
emit internalLog("TODO", "jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm for now. Returning true.");
|
||||||
std::cout << "jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm for now. Returning true." << std::endl;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeadlessSpecRunnerPage::javaScriptAlert(QWebFrame *frame, const QString &msg)
|
void HeadlessSpecRunnerPage::javaScriptAlert(QWebFrame *frame, const QString &msg)
|
||||||
{
|
{
|
||||||
std::cout << "[alert] ";
|
emit internalLog("alert", msg);
|
||||||
std::cout << qPrintable(msg) << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class HeadlessSpecRunner: public QObject
|
class HeadlessSpecRunner: public QObject
|
||||||
@ -71,6 +70,7 @@ public slots:
|
|||||||
private slots:
|
private slots:
|
||||||
void watch(bool ok);
|
void watch(bool ok);
|
||||||
void errorLog(const QString &msg, int lineNumber, const QString &sourceID);
|
void errorLog(const QString &msg, int lineNumber, const QString &sourceID);
|
||||||
|
void internalLog(const QString ¬e, const QString &msg);
|
||||||
protected:
|
protected:
|
||||||
bool hasElement(const char *select);
|
bool hasElement(const char *select);
|
||||||
void timerEvent(QTimerEvent *event);
|
void timerEvent(QTimerEvent *event);
|
||||||
@ -98,6 +98,7 @@ HeadlessSpecRunner::HeadlessSpecRunner()
|
|||||||
m_page.settings()->enablePersistentStorage();
|
m_page.settings()->enablePersistentStorage();
|
||||||
connect(&m_page, SIGNAL(loadFinished(bool)), this, SLOT(watch(bool)));
|
connect(&m_page, SIGNAL(loadFinished(bool)), this, SLOT(watch(bool)));
|
||||||
connect(&m_page, SIGNAL(consoleLog(QString, int, QString)), this, SLOT(errorLog(QString, int, QString)));
|
connect(&m_page, SIGNAL(consoleLog(QString, int, QString)), this, SLOT(errorLog(QString, int, QString)));
|
||||||
|
connect(&m_page, SIGNAL(internalLog(QString, QString)), this, SLOT(internalLog(QString, QString)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeadlessSpecRunner::load(const QString &spec)
|
void HeadlessSpecRunner::load(const QString &spec)
|
||||||
@ -162,6 +163,14 @@ void HeadlessSpecRunner::errorLog(const QString &msg, int lineNumber, const QStr
|
|||||||
m_ticker.start(200, this);
|
m_ticker.start(200, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HeadlessSpecRunner::internalLog(const QString ¬e, const QString &msg) {
|
||||||
|
red();
|
||||||
|
std::cout << "[" << qPrintable(note) << "] ";
|
||||||
|
clear();
|
||||||
|
std::cout << qPrintable(msg);
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
void HeadlessSpecRunner::log(const QString &msg)
|
void HeadlessSpecRunner::log(const QString &msg)
|
||||||
{
|
{
|
||||||
usedConsole = true;
|
usedConsole = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user