Hello!
Laravel App
My project idea is to create a Laravel app for in-house use, so the scripts I would store in the database are going to be created by myself.
The main goal would be to test some websites frontends through browser automation checks, e.g.
- open example.com
- click first item
- add to cart
- check we are on checkout page
- take screenshot
For this browser checks I'll be using puppeteer and it runs on Node. So all the scripts that are in charge of testing the browser are going to be saved to the database on the Laravel app.
Then my idea is to create a small Node API that will accept the script, execute and return if some failure or success.
An example of stored Node script for testing using puppeteer would be:
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await page.screenshot({ path: 'example.png' });
await browser.close();
})();
Node API
My whole issues are in the Node part, I was already searching and found that the API is easy to mount using Express. At this moment I have the API created and ready to receive a POST request with the script.
But the difficulties are in how to transform or run the script (string) that is received once in the API. I was searching and found that it can be done using a Node child_process.
Further investigation points me to use child_process.fork(modulePath) where modulePath is a string, so I can pass the script stored in the DB and sent through the API.