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 Runtime is running inside your application under test, on a transport you know: a local IPC endpoint (VERICUE_ENDPOINT=<path>, Linux/macOS) or a TCP port such as 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);
        });

    // Same machine, Linux/macOS - the endpoint the app announced:
    client.connectToLocalServer("/run/user/1000/vericue/vericue-4213.sock");
    // ... or over TCP (Windows, remote CI, containers, devices):
    // client.connectToServer("127.0.0.1", 4242);
    return app.exec();
}

Both calls send the handshake for you and emit connected() once it succeeds; everything after that point is identical.

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 takes its transport from the environment, so the same test binary runs against a local debug session and a CI target without recompiling:

VariableMeaningDefault
VERICUE_ENDPOINTLocal IPC endpoint path (Linux/macOS)(unset)
VERICUE_HOSTTCP host127.0.0.1
VERICUE_PORTTCP port4242
VERICUE_TOKENAuthentication token, either transport(empty)
bash
# Same machine - the endpoint the app announced
VERICUE_ENDPOINT=/run/user/1000/vericue/vericue-4213.sock ./my-tests

# Remote CI, containers, devices, Windows
VERICUE_HOST=10.0.0.7 VERICUE_PORT=4242 VERICUE_TOKEN=$CI_TOKEN ./my-tests

Precedence: a non-empty VERICUE_ENDPOINT selects local IPC and VERICUE_HOST/VERICUE_PORT are ignored - the same rule the CLI applies to --endpoint versus --host/--port. Setting VERICUE_ENDPOINT= (empty) counts as unset, which is how a run that inherited the endpoint announcement from vericue run can still be pointed at TCP.

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