【问题标题】:C++ desktop GUI testing on Travis CITravis CI 上的 C++ 桌面 GUI 测试
【发布时间】:2017-07-24 13:13:49
【问题描述】:

我非常喜欢 Travis CI 的持续集成测试。我用它测试了我的大部分 C++ 控制台、桌面(Qt、SFML)和 Web(使用 Wt)应用程序。它非常适合测试基于浏览器的应用程序and has documented this nicely

我不能做的一件事是在 Travis CI 上测试桌面应用程序的 GUI。

我需要一些基本的东西,比如“获得一个具有特定标题/名称的窗口”、“在窗口中心单击鼠标左键”和“向窗口发送一个空格”。

我已经可以使用 xdotools、LDTP2 和 Sikuli 在本地执行此操作,但只能在本地执行。然而,在 Travis CI 上,我无法让这些工具成功运行。我一直在尝试写一个tutorial 关于它(these are my scripts),我有contacted the folks at Travis 甚至set a bounty here,都没有成功。

因为这是一个复杂的过程(在 Travis 上设置 Windows 管理器,编写桌面应用程序进行测试,编写脚本以在 bash 中测试这些)我认为在这里发布那些小错误没有用(大多数都有答案在这里已经)。

我的问题是:有没有人有一个可行的例子

  • 非 Web C++ GUI 应用程序
  • 在本地和 Travis 上都对其 GUI 进行了测试
  • 这些测试包括发送按键和鼠标点击

我不关心确切的工具(xdotools 或其他一些窗口管理器工具、Qt 或其他一些 C++ GUI 库、bash 或任何其他脚本语言)。我只想让 Travis CI 在git push 上检查我的 GUI。

【问题讨论】:

    标签: c++ user-interface travis-ci desktop-application xdotool


    【解决方案1】:

    不确定这是否回答了您的问题,但您尝试过的东西的语法可能是导致它对您造成破坏的原因。

    upstream issue中,反复使用如下:

    var=value; program
    

    您能否尝试使用以下语法:

    var=value program
    

    export var=value; program
    

    解释:; 是表达式的终止符,刚刚设置的变量不适用于子 PID。导出变量或使用特殊语法(不带; 作为分隔符)将使刚刚设置的变量可用于子 PID。

    【讨论】:

    • 这很有帮助。我现在就试试这个。谢谢!
    • 我尝试过使用它,但travis-ci.org/richelbilderbeek/… 表明这不是问题所在。不过感谢您的帮助:-)
    【解决方案2】:

    好吧,我在这里:

    Nana C++ GUI test in Travis

    Other click,在特拉维斯:

    3.04s$ ./clicked
    Will wait 2 sec...
    waiting 2 sec...
    running... 
    3 times automatic click. 
    Automatically clicking widget :
    When the window  fm  is clicked, this function is called. 
    Automatically clicking widget :
    When the window  fm  is clicked, this function is called. 
    Automatically clicking widget :
    When the window  fm  is clicked, this function is called. 
    Now with then mouse. 
    Congratulations, this was not trivial !
    Done... 
    Now again waiting 1 sec...
    Done... Now API::exit all ...
    

    编程here

    void clicked(const nana::arg_click & eventinfo)
    {
         std::cout<<  "When the window  fm  is clicked, this function is called. \n";
    }
    
    
    
    int main()
    {
        using namespace nana;
        form fm;
        fm.events().click(clicked);
        fm.show();
        exec( 2, 1, [&fm]()
            {
                std::cout << "3 times automatic click. \n";
                click(fm);
                click(fm);
                click(fm);
    
                nana::arg_mouse m;
                m.window_handle=fm;
                m.alt=m.ctrl=m.mid_button=m.shift=false;
                m.left_button=true;
                m.pos.x=m.pos.y=1;
                m.button=::nana::mouse::left_button;
    
                std::cout << "Now with then mouse. \n";
                //fm.events().mouse_down.emit(m);
                //fm.events().mouse_up.emit(m);
    
                // char c;
                // std::cin >> c;
    
                //fm.close();
    
             });
    }
    

    这还远远没有准备好,只是我最初的想法。我最大的问题是我没有在 linux 中使用 GUI 的经验。我只实现了几个测试,几个例子,这足以让我们发现大问题。我在 Windows 中测试本地化(好吧,当我有时间时......)但我个人无法在 linux 中进行测试,所以,Travis 对我来说非常有用。 我发明了一些函数来在 GUI 库 self 中编写测试。 (还)不是很优雅。我希望我有时间让它变得更好。我很乐意看到您的解决方案。

    【讨论】:

    • 我很高兴听到您享受体面的单元测试。太糟糕了,它没有回答我的问题,例如'得到一个具有特定标题/名称的窗口'。我也能够从应用程序中操作我的窗口。我想从程序外部发送按键和鼠标点击。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-28
    • 2020-07-27
    • 1970-01-01
    • 1970-01-01
    • 2018-11-21
    相关资源
    最近更新 更多