Skip to content
Snippets Groups Projects
Commit f4b9d8bc authored by Robert Long's avatar Robert Long
Browse files

Add --bots=<numbots> to spawn multiple bots

parent 54b6567c
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,7 @@ Options: ...@@ -7,6 +7,7 @@ Options:
-h --host=<host> Hubs host [default: localhost:8080] -h --host=<host> Hubs host [default: localhost:8080]
-r --room=<room> Room id [default: 234234]. -r --room=<room> Room id [default: 234234].
-h --help Show this screen. -h --help Show this screen.
-n --bots=<bots> Number of bots to connect [default: 1].
`; `;
const docopt = require("docopt").docopt; const docopt = require("docopt").docopt;
...@@ -15,18 +16,22 @@ const options = docopt(doc); ...@@ -15,18 +16,22 @@ const options = docopt(doc);
const puppeteer = require("puppeteer"); const puppeteer = require("puppeteer");
const querystring = require("query-string"); const querystring = require("query-string");
(async () => { async function spawnBot(id) {
const browser = await puppeteer.launch({ ignoreHTTPSErrors: true }); const browser = await puppeteer.launch({
headless: false,
ignoreHTTPSErrors: true,
args: ["--headless"]
});
const page = await browser.newPage(); const page = await browser.newPage();
page.on("console", msg => console.log("PAGE: ", msg.text())); page.on("console", msg => console.log(`PAGE ${id}: `, msg.text()));
page.on("error", err => console.error("ERROR: ", err)); page.on("error", err => console.error(`ERROR ${id}: `, err));
page.on("pageerror", err => console.error("PAGE ERROR: ", err)); page.on("pageerror", err => console.error(`PAGE ERROR: ${id}`, err));
const params = { const params = {
room: options["--room"], room: options["--room"],
bot: true bot: true,
name: `Bot ${id}`
}; };
console.log(params);
const url = `https://${options["--host"]}/hub.html?${querystring.stringify(params)}`; const url = `https://${options["--host"]}/hub.html?${querystring.stringify(params)}`;
const navigate = async () => { const navigate = async () => {
...@@ -47,6 +52,12 @@ const querystring = require("query-string"); ...@@ -47,6 +52,12 @@ const querystring = require("query-string");
} }
}; };
await navigate();
console.log("Spawning bot..."); console.log("Spawning bot...");
navigate(); }
(async function() {
for (let i = 0; i < options["--bots"]; i++) {
await spawnBot(i + 1);
}
})(); })();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment