javascript - 柏树中的应用程序重定向,外部没有

标签 javascript redirect cypress e2e-testing e2e

我正在尝试使用 Cypress 为这个应用程序编写端到端测试:https://app.gotphoto.com/admin/auth/login当我从浏览器访问上述 url 时,会显示一个登录表单,正如预期的那样。
当我通过 Cypress 访问上述网址时:

  • cypress 首先导航到 https://app.gotphoto.com/admin/auth/login
  • 紧接着我被重定向到 https://app.gotphoto.com/__/并且登录表单未显示

  • 这是 Cypress 内部的两个屏幕截图:
    enter image description here
    enter image description here
    我的问题是:为什么它在我的浏览器中的运行方式与它在 Cypress / Cypress 的浏览器中的运行方式之间存在差异?
    我使用的浏览器是 Chrome 89,无论在有和没有 Cypress 的情况下运行。
    我正在运行的整个测试是这样的:
    describe('login screen', () => {
      it('logs in', () => {
        cy.visit('/admin/auth/login');
      });
    });
    
    
    使用 cypress.json:
    {
      "baseUrl": "https://app.gotphoto.com"
    }
    
    
    我创建了一个 repo使用上述配置,因此很容易重现。

    最佳答案

    /__/ https://app.gotphoto.com/__/ 的一部分被称为 客户端路由 是 Cypress 的内部配置项。
    您可以在 cypress.json 中将其关闭。配置文件

    {
      ...
      "clientRoute": "/"
    }
    
    这有效地保留了您的原始网址并允许页面正确加载。
    cy.visit('https://app.gotphoto.com/admin/auth/login')
    cy.get('input#username', { timeout: 10000 }).type('admin') // long timeout
                                                               // wait for page to load
    cy.get('input#password').type('password')
    
    cy.intercept('POST', 'api.getphoto.io/v4/auth/login/user').as('user')
    cy.contains('button', 'Submit').click()
    
    cy.wait('@user').then(interception => {
      // incorrect credentials
      expect(interception.response.body.detail).to.eq('Login failed!')
    })
    
    我不确定更改 clientRoute 是否有任何不良副作用,如果我找到它会发布更多信息。

    关于javascript - 柏树中的应用程序重定向,外部没有,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66613875/

    相关文章:

    javascript - JQuery for Select Option 影响页面中的所有选择选项

    cypress - 我需要更改默认的 Cypress 装置和支持文件夹

    javascript - Chrome --enable-precise-memory-info 不起作用并且 performance.memory 仍然是 bucketized

    javascript - 使用mysql通过javascript访问全局函数

    .htaccess - (如何)我可以向网站添加第二个域以改善 SEO?

    javascript - 将 imageURI 传递到另一个 html 页面

    .htaccess - 如何使用 htaccess 重写在子域上保留 SSL?

    javascript - Cypress 和 cookies 弹出窗口 : how to get rid of it

    javascript - Array.toString 在循环外返回空

    JavaScript:为什么我不能用 .push() 链接 Array.prototype.filter?