スキャン結果をローカルに保存

This page is not available in the language you requested. You have been redirected to the English version of the page.
Link to this page copied to clipboard
Not for use with personal data

スキャン結果をローカルに保存すると、JSON結果を使用して、さまざまなレポートツールにアクセシビリティメトリクスを統合できます。また、HTMLレポートを作成して、メールやチャットを通じて共有し、テスト実行のアクセシビリティ状況をチームに通知することもできます。

結果をローカルに保存することは、*自動テスト*の自動テスト内で重要です。

結果の保存と共有

ホームディレクトリに「reports」ディレクトリを作成し、そこにJSON結果を保存します。以下の例を参照してください。

Ruby

require 'json'
require 'fileutils'

#
# Set up driver and capabilities here before scanning
#

# Start Scan Here
axeSettings = { apiKey: '<your-api-key-here>' }
scanResult = @driver.execute_script 'mobile: axeScan', axeSettings

# Convert result to JSON string
json_result = JSON.pretty_generate(scanResult)

# Create timestamp for filename
timestamp = Time.now.strftime('%Y-%m-%dT%H-%M-%S')
filename = "axe-scan-result-#{timestamp}.json"

# Create reports directory
reports_dir = File.join(Dir.home, 'reports', 'axeScans')
FileUtils.mkdir_p(reports_dir)

# Save to file
filepath = File.join(reports_dir, filename)
File.write(filepath, json_result)

puts "Axe scan result saved to: #{filepath}"

JavaScript

const fs = require('fs');
const path = require('path');

//
// Set up driver and capabilities here before scanning
//

// Start axeScan
const axeSettings = { apiKey: '<your-api-key-here>' }
const scanResult = await driver.execute('mobile:axeScan', axeSettings)

// Convert result to JSON string
const jsonResult = JSON.stringify(scanResult, null, 2);

// Create timestamp for filename
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
const filename = `axe-scan-result-${timestamp}.json`;

// Create reports directory
const reportsDir = path.join(require('os').homedir(), 'reports', 'axeScans');
fs.mkdirSync(reportsDir, { recursive: true });

// Save to file
const filepath = path.join(reportsDir, filename);
fs.writeFileSync(filepath, jsonResult, 'utf8');

console.log(`Axe scan result saved to: ${filepath}`);

Python

import json
from datetime import datetime
from pathlib import Path

#
# Set up driver and capabilities here before scanning
#

# Start axeScan
axeSettings = { 'apiKey': '<your-api-key-here>' }
scan_result = driver.execute_script('mobile: axeScan', axeSettings)

# Convert result to JSON string
json_result = json.dumps(scan_result, indent=2)

# Create timestamp for filename
timestamp = datetime.now().strftime('%Y-%m-%dT%H-%M-%S')
filename = f"axe-scan-result-{timestamp}.json"

# Create reports directory
reports_dir = Path.home() / 'reports' / 'axeScans'
reports_dir.mkdir(parents=True, exist_ok=True)

# Save to file
filepath = reports_dir / filename
filepath.write_text(json_result, encoding='utf-8')

print(f"Axe scan result saved to: {filepath}")

Java

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Map;

//
// Set up driver and capabilities here before scanning
//

// Start axeScan
Map<String, String> axeSettings = Map.of("apiKey", "<your-api-key-here>");
Object scanResult = driver.executeScript("mobile: axeScan", axeSettings);

// Convert result to JSON string
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String jsonResult = gson.toJson(scanResult);

// Create timestamp for filename
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH-mm-ss");
String timestamp = LocalDateTime.now().format(formatter);
String filename = "axe-scan-result-" + timestamp + ".json";

// Create reports directory
Path reportsDir = Paths.get(System.getProperty("user.home"), "reports", "axeScans");
Files.createDirectories(reportsDir);

// Save to file
Path filepath = reportsDir.resolve(filename);
Files.write(filepath, jsonResult.getBytes());

System.out.println("Axe scan result saved to: " + filepath.toString());

Kotlin

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import java.nio.file.Files
import java.nio.file.Paths
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

//
// Set up driver and capabilities here before scanning
//

// Start axeScan
val axeSettings = mapOf("apiKey" to "<your-api-key-here>")
val scanResult = driver.executeScript("mobile: axeScan", axeSettings)

// Convert result to JSON string
val gson = GsonBuilder().setPrettyPrinting().create()
val jsonResult = gson.toJson(scanResult)

// Create timestamp for filename
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH-mm-ss")
val timestamp = LocalDateTime.now().format(formatter)
val filename = "axe-scan-result-$timestamp.json"

// Create reports directory
val reportsDir = Paths.get(System.getProperty("user.home"), "reports", "axeScans")
Files.createDirectories(reportsDir)

// Save to file
val filepath = reportsDir.resolve(filename)
Files.write(filepath, jsonResult.toByteArray())

println("Axe scan result saved to: $filepath")

C#

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;

//
// Set up driver and capabilities here before scanning
//

// Start axeScan
var axeSettings = new Dictionary<string, object> { { "apiKey", "<your-api-key-here>" } };
var scanResult = _driver.ExecuteScript("mobile: axeScan", axeSettings);

// Convert result to JSON string
string jsonResult = JsonConvert.SerializeObject(scanResult, Formatting.Indented);

// Create timestamp for filename
string timestamp = DateTime.Now.ToString("yyyy-MM-ddTHH-mm-ss");
string filename = $"axe-scan-result-{timestamp}.json";

// Create reports directory
string reportsDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), 
                                "reports", "axeScans");
Directory.CreateDirectory(reportsDir);

// Save to file
string filepath = Path.Combine(reportsDir, filename);
File.WriteAllText(filepath, jsonResult);

Console.WriteLine($"Axe scan result saved to: {filepath}");

HTMLレポートとサマリーの生成

ターゲットスキャンのためにmobile: axeGenerateHtmlReportAndSummaryを使用してHTMLレポートを生成します。この実行コマンドを追加すると、セッション開始以来収集されたすべてのスキャンの単一集約HTMLレポートと要約を生成し、ドライバーがデバイスからそれをローカルディレクトリに引き出します - axeHtmlReportPath 。デフォルトのディレクトリは、Androidではbuild/AxeDevToolsMobileResults、iOSでは~/AxeDevToolsMobileResults/<UUID>ですが、必要に応じてカスタムの出力パスを定義できます(例: ./reports/accessibility)。デフォルトのレポートファイル名はAxeAccessibilityReportですが、これも変更可能です。次のJavaScriptスニペットの三番目のブロックを参照してください。

// 1. Authenticate once for the session
await driver.executeScript('mobile: axeStartSession', [{
  apiKey: 'your-api-key',
  axeAccountURL: 'https://axe.deque.com',
}]);

// 2. Run targeted scans across the screens you care about
await driver.executeScript('mobile: axeScan', [{ scanName: 'Login screen' }]);
// ...navigate...
await driver.executeScript('mobile: axeScan', [{ scanName: 'Checkout screen' }]);

// 3. Generate a single aggregated HTML report + summary for the session
const result = await driver.executeScript('mobile: axeGenerateHtmlReportAndSummary', [{
  axeHtmlReportPath: './reports/accessibility', // optional (local dir)
  scanName: 'My Session Report',                // optional
}]);

// result.localDirectory -> local directory the report was saved into
// result.reportFiles    -> generated report file path(s) on the device

他のプログラミング言語でのaxeGenerateHtmlReportAndSummaryの実装を見るには、UIAutomator2とXCUITestの両方のために完全自動化例を参照できます。