提问人:MeltingDog 提问时间:11/6/2023 更新时间:11/6/2023 访问量:17
如何在一个功能文件上运行多个 Cucumber .js测试方案?
How do I run multiple Cucumber.js test scenarios on the one feature file?
问:
我是 Cucumber 测试的新手,并使用 Selenium Webdriver、Cucumber.js 和 node.js 设置了一个环境。我已经能够很好地设置单个测试,但对如何运行多个测试感到困惑(我谷歌上的所有内容都只有单个测试的示例)。
我的 .feature Gherkin 文件如下所示:
Feature: Products Page
Scenario: Check the featured products
When we request the products page
Then we should receive
| productName | productSubtitle |
| Product A | Lorem ipsum |
| Product B | Dolar sit amet |
Scenario: Check product prices
When we request the products page
Then the product prices should be
| productName| discount | price |
| Product X | 5.50 | 5.95 |
| Product Y | 5.00 | 6.00 |
| Product Z | 6.00 | 7.50 |
我的步骤 .js 文件看起来像:
const { When, Then, After } = require('cucumber');
const assert = require('assert');
const { Builder, By, until } = require('selenium-webdriver');
When('we request the products page', async function () {
this.driver = new Builder()
.forBrowser('firefox')
.build();
this.driver.wait(until.elementLocated(By.tagName('h1')));
await this.driver.get('https://www.some-website.com/products');
});
Then('we should receive', async function (dataTable) {
var productElements = await this.driver.findElements(By.className('product-card--featured'));
var expectations = dataTable.hashes();
for (let i = 0; i < expectations.length; i++) {
const productName = await productElements[i].findElement(By.className('product__title')).getText();
assert.equal(productName, expectations[i].productName);
const productSubtitle = await productElements[i].findElement(By.className('product__subtitle')).getText();
assert.equal(productSubtitle, expectations[i].productSubtitle);
}
});
Then('the product prices should be', async function (dataTable) {
var productElements = await this.driver.findElements(By.className('product-card'));
var expectations = dataTable.hashes();
for (let i = 0; i < expectations.length; i++) {
const productName = await productElements[i].findElement(By.className('product__title')).getText();
assert.equal(productName, expectations[i].productName);
const discount = await productElements[i].findElement(By.css('.product-card__discount-price')).getText();
assert.equal(discount, expectations[i].discountRate);
const price = await productElements[i].findElement(By.css('.product-card__price')).getText();
assert.equal(price, expectations[i].compRate);
}
});
After(async function() {
this.driver.close();
});
如果我注释掉这些函数中的任何一个,测试就会起作用。Then
我知道我可以制作一个新的步骤文件并将其他测试粘贴到上面,但是肯定有办法将多个测试组合在一个文件上吗?
谁能为我指出一些资源的方向,告诉我如何做到这一点?
答: 暂无答案
评论