import { devices, defineConfig } from "@playwright/test";
/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
import dotenv from "dotenv";
import { defineBddConfig } from "playwright-bdd";
dotenv.config({
path: "./.env",
});
console.log("setting on env:"+ process.env.NODE_ENV);
dotenv.config({
path: `./.env.${process.env.NODE_ENV}`,
});
dotenv.config({
path: `./.env.${process.env.NODE_ENV}.local`,
});
console.log("public url is:", process.env.PUBLIC_URL);
const testDir = defineBddConfig({
paths: ["./features"],
importTestFrom: './steps/fixtures.ts',
require: ['./steps/*.ts'],
quotes: 'backtick' // when fixture filles are converted to spec.ts files, quotes will be replaced to the backticks
});
//
export default defineConfig({
testDir,
timeout: 60 * 1000,
expect: {
/**
* Maximum time expect() should wait for the condition to be met.
* For example in `await expect(locator).toHaveText();`
*/
timeout: 10000,
},
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
reporter: [["html", { outputFolder: "./reports" }]],
use: {
actionTimeout: 0,
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: process.env.PUBLIC_URL ?? 'http://my-dev.dimensional.com',
screenshot: 'only-on-failure',
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry",
testIdAttribute: "data-qa",
},
projects: [
{
name: "setup",
testMatch: /\/__[a-zA-Z0-9].[a-zA-Z0-9_-]+\.feature\.spec\.js$/,
},
{
name: "chromium",
use: {
...devices["Desktop Chrome"],
// Use prepared auth state.
storageState: ".auth/user.json",
},
testMatch: /\/[a-zA-Z0-9].[a-zA-Z0-9_-]+\.feature\.spec\.js$/,
dependencies: ["setup"],
},
],
/* Run your local dev server before starting the tests */
...((!process.env.CI || process.env.CI === 'false') && process.env.NODE_ENV === 'development' ? {
webServer: {
command: 'echo \"running dev server\";cd ../../src/cra;npm run start',
port: 3006,
reuseExistingServer: (!process.env.CI || process.env.CI === 'false')
},
}:
{}
)
});
export
@Fixture<typeof test>("smaBuildModal")
class SmaBuildModal extends Common {
@When("I add direct equity")
async addDirectEquity() {
await this.page.getByTestId("tab-item-strategyDesign-sma").click();
await this.page.locator(".direct-equity-on-sma-modal").first().click({timeout: 3000});
}
}
export
@Fixture<typeof test>("modelBuildModal")
class ModelBuildModal extends Common {
@When("I add direct equity")
async addDirectEquity() {
// different selectors from smaBuildModal
await this.page.getByTestId("tab-item-strategyDesign-model").click();
await this.page.locator(".direct-equity-on-model-modal").first().click({timeout: 3000});
}
}
@fixture:smaBuildModal
Feature: SMA strategy design
Scenario: Direct equity select and deselect
When I add direct equity
type Pages = {
smaBuildModal: SmaBuildModal;
modelBuildModal: ModelBuildModal;
};
export const test = base.extend<Pages>({
smaBuildModal: async ({ page }, use) => use(new SmaBuildModal(page)),
modelBuildModal:async ({ page }, use) => use(new ModelBuildModal(page)),
});
/** Generated from: features/sma-build/sma-create-new-sma/sma-direct-equity-only.feature */
import { test } from "../../../../steps/fixtures.ts";
test.describe(`SMA strategy design`, () => {
test.beforeEach(async ({ Given, smaBuildModal }) => {
await Given(`I am on new sma build modal`, null, { smaBuildModal });
});
test(`Direct equity select and deselect`, async ({ When, And, Then, smaBuildModal }) => {
await When(`I select "strategy design" tab`, null, { smaBuildModal });
await And(`I add direct equity`, null, { smaBuildModal });
> [email protected] watch:bdd
> nodemon -w ./features -w ./steps -w ./step-utils -e feature,js,ts --exec 'npx bddgen'
[nodemon] 3.0.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): features/**/* steps/**/* step-utils/**/*
[nodemon] watching extensions: feature,js,ts
[nodemon] starting `npx bddgen`
setting on env:development
public url is: http://localhost:3006
ERROR: Several step definitions found for text: I add direct equity (features/sma-build/funding-transition.feature)
- I add direct equity
- I add direct equity
[nodemon] app crashed - waiting for file changes before starting...