我放弃了依赖playwright-core
playwright-video
项 playwright
但仍然无法在仪表板中看到视频。
我也contextOptions
按照你说的删除了。
更新了 package.json
{
"devDependencies": {
"@playwright/test": "^1.22.0",
"allure-commandline": "^2.17.2",
"allure-playwright": "^2.0.0-beta.1"
},
"scripts": {
"allure:generate": "npx allure generate ./allure-results --clean",
"allure:open": "npx allure open ./allure-report",
"allure:serve": "npx allure serve",
"test": "npx playwright test || :",
"posttest": "npm run allure:generate"
}
}
我的测试如下:
const { test,Page, expect } = require('@playwright/test');
test.describe("Trader Test", () => {
let page = Page;
//Setting the browser context and initializing page
test.beforeAll(async ( { browser } ) => {
const context = await browser.newContext();
page = await context.newPage();
})
//Test to Connect to the login page
test('Connect to login page', async() => {
await page.goto("http://localhost:3000/trader-desktop/login");
await expect(page.locator('#login-container > div:nth-child(1) > span')).toHaveText('Welcome to Ninja App !');
});
//Token Authentication using local Storage
test('Token Authentication', async() => {
const fs = require('fs');
const localStorage = fs.readFileSync('../localStorage.json', 'utf8');
const deserializedStorage = JSON.parse(localStorage);
await page.evaluate(deserializedStorage => {
for (const key in deserializedStorage) {
if (key === "realms") {
localStorage.setItem(key, JSON.stringify(deserializedStorage[key]));
}
else {
localStorage.setItem(key, deserializedStorage[key]);
}
}
}, deserializedStorage);
await page.goto("http://localhost:3000/trader-desktop/account-selection");
await expect(page.locator('//*[@id="root"]/div[2]/div[1]/div[2]/div/span')).toHaveText('Login Successful, Select a Business to Begin...');
});
//Clicking on Suriya Traders
test('Navigate to Suriya Traders', async() => {
await page.click("text = Suriya traders");
await expect(page.locator('//*[@id="root"]/div[2]/div/div[2]/div[1]/div/div/button[1]')).toHaveText('Add Party');
});
//Clicking on Transactions
test('Navigate to Transactions page', async() => {
await page.click("text = Transactions");
await expect(page.locator('//*[@id="root"]/div[2]/div/div[1]/div/span')).toHaveText('Transactions');
})
//Returning to Dashboard
test('Navigate to Dashboard', async() => {
await page.click("text = Dashboard");
await expect(page.locator('//*[@id="root"]/div[2]/div/div[2]/div[3]/div/div/span')).toContainText('Cash Flow Summary');
})
//Clicking on Logout
test('Logout', async() => {
await page.click('text = Logout');
await expect(page.locator('#login-container > div:nth-child(1) > span')).toHaveText('Welcome!');
})
//Negative Authentication test
test('Failed login', async() => {
var inputBoxes = 6;
await page.locator('input:visible').fill('843534534');
await page.click("text = Get OTP");
//Fill input boxes with '0'
for (var i = 0; i < inputBoxes; i++) {
await page.locator('[aria-label="Digit 6"]').fill('0');
}
await page.click("text = Login");
await expect(page.locator('text = Request failed with status code 400')).not.toHaveText('Request failed with status code 400');
})
})
我的 playwright.config.js
/** @type {import('@playwright/test').PlaywrightTestConfig} */
const config = {
use : {
actionTimeout: 0,
launchOptions: {
devtools: false
},
testDir: './tests',
testMatch: /traderTest.js/,
headless: false,
viewport: { width: 1280, height: 1080 },
channel: "chrome",
screenshot: "on",
video: {
mode: "on",
size: {
width: "1260",
height: 1080
}
},
trace: "on"
},
reporter: [["list"], ["json", { outputFile: "test-results.json"}] ,['allure-playwright']],
projects: [
{
name: 'Trader',
testMatch: /.*traderTest.js/,
retries: 0,
}
]
};
module.exports = config;