隐藏的按钮水豚

时间:2015-05-12 14:27:25

标签: ruby-on-rails ruby capybara

我正在尝试测试水豚中的隐藏按钮,但到目前为止还没有能够在没有以下错误的情况下使其工作。

#include <QApplication>
#include <QCoreApplication>
#include <QOffscreenSurface>
#include <QOpenGLContext>
#include <QOpenGLFunctions>
#include <QOpenGLFramebufferObject>
#include <QOpenGLShader>
#include <QOpenGLTexture>
#include <QLabel>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QSurfaceFormat format;
    format.setMinorVersion( 2 );
    format.setMajorVersion( 4 );
    format.setProfile( QSurfaceFormat::CompatibilityProfile );
//    format.setProfile( QSurfaceFormat::CoreProfile );

    QOpenGLContext context;
    context.setFormat(format);
    if(!context.create()){        
        qFatal("Cannot create the requested OpenGL context!");
    }

    QOffscreenSurface surface;
    surface.setFormat( format );
    surface.create();
    context.makeCurrent( &surface );

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0.0, 1.0, 0.0, 1.0, 0.0, 1.0);
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    const float c_01SquareVertices[8] ={0.0f, 0.0f,
                                        1.0f, 0.0f,
                                        1.0f, 1.0f,
                                        0.0f, 1.0f};
    glVertexPointer(2, GL_FLOAT, 0, c_01SquareVertices);
    glTexCoordPointer(2, GL_FLOAT, 0, c_01SquareVertices);
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_TEXTURE_2D);
    int maxTextureUnits;
    glGetIntegerv ( GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits );
    qDebug()<<"GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS" << maxTextureUnits;

    QImage texImg = QImage(":/tex/tex");
    QOpenGLTexture tex(texImg.mirrored());
    QImage texImg1 = QImage(":/tex/tex1");
    QOpenGLTexture tex1(texImg1.mirrored());
    QImage texImg2 = QImage(":/tex/tex2");
    QOpenGLTexture tex2(texImg2.mirrored());

    QString fsc =
            "uniform sampler2D tex;"
            "uniform sampler2D tex1;"
            "uniform sampler2D tex2;"
            "varying vec4 gl_TexCoord[];"
            "void main(void)"
            "{"
            "   gl_FragColor = texture2D(tex2, gl_TexCoord[0].yx * 2.0);"
//            "   gl_FragColor = texture2D(tex1, gl_TexCoord[0].xy) + texture2D(tex2, gl_TexCoord[0].xy);"
            "}";

    QOpenGLShader fsh( QOpenGLShader::Fragment, &context );
    fsh.compileSourceCode( fsc );

    QOpenGLShaderProgram pr( &context );

    pr.addShader( &fsh );
    pr.link();

    QOpenGLFramebufferObjectFormat fboFormat;
//    fboFormat.setInternalTextureFormat(GL_ALPHA32F);
    QOpenGLFramebufferObject fbo( 1000, 1000, fboFormat );
    fbo.bind();
        glViewport(0,0,fbo.width(),fbo.height());
        glClear(GL_COLOR_BUFFER_BIT);

        tex.bind(0);
        pr.setUniformValue("tex", GLuint(1));

        tex1.bind(2);
        pr.setUniformValue("tex1", GLuint(2));

        tex2.bind(3);
        pr.setUniformValue("tex2", GLuint(3));

        pr.bind();

        glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
    fbo.release();

    QLabel w;
    w.resize(fbo.size());
    w.setPixmap(QPixmap::fromImage(fbo.toImage()));
    w.show();

    return a.exec();
}

有人可能建议使用正确的语法。 电话如下:

undefined method `click_on' for [#<Capybara::Element tag="button">]

2 个答案:

答案 0 :(得分:0)

好的,从评论/答案开始。这就是我要做的事情:

  • 取消隐藏按钮。
  • 让规格通过。 @tridadc的答案应该有效。
  • 将测试标记为待处理/ TODO
  • 将按钮重新隐藏。
  • 当按钮准备就绪并可见时,将测试从挂起更改为活动。

答案 1 :(得分:-1)

如果您的按钮被隐藏,我认为您需要这样做:

find(".playback", visible: false).click

您也可以尝试

Capybara.ignore_hidden_elements = false
find(".playback").click
Capybara.ignore_hidden_elements = true