Skip to content

Quick start - C++

The C++ client uses Qt's signals/slots - every request is fire-and-forget, responses arrive on the responseReceived signal.

Prerequisites

  • find_package(vericue REQUIRED) resolves
  • Your test app links vericue::vericue-client
  • The veriCue server is running on 127.0.0.1:4242

Minimal example

cpp
#include <QCoreApplication>
#include <QJsonObject>
#include <vericue/client.h>

int main(int argc, char *argv[]) {
    QCoreApplication app(argc, argv);
    vericue::VeriCueClient client;

    QObject::connect(&client, &vericue::VeriCueClient::connected, [&]() {
        qInfo() << "Connected, sending mouse click";
        client.mouseClick("MainWindow/centralWidget/okButton");
    });

    QObject::connect(&client, &vericue::VeriCueClient::responseReceived,
        [&](const QString &id, const QJsonObject &result) {
            qInfo() << "Got response:" << result;
            QCoreApplication::quit();
        });

    QObject::connect(&client, &vericue::VeriCueClient::errorReceived,
        [](const QString &, int code, const QString &message) {
            qWarning() << "Error" << code << message;
            QCoreApplication::exit(1);
        });

    client.connectToServer("127.0.0.1", 4242);
    return app.exec();
}

With GoogleTest

veriCue ships a header-only fixture, vericue/gtest_fixture.h, that hides the async plumbing and lets you write synchronous-looking tests:

cpp
#include <gtest/gtest.h>
#include <vericue/gtest_fixture.h>

class LoginTests : public vericue::VeriCueTest {};

TEST_F(LoginTests, OkButtonClicks) {
    QJsonObject result = invoke("mouse_click", QJsonObject{
        {"path", "MainWindow/centralWidget/okButton"},
    });
    EXPECT_TRUE(result["clicked"].toBool());
}

TEST_F(LoginTests, StatusLabelShowsLoggedIn) {
    EXPECT_EQ(prop("MainWindow/statusLabel", "text").toString(), "Logged in");
}

The fixture reads VERICUE_HOST, VERICUE_PORT, and VERICUE_TOKEN environment variables, so the same test binary can run against a local debug session and a CI offscreen target.

Common operations

cpp
// Click
client.mouseClick("MainWindow/okButton");

// Type
client.typeText("MainWindow/searchBox", "hello world");

// Read multiple properties
client.getProperties("MainWindow/usernameField",
    QJsonArray{"text", "enabled", "visible"});

// Set a property
client.setProperty("MainWindow/themeSelector",
    "currentIndex", QJsonValue(2));

// Screenshot to PNG
client.screenshot("MainWindow/canvas");

// Wait for a property value (synchronous on the server side)
client.waitForProperty("MainWindow/statusLabel", "text", "Ready", 5000);

// Push subscriptions - receive eventReceived signals
client.subscribeSignal("MainWindow/okButton", "clicked");
QObject::connect(&client, &vericue::VeriCueClient::eventReceived,
    [](const QString &subId, const QString &event,
       const QString &path, const QJsonObject &data) {
        qInfo() << "Event" << event << "from" << path;
    });

See Clients → C++ for the full method list.

Released under a commercial licence. Privacy · Terms