[SOLVED] QXcbConnection: Could not connect to display [Qt] [Jenkins]



  • I’m having some problems implementing a simple GuiTest (that uses QTestLib) in Jenkins. In a terminal I can execute the following command:

    @./tst_testgui -xunitxml > testresult.xml@

    This command generates the following .xml file:

    @
    <?xml version="1.0" encoding="UTF-8" ?>
    <testsuite errors="0" failures="0" tests="3" name="TestGui">
    <properties>
    <property value="5.0.2" name="QTestVersion"/>
    <property value="5.0.2" name="QtVersion"/>
    </properties>
    <testcase result="pass" name="initTestCase"/>
    <testcase result="pass" name="testGui"/>
    <testcase result="pass" name="cleanupTestCase"/>
    <system-err/>
    </testsuite>@

    In Jenkins I’m trying to do the same by executing the same command in an Execute Shell, but after building the project (works fine) and then executing de command:

    @./tst_testgui -xunitxml > testresult.xml@

    I get the following message in Jenkins:

    QXcbConnection: Could not connect to display
    Aborted (core dumped)
    Build step ‘Execute shell’ marked build as failure
    Finished: FAILURE

    Does somebody know what could be the problem?

    I’m running Jenkins (for the moment) on my localhost and I don’t know if I have a graphic server.
    Where can I check if I’m using a graphic server in Jenkins?

    BTW: There is an empty testresult.xml generated in de workspace folder.

    Grtz. Niels



  • The GuiTest I made is an example project from Qt itself and looks like this:
    @#include <QString>
    #include <QStringList>
    #include <QtTest>
    #include <QLineEdit>

    #include <QApplication>
    #include <QTextEdit>
    #include <QtGui>
    #include <QPushButton>
    #include <QVBoxLayout>
    #include <QMessageBox>

    class TestGui : public QObject
    {
    Q_OBJECT

    private slots:
    void testGui();

    };

    void TestGui::testGui()
    {
    QLineEdit lineEdit;
    QTest::keyClicks(&lineEdit, "hello world");
    QCOMPARE(lineEdit.text(), QString("hello world"));
    }

    QTEST_MAIN(TestGui)

    #include "tst_testgui.moc"@

    The output in QtCreator after running looks like this:

    ********** Start testing of TestGui **********
    Config: Using QTest library 5.0.2, Qt 5.0.2
    PASS : TestGui::initTestCase()
    PASS : TestGui::testGui()
    PASS : TestGui::cleanupTestCase()
    Totals: 3 passed, 0 failed, 0 skipped
    ********* Finished testing of TestGui *********

    When I change:
    @QTEST_MAIN(TestGui)@

    In:
    @QTEST_APPLESS_MAIN(TestGui)@

    The output in QtCreator looks like this:

    ********* Start testing of TestGui *********
    Config: Using QTest library 5.0.2, Qt 5.0.2
    PASS : TestGui::initTestCase()
    QFATAL : TestGui::testGui() QWidget: Must construct a QApplication before a QPaintDevice
    FAIL! : TestGui::testGui() Received a fatal error.
    Loc: [Unknown file(0)]
    Totals: 1 passed, 1 failed, 0 skipped
    ********* Finished testing of TestGui *********
    The program has unexpectedly finished.

    But the error in Jenkins is different now:

    + ./tst_testgui -xml
    Aborted (core dumped)
    Build step 'Execute shell' marked build as failure
    Finished: FAILURE

    Does anybody have an idea?


  • Lifetime Qt Champion

    Hi,

    You are using GUI elements so you have to use QTEST_MAIN.

    When running your application from Jenkins, are you sure that it can find all libraries and plugins ?



  • I think it does, because I can build and compile the project via Jenkins and I managed to make an UnitTest using CppUnit via the JUnit-plugin in an other project with (almost) the same configuration and that works perfect.

    Via the terminal I can exucte the program (tst_testgui) but not with Jenkins.

    Thnx for the fast response!

    EDIT: I'm not using a plugin at the moment. I'm only using shell commands.

    EDIT2: When try to execute the program via Jenkins from my home directory I get the same output as before:
    + /home/hotracodev/workspace/Focus/Experiment/TutorialGuiTest/tutorialGuiTest/tst_testgui
    QXcbConnection: Could not connect to display
    Aborted (core dumped)
    Build step 'Execute shell' marked build as failure
    Finished: FAILURE


  • Lifetime Qt Champion

    Yes you are: Qt 5's platform plugin which is using xcb in your case.

    I don't know jenkins but you could try to see if sets somehow the environment variables before doing a test and if so how does it differ from your console environment variables



  • I managed to solve my problem.

    The problem was in the configuration of Jenkins.
    I needed to use an X-server on my Jenkins machine to run my GUI programs.

    #SOLVED


  • Lifetime Qt Champion

    Great you found out !

    Can you update your thread's title to solved ? So other forum users may know a solution has been found :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.