【问题标题】:How can I get the url in cypress?如何获取柏树中的网址?
【发布时间】:2021-12-16 16:57:57
【问题描述】:

当我点击按钮时,我会尝试检查我是否在正确的页面上。

这是我的代码:

describe('espace_parent is functional', () => {
  it('test login parent', () => {

    cy.visit('http://localhost:3000')
    cy.contains('parent').click()
    cy.contains('Espace Parent')



    cy.get(":input[placeholder='Adresse e-mail']").type('guigui@guigui.fr')
    cy.get(":input[placeholder='Mot de passe']").type('guigui')
    cy.contains('Se connecter').click() 


    cy.log('Current URL is ')
    cy.contains("Accueil")

  })
})

在此代码上,我在 localhost3000 上,我单击必须将我重定向到 localhost3000/connexion/parent 的父级,我想登录但我不知道它是否正常运行。

我已经尝试做不同的事情来打印 URL,但没有任何工作。

【问题讨论】:

    标签: javascript cypress


    【解决方案1】:

    您必须使用cy.url()

    1. 要打印您可以使用的 URL:
    cy.url().then((url) => {
      cy.log('Current URL is: ' + url)
    })
    
    1. 如果您想验证可以使用的 URL:
    cy.url().should('include', '/connexion/parent')
    

    【讨论】:

      【解决方案2】:

      您可以使用命令cy.url()cy.location() 获取网址。

      你会像这样使用cy.url()

      // with should()
      cy.url().should('eq', 'http://localhost:3000/connexion/parent');
      cy.url().should('include', '/connexion/parent');
      // with then()
      cy.url().then(url => cy.log('Current URL is', url);
      

      【讨论】:

        猜你喜欢
        • 2022-01-23
        • 2022-08-05
        • 2021-12-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多