Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何编写对多步骤流程的更改具有弹性的Cypress测试_Cypress_E2e Testing - Fatal编程技术网

如何编写对多步骤流程的更改具有弹性的Cypress测试

如何编写对多步骤流程的更改具有弹性的Cypress测试,cypress,e2e-testing,Cypress,E2e Testing,我在一个单页应用程序中有一个多步骤的过程。将来,可能会在流程中的任何位置添加更多步骤,并且步骤的顺序可能会改变。每个步骤都有其组件,其中包含一个表单和一个“下一步”按钮。如果用户未在表单中选择任何选项,则应禁用该按钮 我想编写一个能够适应过程中变化的测试。这意味着我不想硬编码测试哪一步的概念,而是希望有条件地完成整个多步骤过程,测试如果没有选择任何选项,下一步按钮是否被禁用。在任何步骤上都没有http调用,所以我不必为这个测试担心 在伪代码中,我想到的是: visit the first pag

我在一个单页应用程序中有一个多步骤的过程。将来,可能会在流程中的任何位置添加更多步骤,并且步骤的顺序可能会改变。每个步骤都有其组件,其中包含一个表单和一个“下一步”按钮。如果用户未在表单中选择任何选项,则应禁用该按钮

我想编写一个能够适应过程中变化的测试。这意味着我不想硬编码测试哪一步的概念,而是希望有条件地完成整个多步骤过程,测试如果没有选择任何选项,下一步按钮是否被禁用。在任何步骤上都没有http调用,所以我不必为这个测试担心

在伪代码中,我想到的是:

visit the first page of the process
while(there is a next button on the page // if not we are on the last step/screen) {
  assert that the button is disabled

  select the first option in the form
  click the button // taking us to the next step/screen in the process
}
我一辈子都想不出如何用柏树做这件事。任何帮助都将不胜感激


此外,如果有另一种更为cypressy的算法来实现我的目标,我完全愿意接受。对我来说,重要的不是实现我的精确算法,而是编写一个不需要修改的测试,如果我们决定在过程中间添加一个步骤/屏幕。

< P>这是我能想到的最好的。它使用递归并按预期工作,但在我看来,它是丑陋的

函数运行测试(){
cy.get('body')。然后($body)=>{
if($body.find('button:contains(“Next”)).length){
cy.get('input').should('not.have.property','checked');
cy.contains('button','Next')。应('be.disabled');
cy.get('input').first().check({force:true});
cy.contains('按钮','下一步')
。单击()
。然后(运行测试);
}
});
}

您不应该像这样使用cypress,而应该使用模拟/设置状态然后测试UI。