ruby - cucumber 、 Selenium 、 ruby : best practices to check 301 redirect

标签 ruby selenium-webdriver cucumber

我需要检查 301 重定向。 所以我有应该重定向到新网址的旧网址。 验证它的最佳做法是什么? 现在我正在考虑简单的方法:导航到旧 URL 并检查新 URL 是否正确并显示相应的页面。我可以检查它是301重定向吗? 我找到了以下文章:http://www.natontesting.com/2010/09/06/announcing-responsalizr-test-http-response-codes-in-ruby/

但在重定向后我看到当前状态码 =200 有什么建议我怎样才能捕捉到 301 状态码?

提前致谢

最佳答案

不要在功能规范中这样做。在功能规范( cucumber )中,您测试网站用户如何看待它,用户不关心状态代码是什么。如果您真的关心响应,请在 Controller 或更好的请求规范中执行。使用 rspec,它可能看起来像这样:

describe 'redirects' do
  context 'on GET /old_users' do
    before do
      get '/old_users'
    end

    it 'redirects /old_users to /users' do
      expect(response).to redirect_to('/users')
    end

    it 'responds with a 301 - Permanently moved' do
      expect(response.status).to eq(301)
    end
  end
end

https://www.relishapp.com/rspec/rspec-rails/docs/request-specs/request-spec

关于ruby - cucumber 、 Selenium 、 ruby : best practices to check 301 redirect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20429813/

相关文章:

jquery - 将 # 放在 href 中的 "right"方法是从 onclick 事件执行 HTTP POST 吗?

java - Selenium 从范围报告 3.1.5 迁移到 4.1.6

selenium - 当浏览器忙于执行一些长时间运行的 JavaScript 时 WebDriver API 阻塞行为

java - Selenium 处理 java 中相同类型的重复 xpath

jquery - 单击单词并获取定义...?

ruby - 在 Chef 中更改 ruby​​_block 中的权限时如何执行 "unless"条件?

ruby-on-rails - 使用 Guard 和 Spork 重新加载 RSpec 共享示例

python - 如何在Python中通过Selenium Webdriver从HTML标签的所有子标签中提取文本

ruby - 我如何使用 Ruby 为 Calabash 的功能步骤做多行评论

ruby-on-rails - Capybara 选择器匹配但不是所有过滤器,这是什么意思?