测试重定向到与赛普拉斯

测试重定向到与赛普拉斯

问题描述:

一条新的路径,我使用Cypress测试我的Web应用程序。测试重定向到与赛普拉斯

这个片段当前工作,并会提交一个新的东西:

describe('The Create Page',() => { 
    it('successfully creates a thing',() => { 
    cy.visit('/create') 
    cy.get('input[name=description]').type('Hello World') 
    cy.get('button#submit') 
     .click() 

    // After POST'ing this data via AJAX, the web app then 
    // receives the id of the new thing that was just created 
    // and redirects the user to /newthing/:id 
    // How do I test that this redirection worked? 
    }) 
}) 

就像注解说明,我不知道如何测试重定向是否将新的路线的作品。我可以在浏览器模拟中看到它的重定向工作,我只是想为它添加一个测试。

谢谢!

你需要做的是断言,网址是在期望的状态。

有赛普拉斯很多命令,可以用来做出关于网址的断言。具体来说,cy.url()cy.location()cy.hash()可满足您的要求。可能是您的使用情况下,最好的例子是这样的:

cy.location('pathname').should('eq', '/newthing/:id') 
+0

所以......这个服务器我的web应用程序是POST'ing到可能需要过长...时间响应(如超过10秒)......我仍然得到这个错误:赛普拉斯错误:超时重试:预计'/创造'等于'/新事物/:身份证'...我可以改变多久柏树会继续尝试的东西?另外,thx的帮助,真的很感激它! – SeanPlusPlus

+1

是的。你可以阅读这些定时重试的细节[这里](https://on.cypress.io/introduction-to-cypress#Applying-Timeouts)。 从本质上讲,直到你的说法相符赛普拉斯将不断检查位置的路径('/ newthing /:id'),或者直到超时。默认的超时时间是4000ms。 'cy.location( '路径',{超时:10000})你可以通过传递超时选项'cy.location()'像这样增加这个时候应该( '情商', '/ newthing /:身份证'。 )' –

+0

宾果!超时工作。 Thx soooo !!! – SeanPlusPlus