【问题标题】:Cypress: The command was expected to run against origin赛普拉斯:该命令应针对原点运行
【发布时间】:2023-02-05 09:33:41
【问题描述】:

我尝试通过使用 cy.origin() 更改测试源来实现 Cypress 12 支持的多选项卡测试。我使用 https://www.blender.org/ 作为我在配置文件中设置的 baseUrl,从 Blender 主页我将 href 提取到 Instagram 并将原点更改为它。赛普拉斯给我以下错误:

该命令预期针对源 https://instagram.com 运行,但应用程序位于源 https://www.instagram.com

这是我在测试中所做的:

 When('I change the origin of my test configuration', () => {
  cy.window().then((win) => {
    cy.stub(win, 'open').as('Open');
  });
  const url = Cypress.config('baseUrl');
  cy.visit(url);
  cy.window().scrollTo('bottom');
  var instaUrlString;
  cy.get('.social-icons__instagram')
    .invoke('attr', 'href')
    .then(($instaUrl) => {
      instaUrlString = $instaUrl.toString();
      cy.origin(instaUrlString, { args: instaUrlString }, (instaUrlString) => {
        cy.visit(instaUrlString);
        cy.wait(2000);
        cy.contains('Allow essential and optional cookies').click();
      });
    });
  cy.visit(url);
});

当我将硬编码字符串传递给 cy.origin() 时,它工作正常。我究竟做错了什么?

【问题讨论】:

    标签: cypress cypress-origin


    【解决方案1】:

    错误消息表明您正在尝试访问具有来源的 URL“https://instagram.com”但应用程序的实际来源是“https://www.instagram.com”.要解决此问题,您需要修改您正在访问的 URL 以匹配应用程序的实际来源。

    尝试这个:

     When('I change the origin of my test configuration', () => {
          cy.window().then((win) => {
            cy.stub(win, 'open').as('Open');
          });
          const url = Cypress.config('baseUrl');
          cy.visit(url);
          cy.window().scrollTo('bottom');
          var instaUrlString;
          cy.get('.social-icons__instagram')
            .invoke('attr', 'href')
            .then(($instaUrl) => {
              instaUrlString = $instaUrl.toString();
              const updatedInstaUrl = instaUrlString.replace('instagram.com', 'www.instagram.com');
              cy.origin(updatedInstaUrl, { args: updatedInstaUrl }, (updatedInstaUrl) => {
                cy.visit(updatedInstaUrl);
                cy.wait(2000);
                cy.contains('Allow essential and optional cookies').click();
              });
            });
          cy.visit(url);
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-27
      • 1970-01-01
      • 1970-01-01
      • 2022-09-30
      • 2021-12-05
      • 1970-01-01
      相关资源
      最近更新 更多