Skip to content

Commit

Permalink
Replay generatedScript in chromium browser for mobile scans (#108)
Browse files Browse the repository at this point in the history
* Solution for replaying custom flow scan by replaying generatedScript in chromium browser
* Call a11yStorage clean-up function at end of test
  • Loading branch information
younglim authored Mar 18, 2023
1 parent c90755a commit 4210d2b
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions playwrightAxeGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const playwrightAxeGenerator = async (domain, randomToken, answers) => {
import { spawnSync } from 'child_process';
import safe from 'safe-regex';
import { consoleLogger, silentLogger } from './logs.js';
import { cleanUp } from './utils.js';
const blacklistedPatternsFilename = 'exclusions.txt';
process.env.CRAWLEE_STORAGE_DIR = constants.a11yStorage;
Expand Down Expand Up @@ -213,13 +213,14 @@ const runAxeScan = async page => {
const processPage = async page => {
if (blacklistedPatterns && isSkippedUrl(page, blacklistedPatterns)) {
return;
}
await page.waitForLoadState();
if (await checkIfScanRequired(page)) {
await runAxeScan(page);
if (blacklistedPatterns && isSkippedUrl(page, blacklistedPatterns)) {
return;
} else {
await runAxeScan(page);
}
};
};`

Expand All @@ -245,6 +246,7 @@ const processPage = async page => {
await createAndUpdateResultsFolders('${randomToken}');
createScreenshotsFolder('${randomToken}');
await generateArtifacts('${randomToken}', 'Automated Scan');
cleanUp(constants.a11yStorage);
});`;

let tmpDir;
Expand All @@ -254,7 +256,7 @@ const processPage = async page => {
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), appPrefix));

let codegenCmd = `npx playwright codegen --target javascript -o ${tmpDir}/intermediateScript.js ${domain}`
let extraCodegenOpts = `--block-service-workers --ignore-https-errors`
let extraCodegenOpts = `--browser chromium --block-service-workers --ignore-https-errors`

if (customDevice === 'iPhone 11' || deviceChosen === 'Mobile') {
execSync(
Expand Down Expand Up @@ -302,6 +304,10 @@ const processPage = async page => {
appendToGeneratedScript(`headless: true`);
continue;
}
if (line.trim() === `const browser = await webkit.launch({`) {
appendToGeneratedScript(`const browser = await chromium.launch({`);
continue;
}

if (line.trim().includes('getBy') || line.trim().includes('click()')) {
const lastIndex = line.lastIndexOf('.');
Expand Down

0 comments on commit 4210d2b

Please sign in to comment.