代码之家  ›  专栏  ›  技术社区  ›  joshsz

Cucumber+Capybara:将浏览器重定向到我的应用程序之外的方案出现问题

  •  14
  • joshsz  · 技术社区  · 16 年前
    Given I have a rails app
    And I'm using cucumber
    And I'm using capybara
    And I have an action that results in a redirect_to "http://some.other.domain.com/some_path"
    When I test this action
    Then the in-app portion of the test works fine
    But I see this error: No route matches "/some_path" with {:method=>:get} (ActionController::RoutingError)
    

    所以Capybara被正确地重定向到“ http://some.other.domain.com/some_path 但出于某种原因,它认为它应该处理我的应用程序中URL的路径部分。 注释 凯帕拉对 http://some.other.domain.com/ “--如果我重定向到没有路径部分的URL,则测试通过。

    这是虫子吗?

    7 回复  |  直到 9 年前
        1
  •  1
  •   jnicklas    16 年前

    你用的是哪个司机?机架测试驱动程序不允许您从其他域请求内容。如果水豚用硒或克分子来做这个,那肯定是一种虫子。如果您想帮助修复它,编写一个失败的规范将是 非常 感谢:

        2
  •  6
  •   iGEL    12 年前

    我想我和你有同样的问题:我只是想确认一下,我的代码用正确的状态代码重定向到给定的URL,但是我不想在该URL上做任何事情。

    问题是,站点按预期返回重定向,但rack::test将所有内容解释给被测试的应用程序,而该URL可能不存在。但是我们可以捕捉到错误,然后看看响应是什么样子的。除了Capybara的默认驱动程序,这可能不适用于其他任何程序。

    begin
      click_button('Pay with Paypal')
    rescue ActionController::RoutingError
    end
    
    expect(page.status_code).to eq(302)
    expect(page.response_headers['Location']).to include('paypal.com/cgi-bin/websrc')
    
        3
  •  3
  •   Jay Moorthi    14 年前

    下面是我写的一个关于使用CapybaraMechanical和VCR测试外部重定向的例子。

    http://blog.tddium.com/2011/10/04/testing-external-redirects-vcr-capybara-mechanize/

        4
  •  2
  •   daveharris    9 年前

    我发现了一种很酷的水飞蓟溶液(它可以适应黄瓜)。

    begin
      click_button 'Accept'
    rescue ActionController::RoutingError
      # Capybara doesn't redirect externally, so matches '/cb' but that route doesn't exist
      expect(page.current_url).to eq "https://example.com/cb?param=123"
    end
    
        5
  •  1
  •   nruth    16 年前

    @Javascript是目前正在使用的解决方案,尽管 mechanize driver 在Works中,它使用机架测试直到您碰到外部请求为止。

    它有点新,我还没有尝试过,但我打算将我的外部@javascript测试改为使用它(标记为@live或@external或类似)来提高速度。

        6
  •  1
  •   grosser    11 年前

    使用这个小片段:

    external_redirect "https://api.twitter.com/oauth/authenticate?x_auth_access_type=read&oauth_token=TOKEN" do
      click_link "Continue with Twitter"
    end
    
    def external_redirect(url)
      yield
    rescue ActionController::RoutingError # goes to twitter.com/oauth/authenticate
      current_url.must_equal url
    else
      raise "Missing external redirect"
    end
    
        7
  •  0
  •   paulbjensen    16 年前

    我也遇到过类似的情况,我将我的应用程序与公司的SSO平台集成在一起。我解决这个问题的方法是通过在场景中附加@javascript标记来让站点运行Selenium。