Skip to content

Instantly share code, notes, and snippets.

@Ianfeather
Created October 15, 2024 13:00
Show Gist options
  • Save Ianfeather/f322dd68c22ca8395e1cb5c579801add to your computer and use it in GitHub Desktop.
Save Ianfeather/f322dd68c22ca8395e1cb5c579801add to your computer and use it in GitHub Desktop.
const { chromium} = require('playwright')
const { spawn } = require('child_process');
const user = "RigUI";
const key = "key";
const capabilities = {
'browserName': 'chrome',
'browserVersion': 'latest',
'LT:Options': {
'platform': 'Windows 10',
'build': 'Rig UI',
'name': 'Rig UI Test Suite',
user,
'accessKey': key,
'video': true,
'console': true,
'tunnel': true,
'network': true,
'network.har': true
}
}
async function startTunnelFromBinary() {
function waitForTunnelReady(ltProcess) {
return new Promise((resolve, reject) => {
ltProcess.stderr.on('data', (data) => {
console.error(`LT Error: ${data}`);
reject(data);
});
ltProcess.stdout.on('data', (data) => {
const output = data.toString();
console.log(`LT Output: ${output.trim()}`);
// Check if the expected string is in the output
if (output.includes('You can start testing now')) {
resolve();
}
});
});
}
process.on('uncaughtException', (error) => { // Handle any uncaught exceptions
console.error('Uncaught Exception:', error);
process.exit(1);
});
try {
// Replace with the path to binary
let tunnel = spawn('../LT', [
'--user', user,
'--key', key
]);
await waitForTunnelReady(tunnel, 'You can start testing now');
console.log('Tunnel is ready.');
global.__TUNNEL__ = tunnel;
} catch (e) {
console.error(e);
throw e;
}
}
const start = async () => {
await startTunnelFromBinary();
console.log("starting chromium")
try {
let browser = await chromium.connect(`wss://cdp.lambdatest.com/playwright?capabilities=${encodeURIComponent(JSON.stringify(capabilities))}`)
console.log('LambdaTest Tunnel started successfully');
}catch (e) {
console.error(e)
console.log('error setting it up')
}
};
start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment