実現したいこと
仕事で利用する必要のある下記スクリプトをWindows 10 端末のNode.jsで実行し、ウェブアクセシビリティチェックを実施すること
※本日投稿させていただいたこちらの質問にてエラーが解決したことにより、新たに判明した問題に関する内容です。
※参考サイト: GitHub 「axe-test.js」
前提
基礎知識の全くない状態にも関わらず業務でNode.jsを利用し特定のスクリプトを実行することを求められている状況なので、見当違いな内容を記載している可能性がありますが、ご容赦ください。
上記サイトの手順書を頼りに事前設定・スクリプトの実行を行ったところ、本来CSVファイルに書き出されるはずの結果がターミナル上にのみ表示され、肝心のCSVファイルが出力されない状況です。
あまり時間がないため、もし解決方法をご存じの方がいらっしゃいましたら、できるだけ早くご教示いただければ幸いです。
発生している問題・エラーメッセージ
エラーメッセージは出力されておらず、下記の通り本来CSVファイルに転記されるはずの結果がターミナル上に表示されている状況です。
URL,Volation Type,Impact,Help,HTML Element,Messages,DOM Element https://www.xxx.co.jp/,color-contrast,serious,https://dequeuniversity.com/rules/axe/4.9/color-contrast?appl ication=axe-puppeteer&lang=ja,<span class="category info">お知らせ</span>,要素のコントラスト比が不十分です 3.91(前景色: #009606、背景色: #ffffff、フォントサイズ: 10.5pt (14px)、フォントの太さ: normal)。コントラスト比4.5:1を必要とします,li :nth-child(1) > p:nth-child(1) > .info.category https://www.xxx.co.jp/,color-contrast,serious,https://dequeuniversity.com/rules/axe/4.9/color-contrast?appl ication=axe-puppeteer&lang=ja,<span class="category info">お知らせ</span>,要素のコントラスト比が不十分です 3.91(前景色: #009606、背景色: #ffffff、フォントサイズ: 10.5pt (14px)、フォントの太さ: normal)。コントラスト比4.5:1を必要とします,li :nth-child(5) > p:nth-child(1) > .info.category https://www.xxx.co.jp/,color-contrast,serious,https://dequeuniversity.com/rules/axe/4.9/color-contrast?appl ication=axe-puppeteer&lang=ja,<span class="category info">お知らせ</span>,要素のコントラスト比が不十分です 3.91(前景色: #009606、背景色: #ffffff、フォントサイズ: 10.5pt (14px)、フォントの太さ: normal)。コントラスト比4.5:1を必要とします,li :nth-child(6) > p:nth-child(1) > .info.category https://www.xxx.co.jp/,color-contrast,serious,https://dequeuniversity.com/rules/axe/4.9/color-contrast?appl ication=axe-puppeteer&lang=ja,<span class="category info">お知らせ</span>,要素のコントラスト比が不十分です 3.91(前景色: #009606、背景色: #ffffff、フォントサイズ: 10.5pt (14px)、フォントの太さ: normal)。コントラスト比4.5:1を必要とします,li :nth-child(7) > p:nth-child(1) > .info.category https://www.xxx.co.jp/,color-contrast,serious,https://dequeuniversity.com/rules/axe/4.9/color-contrast?appl ication=axe-puppeteer&lang=ja,<p>MASAYUKI OKUMOTO</p>,要素のコントラスト比が不十分です 1.24(前景色: #e6e6e6、背景色: #f fffff、フォントサイズ: 27.0pt (36px)、フォントの太さ: bold)。コントラスト比3:1を必要とします,.toppage_message_right_nam e > p:nth-child(2) https://www.xxx.co.jp/,page-has-heading-one,moderate,https://dequeuniversity.com/rules/axe/4.9/page-has-hea ding-one?application=axe-puppeteer&lang=ja,<html lang="ja" itemscope="" itemtype="http://schema.org/WebPage">,,html
該当のソースコード
○ダウンロードした「axe-test.js」
※必要となるPuppeteer、axe-core、axe-reportsは参考サイトの手順通りにインストール済みです。
JavaScript
1const { AxePuppeteer } = require('@axe-core/puppeteer'); 2const puppeteer = require('puppeteer'); 3 4// テスト結果を日本語で出力するように設定する。 5const AXE_LOCALE_JA = require('axe-core/locales/ja.json'); 6const config = { 7 locale: AXE_LOCALE_JA 8} 9 10// テスト結果の出力に、axe-reports を使用するように設定する。 11const AxeReports = require('axe-reports'); 12 13// テスト対象の URL を、外部テキストファイルから読み込んで、配列に整形する。 14const fs = require('fs'); 15let urls_list = fs.readFileSync("./urls.txt", "utf-8"); 16urls_list = urls_list.replace(/\r?\n/g, ','); 17urls_list = urls_list.split(','); 18 19(async () => { 20 21 const urls = urls_list 22 23 // axe-reports で、見出し行をまずは作成する。 24 AxeReports.createCsvReportHeaderRow(); 25 26 const browser = await puppeteer.launch(); 27 28 for (let i = 0; i < urls.length; i++) { 29 30 const url = urls[i]; 31 const page = await browser.newPage(); 32 await page.setBypassCSP(true); 33 34 // デバイスのエミュレートをする場合は、下記を適用する。 35 // await page.emulate(puppeteer.devices['iPhone 8']); 36 37 // ページを読み込む。 38 await Promise.all([ 39 page.setDefaultNavigationTimeout(0), 40 page.waitForNavigation({waitUntil: ['load', 'networkidle2']}), 41 page.goto(`${url}`) 42 ]); 43 44 // テストを実行する。withTags で、テスト基準をいろいろ設定できる。 45 const results = await new AxePuppeteer(page).configure(config).withTags(['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa', 'best-practice']).analyze(); 46 47 // axe-reports で、検証結果の行を追加する。 48 AxeReports.createCsvReportRow(results); 49 50 await page.close(); 51 } 52 53 await browser.close(); 54 55})();
○スクリプトの実行コマンド
node axe-test.js => result.csv
試したこと
お恥ずかしながら基礎知識が殆どないため、「ウェブ検索をしてCSVへの書き出しにFSパッケージが使われることを知って追加インストールした」という対処しかできていません。
以上です。
よろしくお願いいたします。
補足情報
Node.jsのバージョンは20.16.0を使用しています。
回答1件
あなたの回答
tips
プレビュー
2024/08/06 10:39