monocart-reporter 2.3.1 → 2.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -569,7 +569,8 @@ module.exports = {
569
569
  ```
570
570
 
571
571
  ## Metadata
572
- * add `metadata` to config
572
+ > All metadata will be listed in the report in a key/value format.
573
+ - Global level `metadata`
573
574
  ```js
574
575
  // playwright.config.js
575
576
  module.exports = {
@@ -591,19 +592,59 @@ module.exports = {
591
592
  ]
592
593
  };
593
594
  ```
594
- * collect metadata in global setup
595
+
596
+ - Project level `metadata`
597
+ ```js
598
+ // playwright.config.js
599
+ module.exports = {
600
+ projects: [
601
+ {
602
+ name: 'Desktop Chromium',
603
+ use: {
604
+ browserName: 'chromium'
605
+ },
606
+ metadata: {
607
+ projectData: 'project level metadata',
608
+ owner: 'PO',
609
+ link: 'https://github.com/cenfun/monocart-reporter'
610
+ }
611
+ }
612
+ ]
613
+ }
614
+ ```
615
+
616
+ - Collect metadata in [global setup or teardown](https://playwright.dev/docs/test-global-setup-teardown)
595
617
  ```js
596
618
  // ./common/global-setup.js
597
619
  import { chromium } from '@playwright/test';
598
620
  export default async (config) => {
599
621
  const metadata = config.metadata;
600
- // collect data and save to metadata
622
+ // collect data and save to global metadata
601
623
  const browser = await chromium.launch();
602
624
  const chromiumVersion = await browser.version();
603
625
  metadata.chromiumVersion = chromiumVersion;
604
626
  };
605
627
  ```
606
628
 
629
+ - Collect metadata in a test
630
+ > Playwright Test runs tests in [parallel](https://playwright.dev/docs/test-parallel) with isolate test data by default, so we need to utilize [global state management](#global-state-management) to collect metadata in a test.
631
+
632
+ - Enable global state, see [Setup Global State](#setup-global-state)
633
+ - Update global state in a test
634
+ ```js
635
+ const { test } = require('@playwright/test');
636
+ const { useState } = require('monocart-reporter');
637
+
638
+ const state = useState({
639
+ // port: 8130
640
+ });
641
+
642
+ test('test metadata url', async ({ page }) => {
643
+ const url = await page.evaluate(() => window.location.href);
644
+ await state.set('url', url);
645
+ });
646
+ ```
647
+
607
648
  ## Trend Chart
608
649
  > Note: The trend chart requires historical data generally stored in the server database. There is a serverless solution which is connecting and collecting historical trend data from previous report data before test every time.
609
650
  - If a report is generated in the same place every time, you can simply connect the data with the report JSON path (the data is not 100% safe if there is any runtime error, the previous output dir will be empty by Playwright but the reporter processing not finish)