diff --git a/src/session.js b/src/session.js index e1d0daf7fe..80e3225f1f 100644 --- a/src/session.js +++ b/src/session.js @@ -35,13 +35,18 @@ module.exports = class RiotSession { this.log = new Logger(this.username); } - static async create(username, puppeteerOptions, riotserver, hsUrl) { + static async create(username, puppeteerOptions, riotserver, hsUrl, throttleCpuFactor = 1) { const browser = await puppeteer.launch(puppeteerOptions); const page = await browser.newPage(); await page.setViewport({ width: 1280, height: 800 }); + if (throttleCpuFactor !== 1) { + const client = await page.target().createCDPSession(); + console.log("throttling cpu by a factor of", throttleCpuFactor); + await client.send('Emulation.setCPUThrottlingRate', { rate: throttleCpuFactor }); + } return new RiotSession(browser, page, username, riotserver, hsUrl); } diff --git a/start.js b/start.js index 43988095f9..b98dc7f366 100644 --- a/start.js +++ b/start.js @@ -25,8 +25,9 @@ program .option('--no-logs', "don't output logs, document html on error", false) .option('--riot-url [url]', "riot url to test", "http://localhost:5000") .option('--windowed', "dont run tests headless", false) - .option('--slow-mo', "run tests slower to follow whats going on", false) + .option('--slow-mo', "type at a human speed", false) .option('--dev-tools', "open chrome devtools in browser window", false) + .option('--throttle-cpu [factor]', "factor to slow down the cpu with", parseFloat, 1.0) .option('--no-sandbox', "same as puppeteer arg", false) .option('--log-directory ', 'a directory to dump html and network logs in when the tests fail') .parse(process.argv); @@ -57,7 +58,7 @@ async function runTests() { ); async function createSession(username) { - const session = await RiotSession.create(username, options, program.riotUrl, hsUrl); + const session = await RiotSession.create(username, options, program.riotUrl, hsUrl, program.throttleCpu); sessions.push(session); return session; }