Ruby on rails 5 轨道与cypress形成_,给出CSRF错误

Ruby on rails 5 轨道与cypress形成_,给出CSRF错误,ruby-on-rails-5,integration-testing,cypress,cypress-cucumber-preprocessor,Ruby On Rails 5,Integration Testing,Cypress,Cypress Cucumber Preprocessor,我在这个问题上纠缠了将近两天 这是我正在使用的表单 <%= component "modal", title: "Remove Vessel", content_only: true do |c| %> <% c.body do %> <%= form_for @vessel, url: { controller: controller_n

我在这个问题上纠缠了将近两天

这是我正在使用的表单

<%= component "modal", title: "Remove Vessel", content_only: true do |c| %>
  <% c.body do %>
    <%= form_for @vessel,
                  url: {
                    controller: controller_name,
                    action: :remove
                  },
                  builder: WrappedFormBuilder,
                  remote: true,  authenticity_token: true do |f| %>
      <div class="modal__body">
        <p>Do you want to move the users to another vessel?</p>
        </br>
        <p><b>Move Users to Vessel:</b></p>
        <%= select_tag "vessel_id", options_from_collection_for_select((Vessel.all.where.not(id: @vessel.id)), "id", "name"), include_blank: 'Do not move users' %>
      </div>
      <div class="modal__footer">
        <%= button_tag "Cancel",
                       type: :button,
                       class: "btn--link u-mr u-text-muted",
                       data: { cy: "vessel-removal-cancel", target: "form-activation.action", action: "modal#hide" } %>
        <%= f.submit "Save",
          class: "btn btn--primary",
          data: {
            cy: "vessel-submit",
            disable_with: "Removing"
          }
        %>
      </div>
    <% end %>
  <% end %>
<% end %>
最后给出了测试代码

it("remove an existing vessel with users", () => {
        cy.get("[data-cy=vessel-1-remove]").click();
        cy.wait(2000);
        cy.get("[data-cy=vessel-submit]").click();
        cy.wait(4000);
        cy.get("[data-cy=vessel-1]").should("not.exist");
    });
塞浦路斯显示了这一错误

CypressError:Cypress检测到页面加载时发生跨原点错误:

用“原点”阻止帧http://localhost:3000“从访问交叉原点帧

在页面加载之前,您已绑定到源策略:

http://localhost:3000

当应用程序导航到与上述源策略不匹配的新超域时,会发生跨源错误

这通常以以下三种方式之一发生:

  • 您单击了将您路由到应用程序外部的
  • 您提交了一个表单,服务器将您重定向到应用程序之外
  • 您使用javascript重定向到应用程序外部的页面
  • Cypress不允许您在单个测试中更改超域

    您可能需要重新构造一些测试代码以避免此问题

    或者,您也可以禁用chromeWebSecurity,这将通过在“cypress.json”中设置{chromeWebSecurity:false}来关闭此限制

    由于此错误发生在“每次之前”挂钩期间,因此我们将跳过当前套件中的其余测试:“管理>设置>船只”

    @vessel = scope.find(params[:id])
            authorize([:manage, :settings, @vessel])
    
            if @vessel.move_users_and_delete(params[:vessel_id])
              redirect_to edit_manage_organization_settings_meta_data_path,
                          flash: { success: "Users Moved and Vessel updated" }
            else
              render "delete", flash: { danger: "There were issues updating the vessel" }
            end
    
    it("remove an existing vessel with users", () => {
            cy.get("[data-cy=vessel-1-remove]").click();
            cy.wait(2000);
            cy.get("[data-cy=vessel-submit]").click();
            cy.wait(4000);
            cy.get("[data-cy=vessel-1]").should("not.exist");
        });