Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated hyperexecute file to handle timeout error and run on different platforms #3309

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Hyperexecute
on:
workflow_dispatch:
inputs:
username:
required: true
description: LT Username
accessKey:
description: LT Access Key
required: true
sampleRepoLink:
description: Link to the HyperExecute sample repo
default: https://github.com/gauravchawhan/mathjs
required: true
jobs:
HyperExecute-Playwright:
runs-on: ${{ matrix.os }}
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
os: [windows-latest]
steps:
- name: Checkout sources
uses: actions/checkout@v2

- name: Starting CLI testing
shell: bash
run: |
echo "STEP 1 ) Downloading sample suite"
git clone https://github.com/gauravchawhan/mathjs
echo "STEP 2) Download CLI and setting environment variables"
cd mathjs
curl https://downloads.lambdatest.com/hyperexecute/windows/hyperexecute.exe -o hyperexecute.exe
export LT_USERNAME=${{ github.event.inputs.username }}
export LT_ACCESS_KEY=${{ github.event.inputs.accessKey }}
echo $LT_USERNAME
echo $LT_ACCESS_KEY
./hyperexecute --user $LT_USERNAME --key $LT_ACCESS_KEY --config hyperexecute.yaml --download-logs
npm install fs path readline
node printresults.cjs
22 changes: 22 additions & 0 deletions hyperexecute.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
version: 0.1
runson: ${matrix.os} # defines the OS to test on

concurrency: 1 # number of machines to execute the testcases

matrix:
os: [win, win11, linux] #runnning unit tests on different platforms

# pre steps sets up the environment for testing
pre:
- npm install
- npm install -g karma karma-jasmine karma-safari-launcher karma-webdriver-launcher karma-mocha karma-webpack mocha


# Smart cache
cacheKey: '{{ checksum "package-lock.json" }}'
cacheDirectories:
- node_modules

testSuites:
- karma start test/browser-test-config/lt_karma.js # executing runner command
59 changes: 59 additions & 0 deletions printresults.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const fs = require('fs');
const readline = require('readline');
const path = require('path');

// Define the YAML file and log file template
const yamlFile = '.updatedhyperexecute.yaml';
const logFileTemplate = 'logs/{jobID}/scenarios/karma start test-browser-test-config-lt_karma.js';

// Function to extract jobID from YAML
function getJobIdFromYaml(file) {
const content = fs.readFileSync(file, 'utf8');
const match = content.match(/jobID:\s*([^\s]+)/);
return match ? match[1] : null;
}

// Function to read last 50 lines of a file and filter for "TOTAL"
function tailAndFilter(filePath, keyword) {
const lines = [];
const rl = readline.createInterface({
input: fs.createReadStream(filePath, { encoding: 'utf8' }),
output: process.stdout,
terminal: false
});

rl.on('line', (line) => {
lines.push(line);
if (lines.length > 50) lines.shift();
});

rl.on('close', () => {
const filteredLines = lines.filter(line => line.includes(keyword));
filteredLines.forEach(line => console.log(line));
});
}

// Main function
async function main() {
const jobId = getJobIdFromYaml(yamlFile);
if (!jobId) {
console.error("Error: jobID not found in the YAML file.");
return;
}

// Construct log file path and ensure compatibility with different platforms
const logFilePath = path.join(...logFileTemplate.replace('{jobID}', jobId).split('/'));

// Check if the log file exists
if (!fs.existsSync(logFilePath)) {
console.error(`Error: Log file not found at path ${logFilePath}`);
return;
}

console.log("///////////////////////////")
// Retrieve the last 50 lines containing the keyword "TOTAL"
await tailAndFilter(logFilePath, "TOTAL");
}

// Run the main function
main();
70 changes: 70 additions & 0 deletions test/browser-test-config/lt_karma.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
var fs = require('fs');

Check warning on line 1 in test/browser-test-config/lt_karma.js

View workflow job for this annotation

GitHub Actions / build-and-test

Unexpected var, use let or const instead

Check failure on line 1 in test/browser-test-config/lt_karma.js

View workflow job for this annotation

GitHub Actions / build-and-test

'fs' is assigned a value but never used

Check failure on line 1 in test/browser-test-config/lt_karma.js

View workflow job for this annotation

GitHub Actions / build-and-test

Extra semicolon

Check warning on line 1 in test/browser-test-config/lt_karma.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected var, use let or const instead

Check failure on line 1 in test/browser-test-config/lt_karma.js

View workflow job for this annotation

GitHub Actions / lint

'fs' is assigned a value but never used

Check failure on line 1 in test/browser-test-config/lt_karma.js

View workflow job for this annotation

GitHub Actions / lint

Extra semicolon
const baseKarma = require('./base-karma')
const mochaConfig = require('../../.mocharc.json')
const webpack = require('webpack')

Check failure on line 4 in test/browser-test-config/lt_karma.js

View workflow job for this annotation

GitHub Actions / build-and-test

'webpack' is assigned a value but never used

Check failure on line 4 in test/browser-test-config/lt_karma.js

View workflow job for this annotation

GitHub Actions / lint

'webpack' is assigned a value but never used


Check failure on line 6 in test/browser-test-config/lt_karma.js

View workflow job for this annotation

GitHub Actions / build-and-test

More than 1 blank line not allowed

Check failure on line 6 in test/browser-test-config/lt_karma.js

View workflow job for this annotation

GitHub Actions / lint

More than 1 blank line not allowed
module.exports = function(config) {

Check failure on line 7 in test/browser-test-config/lt_karma.js

View workflow job for this annotation

GitHub Actions / build-and-test

Missing space before function parentheses

Check failure on line 7 in test/browser-test-config/lt_karma.js

View workflow job for this annotation

GitHub Actions / lint

Missing space before function parentheses
var webdriverConfig = {

Check warning on line 8 in test/browser-test-config/lt_karma.js

View workflow job for this annotation

GitHub Actions / build-and-test

Unexpected var, use let or const instead

Check warning on line 8 in test/browser-test-config/lt_karma.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected var, use let or const instead
hostname: 'hub.lambdatest.com', //lambdatest hub address

Check failure on line 9 in test/browser-test-config/lt_karma.js

View workflow job for this annotation

GitHub Actions / build-and-test

Expected indentation of 4 spaces but found 6

Check failure on line 9 in test/browser-test-config/lt_karma.js

View workflow job for this annotation

GitHub Actions / build-and-test

Expected space or tab after '//' in comment

Check failure on line 9 in test/browser-test-config/lt_karma.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 4 spaces but found 6

Check failure on line 9 in test/browser-test-config/lt_karma.js

View workflow job for this annotation

GitHub Actions / lint

Expected space or tab after '//' in comment
port: 80

Check failure on line 10 in test/browser-test-config/lt_karma.js

View workflow job for this annotation

GitHub Actions / build-and-test

Expected indentation of 4 spaces but found 6

Check failure on line 10 in test/browser-test-config/lt_karma.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 4 spaces but found 6
}

const baseConfig = baseKarma(config)

config.set(Object.assign(baseConfig, {
hostname: '127.0.0.1', // hostname, where karma web server will run

Check failure on line 16 in test/browser-test-config/lt_karma.js

View workflow job for this annotation

GitHub Actions / build-and-test

Expected indentation of 4 spaces but found 6

Check failure on line 16 in test/browser-test-config/lt_karma.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 4 spaces but found 6
port: 9876,

Check failure on line 17 in test/browser-test-config/lt_karma.js

View workflow job for this annotation

GitHub Actions / build-and-test

Expected indentation of 4 spaces but found 6

Check failure on line 17 in test/browser-test-config/lt_karma.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 4 spaces but found 6
basePath: '../..',
frameworks: ['mocha'],


client: {
mocha: {
timeout: mochaConfig.timeout
}
},
files: [
'test/browser-test-config/browser-tests.test.js'
],

plugins: [

'karma-webpack',
'karma-mocha',

'karma-webdriver-launcher',

],

captureTimeout: 600000,
retryLimit: 1,
browserDisconnectTimeout: 90000,
browserDisconnectTolerance: 1,
browserNoActivityTimeout: 90000,

concurrency: 1,
logLevel: config.LOG_DEBUG,
browsers: ['Windows_Chrome'],
customLaunchers: {
'Windows_Chrome': {
base: 'WebDriver',
config: webdriverConfig,
browserName: 'chrome',
version: 'latest',
build: 'OSS',
name: 'Jos MathJs',
video: true, // capture video for your test
visual: true, // capture screenshots on each step
network: true, // capture network logs for your test
console: true, // capture browser console logs
terminal: true,
user: process.env.LT_USERNAME,
accessKey: process.env.LT_ACCESS_KEY,
pseudoActivityInterval: 15000 // 5000 ms heartbeat
}
},
singleRun: true,
autoWatch: true
}));
};