如何从柏树小黄瓜设置中的场景大纲中获取场景名称?

时间:2020-02-27 08:42:50

标签: cucumber cypress gherkin

假设我有一个测试用例-

Scenario: Scenario to verify Title Matched 

  When Navigate to the App "Facebook"

  Then verify the "TitleName" Field

如何从对应于“当导航到App Facebook时”和“然后验证“ TitleName”字段”的步骤定义方法中获取场景名称

步骤定义方法是-

When('Navigate to the App {string} for demo',(AppURL:string)=>{

    if(AppURL=="FaceBook"){

    }

});

Then('verify the Title of the page for demo',()=>

 {    
        SampleAPPUI.verfiyTitledemo('');

});

注意:我正在使用带有typescript的cypres-cucumber

2 个答案:

答案 0 :(得分:0)

我正在Java-Selenium-Gherkin测试套件中进行此操作。可能不是您需要的解决方案,但是它将为您提供有关如何获取值的一些指导:

@BeforeStep
public void doSomethingBeforeStep(Scenario scenario) throws Exception {
    testScenario = scenario.getName().toString();
    scenarioObj = scenario;
    Field f = scenario.getClass().getDeclaredField("testCase");
    f.setAccessible(true);
    TestCase r = (TestCase) f.get(scenario);

    List<PickleStepTestStep> stepDefs = r.getTestSteps()
            .stream()
            .filter(x -> x instanceof PickleStepTestStep)
            .map(x -> (PickleStepTestStep) x)
            .collect(Collectors.toList());

    PickleStepTestStep currentStepDef = stepDefs.get(currentStepIndex);
    testCase = currentStepDef.getStepText();
}

另外,请参见herehere

答案 1 :(得分:0)

这对我来说非常合适,尽管我没有使用TS,但其背后的逻辑应该为您提供一个良好的起点:

const arr = [0, 2, 4, 6];
let flag = true;
diff = arr[1] - arr[0];
for(let i = 1; i < arr.length-1; i++){
           if(arr[i+1] - arr[i]  != diff ){
              flag = false;
              break;
           } 


     }
console.log(flag)