【问题标题】:Nightwatch/Cucumber - Scenario Outline and Example table not workingNightwatch/Cucumber - 场景大纲和示例表不起作用
【发布时间】:2025-12-20 07:00:12
【问题描述】:

我不是开发人员,所以还在学习 javascript 等。 我使用 Nightwatch/Cucumber 启动并运行了一些自动化脚本。我现在正在尝试更复杂的步骤。 带有示例表的场景大纲。我面临的问题是,我无法通过测试从表中获取数据。它到达步骤,然后重新开始而没有实际填充。看起来我的步骤没有定义。 我正在使用 PageObjects,除了这种情况外,这一切都可以正常工作。我不确定如何正确编码步骤

场景大纲

When I create a new Lot 
Then I can create multiple Lots using a different <postcode>

Examples:
|postcode|
|WF4 5HQ |
|SA11 1DJ|

步骤定义

Then(/^I can create multiple lots using a different ([^\"]*)$/, (postcode) => {
return pageLotsMultiple
    .useXpath()
    .waitForElementVisible('//*[@id="__06a943c59f33a34bb5924aaf72cd2995"]/input')
    .pause(1000)
    .setPostcode(postcode)

我尝试了各种方法,都做同样的事情

Then(/^I can create multiple lots using a different ([^\"]*)$/, (postcode) => {
return pageLotsMultiple
    .setPostcode(postcode)
    .addProperty()
    .waitForElementVisible('@newPostcode')
    .newPostcode()

测试在没有表格和编码邮政编码的情况下运行良好,但我想避免这种情况

【问题讨论】:

    标签: javascript cucumber nightwatch.js


    【解决方案1】:

    这是我们每个人都会经历的愚蠢错误。我将用 quotes 写下你的。

    Scenario Outline: Scenario Name
    When I create a new Lot
    Then I can create multiple Lots using a different <postcode>
    
    Examples:
      | postcode   |
      | "WF4 5HQ"  |
      | "SA11 1DJ" |
    

    【讨论】:

    • 您好,感谢您的回复,但没有帮助:? Then I can create multiple Lots using a different "WF4 5HQ" Undefined. Implement with the following snippet: Then('I can create multiple Lots using a different {string}', function (string) { // Write code here that turns the phrase above into concrete actions return 'pending'; });
    • 你有这个在 repo 或者我可以看看的东西吗?
    【解决方案2】:

    “然后我可以使用不同的批次创建多个批次”不等于“我可以使用不同的批次创建多个批次”。批次的情况不同。

    【讨论】:

      最近更新 更多