0

我被困在这个问题上将近两天了。

这是我正在使用的表格

<%= 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 %>

这是传递给控制器​​的参数。

<ActionController::Parameters {"utf8"=>"✓&quot;, "_method"=>"patch", "authenticity_token"=>"KF2LG9i6kRP956HbwtvaEjmy1Dq2v-slrhHWE9CrByRK7SIgx-Mk7j4KvEpRR-lBixFRM3oEhi-p8yuAs31SwQ", "vessel_id"=>"", "button"=>"", "commit"=>"Save", "controller"=>"manage/settings/vessels", "action"=>"remove", "organization_id"=>"1", "id"=>"1"} permitted: 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");
    });

塞浦路斯显示此错误。

CypressError:赛普拉斯检测到页面加载时发生跨源错误:

阻止来源为“http://localhost:3000”的框架访问跨域框架。

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

http://localhost:3000

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

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

  1. 您单击了将您路由到应用程序之外的
  2. 您提交了一个表单,您的服务器将您重定向到您的应用程序之外
  3. 您使用 javascript 重定向到应用程序外部的页面

Cypress 不允许您在单个测试中更改超级域。

您可能需要重组一些测试代码以避免此问题。

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

https://on.cypress.io/cross-origin-violation

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

4

0 回答 0