Skip to content

Commit

Permalink
adding node script
Browse files Browse the repository at this point in the history
  • Loading branch information
mayarajan3 committed Jun 17, 2024
1 parent d70573c commit 49140d7
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 6 deletions.
84 changes: 84 additions & 0 deletions extensions/integration_testing/node_script.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
const { exec } = require('child_process');

let devProcess: any;

async function runDevScript(param: string): Promise<void> {
return new Promise((resolve, reject) => {
devProcess = exec(`cd ../.. && pnpm dev -i ${param}`, (error: any, stdout: any, stderr: any) => {
if (error) {
console.error(`Error running dev script: ${error}`);
reject(error);
} else {
console.log(`Dev script output: ${stdout}`);
resolve();
}
});

devProcess.stdout.on('data', (data: any) => {
console.log(`stdout: ${data}`);
});

devProcess.stderr.on('data', (data: any) => {
console.error(`stderr: ${data}`);
});
});
}

async function runPlaywrightScript(scriptName: string) {
return new Promise((resolve, reject) => {
const command = `npx ts-node ${scriptName}`;
const playwrightProcess = exec(command, (error: any, stdout: any, stderr: any) => {
if (error) {
console.error(`Error running script: ${error.message}`);
reject(error);
}
if (stderr) {
console.error(`Error output: ${stderr}`);
reject(stderr);
}
console.log(`Script output: ${stdout}`);
resolve(stdout);
});

playwrightProcess.stdout.on('data', (data: any) => {
console.log(`stdout: ${data}`);
});

playwrightProcess.stderr.on('data', (data: any) => {
console.error(`stderr: ${data}`);
});
});
}


async function runPlaywrightTasks() {
try {
await runPlaywrightScript('playwright_save_all.ts');
await runPlaywrightScript('playwright_save_combo.ts');
await runPlaywrightScript('playwright_load.ts');
devProcess.kill();
} catch (error) {
console.error('Error during Playwright tasks:', error);
}
}

async function main() {
const args = process.argv.slice(2);

if (args.length === 0) {
console.error('Please provide a parameter.');
return;
}

const param = args[0];

try {
runDevScript(param);
console.log('Dev script started successfully');
runPlaywrightTasks();
} catch (error) {
console.error('Error running script:', error);
}
}

main();
21 changes: 19 additions & 2 deletions extensions/integration_testing/playwright_load.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { chromium, Browser, BrowserContext, Page, ElementHandle } from 'playwright';
import * as path from 'path';

const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));

(async () => {
// Launch a browser instance
const browser = await chromium.launch({ headless: false }); // Set headless: false to see the browser actions
Expand All @@ -11,6 +13,19 @@ import * as path from 'path';
const page = await context.newPage();

// Navigate to 'Create' page

// Try connecting to the server in a loop with delay
// let connected = false;
// for (let i = 0; i < 120; i++) { // Retry up to 10 times
// try {
// await page.goto('http://localhost:8602/', { waitUntil: 'networkidle', timeout: 6000 });
// connected = true;
// break;
// } catch (e) {
// console.log('Connection failed, retrying...');
// await delay(5000); // Wait for 5 seconds before retrying
// }
// }
await page.goto('http://localhost:8602/');
await page.click('text=File');

Expand Down Expand Up @@ -51,15 +66,17 @@ import * as path from 'path';
}
});

await page.waitForSelector('.blocklyBlockCanvas');
//await page.waitForSelector('.blocklyBlockCanvas', { timeout: 120000 });
await page.waitForTimeout(2000);
await page.click('text=File');
const [fileChooser2] = await Promise.all([
page.waitForEvent('filechooser'),
page.click('text=Load from your computer'),
]);

await fileChooser2.setFiles(filePath);
await page.waitForSelector('.blocklyBlockCanvas');
//await page.waitForSelector('.blocklyBlockCanvas', { timeout: 120000 });
await page.waitForTimeout(2000);


// Wait until blockly canvas has children
Expand Down
18 changes: 15 additions & 3 deletions extensions/integration_testing/playwright_save_all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { chromium } from 'playwright';
import { expect } from 'playwright/test';
import * as path from 'path';

const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));

(async () => {
// Launch a browser instance
const browser = await chromium.launch({ headless: false }); // Set headless: false to see the browser actions
Expand All @@ -10,7 +12,17 @@ import * as path from 'path';
acceptDownloads: true
});
const page = await context.newPage();
await page.goto('http://localhost:8602/');
let connected = false;
for (let i = 0; i < 120; i++) { // Retry up to 10 times
try {
await page.goto('http://localhost:8602/', { waitUntil: 'networkidle', timeout: 6000 });
connected = true;
break;
} catch (e) {
console.log('Connection failed, retrying...');
await delay(5000); // Wait for 5 seconds before retrying
}
}

// All the extensions that have been included
const includedExtensions = [
Expand All @@ -35,8 +47,8 @@ import * as path from 'path';
const startY = 130;

// Wait for the editor to load
await page.waitForSelector('.blocklyWorkspace');

//await page.waitForSelector('.blocklyBlockCanvas');
await page.waitForTimeout(2000);
// Add the extension
const addExtension = await page.$('[title="Add Extension"]');
if (addExtension) {
Expand Down
3 changes: 2 additions & 1 deletion extensions/integration_testing/playwright_save_combo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import * as path from 'path';
];


await page.waitForSelector('.blocklyWorkspace');
//await page.waitForSelector('.blocklyWorkspace');
await page.waitForTimeout(2000);

// Make sure no blocks are dragged out of the workspace
function boundY(y: any) {
Expand Down

0 comments on commit 49140d7

Please sign in to comment.