From 70eed430ac7eb8947d7c1036d58889688c9ea0e3 Mon Sep 17 00:00:00 2001 From: Dani Tseitlin Date: Fri, 27 Sep 2024 14:48:27 +0300 Subject: [PATCH 01/30] Fixing issues with intergration tests not working --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fb106d3..77882b2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,7 +44,7 @@ jobs: - name: Docker version run: docker -v - name: Setting up a local Report Portal environment - run: sudo docker-compose -f docker-compose.yml -p reportportal up -d --force-recreate + run: sudo docker compose -f docker-compose.yml -p reportportal up -d --force-recreate - name: Waiting for services to be up run: ./scripts/healthcheck.bash - name: Report Portal server status From c798debec25b5ffe2e121cba3b42a820c08f46b0 Mon Sep 17 00:00:00 2001 From: Dani Tseitlin Date: Fri, 27 Sep 2024 16:10:56 +0300 Subject: [PATCH 02/30] . --- .github/workflows/ci.yml | 2 +- package.json | 1 + tests/integration/integration.executor.ts | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 77882b2..bd48393 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,7 +40,7 @@ jobs: - name: Setting a Report Portal local reporter run: npm run build && npm run link-pkg - name: Downloading docker compose file - run: npm run download-report-portal-latest-docker-compose-file + run: npm run download-report-portal-docker-compose-file - name: Docker version run: docker -v - name: Setting up a local Report Portal environment diff --git a/package.json b/package.json index 1e7de34..0f4c504 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "run-full-unit-tests": "npm run build-local-reporter && npm run unit-tests && npm run unit-retry-tests && npm run unit-no-live-reporting-tests && npm run unit-display-debug-logs-tests", "integration-tests": "npm run test ./tests/integration/integration.executor.ts -- --display-debug-logs", "run-integration-tests": "npm run build-local-reporter && npm run integration-tests", + "download-report-portal-docker-compose-file": "curl https://raw.githubusercontent.com/reportportal/reportportal/52ab9fa5613970bf426ce3f8236e22dfe95e92a6/docker-compose.yml -o docker-compose.yml", "download-report-portal-latest-docker-compose-file": "curl https://raw.githubusercontent.com/reportportal/reportportal/master/docker-compose.yml -o docker-compose.yml", "up": "docker compose -p reportportal up", "start": "docker compose -p reportportal start", diff --git a/tests/integration/integration.executor.ts b/tests/integration/integration.executor.ts index 6618589..885c491 100644 --- a/tests/integration/integration.executor.ts +++ b/tests/integration/integration.executor.ts @@ -15,8 +15,11 @@ describe('Performing Integration testing', async function() { apiPath: '/uat', }); const token = await client.getApiToken('default', '1q2w3e'); + console.log(`Got the following token: ${JSON.stringify(token)}`) const apiToken = await client.generateApiToken(token.access_token); + console.log(`Generated the following report portal token: ${apiToken.access_token}`) cliArguments.rtoken = apiToken.access_token; + console.log(`List of arguments: ${JSON.stringify(cliArguments)}`) testcafeServer = await createTestCafe('localhost', 1337, 1338); }); From 210adc7932e8d9a6b69b8b3ec9f7a3c00402baf5 Mon Sep 17 00:00:00 2001 From: Dani Tseitlin Date: Fri, 27 Sep 2024 21:11:48 +0300 Subject: [PATCH 03/30] . --- src/uat.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/uat.js b/src/uat.js index c250da2..ce81f76 100644 --- a/src/uat.js +++ b/src/uat.js @@ -62,6 +62,7 @@ class UAT { const token = Buffer.from('ui:uiman').toString('base64'); this.setUiToken(token); const response = await this.client.post(`/sso/oauth/token?${encodedURI}`); + console.log(response) return this.handleResponse(response); } catch (error) { @@ -81,6 +82,7 @@ class UAT { return this.handleResponse(response); } catch(error) { + console.log(error) return this.handleError(error); } } From 53932999b0a3afafebde3fcec33cf25e72f0a63e Mon Sep 17 00:00:00 2001 From: Dani Tseitlin Date: Fri, 27 Sep 2024 21:12:58 +0300 Subject: [PATCH 04/30] . --- src/uat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uat.js b/src/uat.js index ce81f76..6688cbd 100644 --- a/src/uat.js +++ b/src/uat.js @@ -82,7 +82,7 @@ class UAT { return this.handleResponse(response); } catch(error) { - console.log(error) + console.log(error); return this.handleError(error); } } From 38b6122f34582d7825b33aef1b8167b0c8b9a2ed Mon Sep 17 00:00:00 2001 From: Dani Tseitlin Date: Fri, 27 Sep 2024 21:17:00 +0300 Subject: [PATCH 05/30] . --- src/uat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uat.js b/src/uat.js index 6688cbd..77111db 100644 --- a/src/uat.js +++ b/src/uat.js @@ -62,7 +62,7 @@ class UAT { const token = Buffer.from('ui:uiman').toString('base64'); this.setUiToken(token); const response = await this.client.post(`/sso/oauth/token?${encodedURI}`); - console.log(response) + console.log(response); return this.handleResponse(response); } catch (error) { From d55a3c29396bcf3b0e38a53733c4c8756981a5ad Mon Sep 17 00:00:00 2001 From: Dani Tseitlin Date: Fri, 27 Sep 2024 21:23:34 +0300 Subject: [PATCH 06/30] . --- src/uat.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/uat.js b/src/uat.js index 77111db..29256e1 100644 --- a/src/uat.js +++ b/src/uat.js @@ -66,6 +66,7 @@ class UAT { return this.handleResponse(response); } catch (error) { + console.log(error); return this.handleError(error); } } From b07baa27bf5c4c4efb6e62f8aa7533644e339c10 Mon Sep 17 00:00:00 2001 From: Dani Tseitlin Date: Fri, 27 Sep 2024 21:26:43 +0300 Subject: [PATCH 07/30] . --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0f4c504..170ab4c 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "run-full-unit-tests": "npm run build-local-reporter && npm run unit-tests && npm run unit-retry-tests && npm run unit-no-live-reporting-tests && npm run unit-display-debug-logs-tests", "integration-tests": "npm run test ./tests/integration/integration.executor.ts -- --display-debug-logs", "run-integration-tests": "npm run build-local-reporter && npm run integration-tests", - "download-report-portal-docker-compose-file": "curl https://raw.githubusercontent.com/reportportal/reportportal/52ab9fa5613970bf426ce3f8236e22dfe95e92a6/docker-compose.yml -o docker-compose.yml", + "download-report-portal-docker-compose-file": "curl https://raw.githubusercontent.com/reportportal/reportportal/294c92503ff65bf2177b214b1fcb5c49feaf1315/docker-compose.yml -o docker-compose.yml", "download-report-portal-latest-docker-compose-file": "curl https://raw.githubusercontent.com/reportportal/reportportal/master/docker-compose.yml -o docker-compose.yml", "up": "docker compose -p reportportal up", "start": "docker compose -p reportportal start", From f528c3b5c4a690b96ee0c85e402da090074137ab Mon Sep 17 00:00:00 2001 From: Dani Tseitlin Date: Fri, 27 Sep 2024 21:43:25 +0300 Subject: [PATCH 08/30] . --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 170ab4c..8d8b646 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "run-full-unit-tests": "npm run build-local-reporter && npm run unit-tests && npm run unit-retry-tests && npm run unit-no-live-reporting-tests && npm run unit-display-debug-logs-tests", "integration-tests": "npm run test ./tests/integration/integration.executor.ts -- --display-debug-logs", "run-integration-tests": "npm run build-local-reporter && npm run integration-tests", - "download-report-portal-docker-compose-file": "curl https://raw.githubusercontent.com/reportportal/reportportal/294c92503ff65bf2177b214b1fcb5c49feaf1315/docker-compose.yml -o docker-compose.yml", + "download-report-portal-docker-compose-file": "curl https://raw.githubusercontent.com/reportportal/reportportal/e3ba138d62d2f4d11502389c96f6a8ea5f077f39/docker-compose.yml -o docker-compose.yml", "download-report-portal-latest-docker-compose-file": "curl https://raw.githubusercontent.com/reportportal/reportportal/master/docker-compose.yml -o docker-compose.yml", "up": "docker compose -p reportportal up", "start": "docker compose -p reportportal start", From 0014cc9c79c8e75858c3c8dcaa2ae6835ddce129 Mon Sep 17 00:00:00 2001 From: Dani Tseitlin Date: Fri, 27 Sep 2024 22:18:36 +0300 Subject: [PATCH 09/30] . --- tests/integration/integration.executor.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/integration.executor.ts b/tests/integration/integration.executor.ts index 885c491..2884b04 100644 --- a/tests/integration/integration.executor.ts +++ b/tests/integration/integration.executor.ts @@ -14,11 +14,11 @@ describe('Performing Integration testing', async function() { domain: 'localhost:8080', apiPath: '/uat', }); - const token = await client.getApiToken('default', '1q2w3e'); + const token = await client.getApiToken('superadmin', 'erebus'); console.log(`Got the following token: ${JSON.stringify(token)}`) const apiToken = await client.generateApiToken(token.access_token); console.log(`Generated the following report portal token: ${apiToken.access_token}`) - cliArguments.rtoken = apiToken.access_token; + cliArguments.rtoken = token.access_token; console.log(`List of arguments: ${JSON.stringify(cliArguments)}`) testcafeServer = await createTestCafe('localhost', 1337, 1338); }); From 13ded7987c717aef53f571334873bc0db70bb895 Mon Sep 17 00:00:00 2001 From: Dani Tseitlin Date: Sat, 28 Sep 2024 02:29:20 +0300 Subject: [PATCH 10/30] . --- src/api.js | 53 ++++++++++++++++++----- src/index.js | 5 ++- src/report-portal.js | 2 +- src/uat.js | 24 ++++++++++ tests/integration/integration.executor.ts | 17 +++++--- tests/integration/integration.testcafe.ts | 46 +++++++++++++------- 6 files changed, 114 insertions(+), 33 deletions(-) diff --git a/src/api.js b/src/api.js index 5ae6a88..8f9ba13 100644 --- a/src/api.js +++ b/src/api.js @@ -18,7 +18,7 @@ class API { */ async checkConnect () { try { - return this.handleResponse(await this.client.get('/user')); + return this.handleResponse(await this.client.get('/users')); } catch (error) { if(this.displayDebugLogs === true){ @@ -35,7 +35,7 @@ class API { */ async createLaunch (projectName, options) { try { - return this.handleResponse(await this.client.post(`/${projectName}/launch`, options)); + return this.handleResponse(await this.client.post(`/v1/${projectName}/launch`, options)); } catch (error) { return this.handleError(error); @@ -50,7 +50,7 @@ class API { */ async finishLaunch (projectName, launchId, options) { try { - return this.handleResponse(await this.client.put(`/${projectName}/launch/${launchId}/finish`, options)); + return this.handleResponse(await this.client.put(`/v1/${projectName}/launch/${launchId}/finish`, options)); } catch (error) { return this.handleError(error); @@ -65,7 +65,7 @@ class API { */ async forceStopLaunch (projectName, launchId, options) { try { - return this.handleResponse(await this.client.put(`/${projectName}/launch/${launchId}/stop`, options)); + return this.handleResponse(await this.client.put(`/v1/${projectName}/launch/${launchId}/stop`, options)); } catch (error) { return this.handleError(error); @@ -79,7 +79,7 @@ class API { */ async createTestItem (projectName, options) { try { - return this.handleResponse(await this.client.post(`/${projectName}/item`, options)); + return this.handleResponse(await this.client.post(`/v1/${projectName}/item`, options)); } catch (error) { return this.handleError(error); @@ -94,7 +94,7 @@ class API { */ async createChildTestItem (projectName, parentItem, options) { try { - return this.handleResponse(await this.client.post(`/${projectName}/item/${parentItem}`, options)); + return this.handleResponse(await this.client.post(`/v1/${projectName}/item/${parentItem}`, options)); } catch (error) { return this.handleError(error); @@ -109,7 +109,7 @@ class API { */ async finishTestItem (projectName, testItemId, options) { try { - return this.handleResponse(await this.client.put(`/${projectName}/item/${testItemId}`, options)); + return this.handleResponse(await this.client.put(`/v1/${projectName}/item/${testItemId}`, options)); } catch (error) { return this.handleError(error); @@ -159,19 +159,52 @@ class API { headers: { 'Content-type': `multipart/form-data; boundary=${MULTIPART_BOUNDARY}`, 'Authorization': `Bearer ${this.token}` } }); - await instance.post(`${this.baseURL}/${projectName}/log`, this.buildMultiPartStream([options], { + await instance.post(`${this.baseURL}/v1/${projectName}/log`, this.buildMultiPartStream([options], { name: options.file.name, type: 'image/png', content: fs.readFileSync(fullPath) }, MULTIPART_BOUNDARY)); } - else this.handleResponse(await this.client.post(`/${projectName}/log`, options)); + else this.handleResponse(await this.client.post(`/v1/${projectName}/log`, options)); } catch (error) { this.handleError(error); } } + async getLaunches(projectName) { + try { + const response = await this.client.get(`/v1/${projectName}/launch/latest`); + return this.handleResponse(response).content; + } + catch (error) { + return this.handleError(error); + } + } + + async getItems(projectName, launchId) { + try { + const response = await this.client.get(`/v1/${projectName}/item?filter.eq.launchId=${launchId}&isLatest=false&launchesLimit=0`)//filter.eq.launchId=${launchId}&isLatest=false&launchesLimit=0`); + return this.handleResponse(response).content; + } + catch (error) { + return this.handleError(error); + } + } + + async getItemLogs(projectName, itemId, logLevel='info') { + try { + const response = await this.client.post(`/v1/${projectName}/log/under`, { + itemIds: [itemId], + logLevel: logLevel + }); + return this.handleResponse(response)[itemId]; + } + catch (error) { + return this.handleError(error); + } + } + /** * Retrieving all logs in a project * @param {*} projectName The name of the project @@ -179,7 +212,7 @@ class API { */ async getLogs(projectName) { try { - const response = await this.client.get(`/${projectName}/log`); + const response = await this.client.get(`/v1/${projectName}/log`); return this.handleResponse(response); } catch (error) { diff --git a/src/index.js b/src/index.js index b92121e..b4cf762 100644 --- a/src/index.js +++ b/src/index.js @@ -78,12 +78,13 @@ exports['default'] = () => { async reportLogs(testId, level, message, time, attachment) { if(message !== undefined) { const isJSON = this.reporter.client.isJSON(message) || Array.isArray(message); + const isException = isJSON && JSON.parse(message).errMsg !== undefined //If the log is a stacktrace, and we want to focus on printing the error message itself. - if(isJSON && JSON.parse(message).errMsg !== undefined) message = JSON.parse(message).errMsg; + if(isException) message = JSON.parse(message).errMsg; //If the log is a JS Object else if(isJSON) message = JSON.parse(message); else if(typeof message === 'object') message = `"${message}"`; - message = this.reporter.client.isJSON(message) ? JSON.stringify(message): message; + message = isJSON ? JSON.stringify(message): message; } await this.reporter.sendTestLogs(testId, level, message, time, attachment); }, diff --git a/src/report-portal.js b/src/report-portal.js index 1ad219a..0aa575a 100644 --- a/src/report-portal.js +++ b/src/report-portal.js @@ -17,7 +17,7 @@ class ReportPortal { this.client = new RPClient({ protocol: (cliArguments.rprotocol) ? cliArguments.rprotocol: 'https', domain: cliArguments.rdomain, - apiPath: '/api/v1', + apiPath: '/api', token: cliArguments.rtoken, }); this.connected = true; diff --git a/src/uat.js b/src/uat.js index 29256e1..128a03e 100644 --- a/src/uat.js +++ b/src/uat.js @@ -87,6 +87,30 @@ class UAT { return this.handleError(error); } } + + async getApiKeys(token, userId) { + try { + this.setApiToken(token); + const response = await this.client.get(`api/users/${userId}/api-keys`) + console.log(response); + return this.handleResponse(response).items; + } + catch (error) { + return this.handleError(error); + } + } + + async createApiToken(token, userId, name) { + try { + this.setApiToken(token); + const response = await this.client.post(`api/users/${userId}/api-keys`, {name: name}) + console.log(response); + return this.handleResponse(response); + } + catch (error) { + return this.handleError(error); + } + } /** * Checking if item is a valid JSON diff --git a/tests/integration/integration.executor.ts b/tests/integration/integration.executor.ts index 2884b04..c1a8fc5 100644 --- a/tests/integration/integration.executor.ts +++ b/tests/integration/integration.executor.ts @@ -9,16 +9,21 @@ describe('Performing Integration testing', async function() { this.timeout(10 * 60 * 60 * 60); before(async () => { loadArguments(); - const client = new UAT({ + let client = new UAT({ protocol: 'http', domain: 'localhost:8080', apiPath: '/uat', }); - const token = await client.getApiToken('superadmin', 'erebus'); + const token = await client.getApiToken('default', '1q2w3e'); console.log(`Got the following token: ${JSON.stringify(token)}`) - const apiToken = await client.generateApiToken(token.access_token); - console.log(`Generated the following report portal token: ${apiToken.access_token}`) - cliArguments.rtoken = token.access_token; + client = new UAT({ + protocol: 'http', + domain: 'localhost:8080', + apiPath: '/', + }); + const apiToken = await client.createApiToken(token.access_token, 1, 'testing'+new Date().getTime() ); + console.log(`Generated the following report portal token: ${JSON.stringify(apiToken)}`) + cliArguments.rtoken = apiToken.api_key; console.log(`List of arguments: ${JSON.stringify(cliArguments)}`) testcafeServer = await createTestCafe('localhost', 1337, 1338); }); @@ -30,6 +35,7 @@ describe('Performing Integration testing', async function() { }); it('Running TestCafe Tests', async () => { + cliArguments.rlaunch="TestCafe Tests" const runner = testcafeServer.createRunner(); const failedCount = await runner .src(['tests/integration/integration.testcafe.ts']) @@ -40,6 +46,7 @@ describe('Performing Integration testing', async function() { console.log('Tests failed: ' + failedCount); }); it('Retry mechanism Tests', async () => { + cliArguments.rlaunch="Retry mechanism Tests" const runner = testcafeServer.createRunner(); const failedCount = await runner .src(['tests/integration/integration.retry.testcafe.ts']) diff --git a/tests/integration/integration.testcafe.ts b/tests/integration/integration.testcafe.ts index 8a703a0..f55e50d 100644 --- a/tests/integration/integration.testcafe.ts +++ b/tests/integration/integration.testcafe.ts @@ -1,5 +1,12 @@ import { t } from 'testcafe'; import { cliArguments } from 'cli-argument-parser'; +declare global { + interface TestController { + testRun: { + name: string; + }; + } +} const API = require('../../src/api.js'); let api: typeof API; fixture `First fixture` @@ -8,42 +15,51 @@ fixture `First fixture` api = new API({ protocol: 'http', domain: 'localhost:8080', - apiPath: '/api/v1', + apiPath: '/api', token: cliArguments.rtoken, }) }); test('Taking screenshot', async () => { - await logAndVerify('About to take a screenshot'); + await logAndVerify('Taking screenshot', 'About to take a screenshot'); await t.takeScreenshot() - await logAndVerify('The screenshot was succesfully taken!'); + await logAndVerify('Taking screenshot', 'The screenshot was succesfully taken!'); }) test('Negative testing, verifying Error display', async () => { - await logAndVerify('About to fail..'); - await logAndVerify(`${{obj: 'X', obj2: { x: 'Y'}}}`) - await logAndVerify({obj: 'X', obj2: { x: 'Y'}}) + await logAndVerify('Negative testing, verifying Error display', 'About to fail..'); + await logAndVerify('Negative testing, verifying Error display', `${{obj: 'X', obj2: { x: 'Y'}}}`) + await logAndVerify('Negative testing, verifying Error display', {obj: 'X', obj2: { x: 'Y'}}) await t.expect('X').eql('Y', 'OMG'); - await logAndVerify('The test failed!'); + await logAndVerify('Negative testing, verifying Error display', 'The test failed!'); }) fixture `Second fixture` test.skip('Skipping the test', async () => { - await logAndVerify('The test is skipped. This log shoud not be appearing.'); + await logAndVerify('Skipping the test', 'The test is skipped. This log shoud not be appearing.'); }) test('Basic print', async () => { - await logAndVerify('Printing the test contents'); + await logAndVerify('Basic print', 'Printing the test contents'); }) /** * Logging a message via console.log and verifying it exists in report portal * @param logMsg The log message */ -async function logAndVerify(logMsg: any) { - console.log(logMsg); +async function logAndVerify(testName: string, logMsg: any) { + const message = typeof logMsg !== 'string' ? JSON.stringify(logMsg): logMsg + console.log(message); await sleepInSeconds(5 * 1000); - let logs = await api.getLogs(cliArguments.rproject); - let log = logs.content.filter(l => l.message === logMsg); - process.stdout.write(`\n[Test logs]: Found ${log.length} occurances for message '${logMsg}'\n`); - await t.expect(log.length).gte(1, `Log appearances for '${logMsg}'`); + let launches = await api.getLaunches(cliArguments.rproject); + launches = launches.filter(l => l.name === cliArguments.rlaunch) + const launchId = launches[0].id; + const items = await api.getItems(cliArguments.rproject, launchId, testName) + + const item = items.find(item => item.name === testName && item.type === 'TEST') + const logs = await api.getItemLogs(cliArguments.rproject, item.id) + + const filteredLogs = logs.filter(l => l.message === message); + + process.stdout.write(`\n[Test logs]: Found ${filteredLogs.length} occurances for message '${message}'\n`); + await t.expect(filteredLogs.length).gte(1, `Log appearances for '${message}'`); } /** From 164e18e01bd175b80ff3ade4b7489c4da3661396 Mon Sep 17 00:00:00 2001 From: Dani Tseitlin Date: Sat, 28 Sep 2024 02:35:56 +0300 Subject: [PATCH 11/30] ... --- src/api.js | 2 +- src/index.js | 2 +- src/uat.js | 13 ++++--------- tests/integration/integration.executor.ts | 10 +--------- 4 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/api.js b/src/api.js index 8f9ba13..310f8a2 100644 --- a/src/api.js +++ b/src/api.js @@ -184,7 +184,7 @@ class API { async getItems(projectName, launchId) { try { - const response = await this.client.get(`/v1/${projectName}/item?filter.eq.launchId=${launchId}&isLatest=false&launchesLimit=0`)//filter.eq.launchId=${launchId}&isLatest=false&launchesLimit=0`); + const response = await this.client.get(`/v1/${projectName}/item?filter.eq.launchId=${launchId}&isLatest=false&launchesLimit=0`); return this.handleResponse(response).content; } catch (error) { diff --git a/src/index.js b/src/index.js index b4cf762..b1d9037 100644 --- a/src/index.js +++ b/src/index.js @@ -78,7 +78,7 @@ exports['default'] = () => { async reportLogs(testId, level, message, time, attachment) { if(message !== undefined) { const isJSON = this.reporter.client.isJSON(message) || Array.isArray(message); - const isException = isJSON && JSON.parse(message).errMsg !== undefined + const isException = isJSON && JSON.parse(message).errMsg !== undefined; //If the log is a stacktrace, and we want to focus on printing the error message itself. if(isException) message = JSON.parse(message).errMsg; //If the log is a JS Object diff --git a/src/uat.js b/src/uat.js index 128a03e..5cd2577 100644 --- a/src/uat.js +++ b/src/uat.js @@ -61,12 +61,10 @@ class UAT { }); const token = Buffer.from('ui:uiman').toString('base64'); this.setUiToken(token); - const response = await this.client.post(`/sso/oauth/token?${encodedURI}`); - console.log(response); + const response = await this.client.post(`uat/sso/oauth/token?${encodedURI}`); return this.handleResponse(response); } catch (error) { - console.log(error); return this.handleError(error); } } @@ -79,11 +77,10 @@ class UAT { async generateApiToken(token) { this.setApiToken(token); try { - const response = await this.client.post('/sso/me/apitoken?authenticated=true'); + const response = await this.client.post('uat/sso/me/apitoken?authenticated=true'); return this.handleResponse(response); } catch(error) { - console.log(error); return this.handleError(error); } } @@ -91,8 +88,7 @@ class UAT { async getApiKeys(token, userId) { try { this.setApiToken(token); - const response = await this.client.get(`api/users/${userId}/api-keys`) - console.log(response); + const response = await this.client.get(`uat/api/users/${userId}/api-keys`); return this.handleResponse(response).items; } catch (error) { @@ -103,8 +99,7 @@ class UAT { async createApiToken(token, userId, name) { try { this.setApiToken(token); - const response = await this.client.post(`api/users/${userId}/api-keys`, {name: name}) - console.log(response); + const response = await this.client.post(`api/users/${userId}/api-keys`, {name: name}); return this.handleResponse(response); } catch (error) { diff --git a/tests/integration/integration.executor.ts b/tests/integration/integration.executor.ts index c1a8fc5..e0d929c 100644 --- a/tests/integration/integration.executor.ts +++ b/tests/integration/integration.executor.ts @@ -10,21 +10,13 @@ describe('Performing Integration testing', async function() { before(async () => { loadArguments(); let client = new UAT({ - protocol: 'http', - domain: 'localhost:8080', - apiPath: '/uat', - }); - const token = await client.getApiToken('default', '1q2w3e'); - console.log(`Got the following token: ${JSON.stringify(token)}`) - client = new UAT({ protocol: 'http', domain: 'localhost:8080', apiPath: '/', }); + const token = await client.getApiToken('default', '1q2w3e'); const apiToken = await client.createApiToken(token.access_token, 1, 'testing'+new Date().getTime() ); - console.log(`Generated the following report portal token: ${JSON.stringify(apiToken)}`) cliArguments.rtoken = apiToken.api_key; - console.log(`List of arguments: ${JSON.stringify(cliArguments)}`) testcafeServer = await createTestCafe('localhost', 1337, 1338); }); From d73a12c1c8965bdc1958d1329274609ffe390e9a Mon Sep 17 00:00:00 2001 From: Dani Tseitlin Date: Sat, 28 Sep 2024 02:41:28 +0300 Subject: [PATCH 12/30] . --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8d8b646..f57010d 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "run-full-unit-tests": "npm run build-local-reporter && npm run unit-tests && npm run unit-retry-tests && npm run unit-no-live-reporting-tests && npm run unit-display-debug-logs-tests", "integration-tests": "npm run test ./tests/integration/integration.executor.ts -- --display-debug-logs", "run-integration-tests": "npm run build-local-reporter && npm run integration-tests", - "download-report-portal-docker-compose-file": "curl https://raw.githubusercontent.com/reportportal/reportportal/e3ba138d62d2f4d11502389c96f6a8ea5f077f39/docker-compose.yml -o docker-compose.yml", + "download-report-portal-docker-compose-file": "curl https://raw.githubusercontent.com/reportportal/reportportal/087acfad30b8c04588783e530b355f500e876694/docker-compose-release.yml -o docker-compose.yml", "download-report-portal-latest-docker-compose-file": "curl https://raw.githubusercontent.com/reportportal/reportportal/master/docker-compose.yml -o docker-compose.yml", "up": "docker compose -p reportportal up", "start": "docker compose -p reportportal start", From 37828067f529613bd71131760aec6a7dbf677f9d Mon Sep 17 00:00:00 2001 From: Dani Tseitlin Date: Sat, 28 Sep 2024 02:49:54 +0300 Subject: [PATCH 13/30] . --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bd48393..333cf0c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,7 +44,7 @@ jobs: - name: Docker version run: docker -v - name: Setting up a local Report Portal environment - run: sudo docker compose -f docker-compose.yml -p reportportal up -d --force-recreate + run: npm run up #sudo docker compose -f docker-compose.yml -p reportportal up -d --force-recreate - name: Waiting for services to be up run: ./scripts/healthcheck.bash - name: Report Portal server status From 8849202b79c126603860454ef1c98b9215e7b753 Mon Sep 17 00:00:00 2001 From: Dani Tseitlin Date: Sat, 28 Sep 2024 02:53:11 +0300 Subject: [PATCH 14/30] . --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 333cf0c..77882b2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,11 +40,11 @@ jobs: - name: Setting a Report Portal local reporter run: npm run build && npm run link-pkg - name: Downloading docker compose file - run: npm run download-report-portal-docker-compose-file + run: npm run download-report-portal-latest-docker-compose-file - name: Docker version run: docker -v - name: Setting up a local Report Portal environment - run: npm run up #sudo docker compose -f docker-compose.yml -p reportportal up -d --force-recreate + run: sudo docker compose -f docker-compose.yml -p reportportal up -d --force-recreate - name: Waiting for services to be up run: ./scripts/healthcheck.bash - name: Report Portal server status From 14a25274dbd89d309649c6b48d6f3cc647206ba2 Mon Sep 17 00:00:00 2001 From: Dani Tseitlin Date: Sat, 28 Sep 2024 03:03:15 +0300 Subject: [PATCH 15/30] ... --- tests/integration/integration.executor.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/integration/integration.executor.ts b/tests/integration/integration.executor.ts index e0d929c..c11e4ad 100644 --- a/tests/integration/integration.executor.ts +++ b/tests/integration/integration.executor.ts @@ -15,7 +15,10 @@ describe('Performing Integration testing', async function() { apiPath: '/', }); const token = await client.getApiToken('default', '1q2w3e'); + console.log(JSON.stringify(token)) const apiToken = await client.createApiToken(token.access_token, 1, 'testing'+new Date().getTime() ); + console.log(JSON.stringify(apiToken)) + cliArguments.rtoken = apiToken.api_key; testcafeServer = await createTestCafe('localhost', 1337, 1338); }); From 15fea9ed63a79f3b13bc2ae175fd567a57195a71 Mon Sep 17 00:00:00 2001 From: Dani Tseitlin Date: Sat, 28 Sep 2024 03:09:28 +0300 Subject: [PATCH 16/30] . --- scripts/healthcheck.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/healthcheck.bash b/scripts/healthcheck.bash index 39009eb..64422f8 100755 --- a/scripts/healthcheck.bash +++ b/scripts/healthcheck.bash @@ -5,7 +5,7 @@ wait-for-status() { echo "Waiting for services status" echo "" bash -c \ - 'while [[ "$(npm run status)" == *"(starting)"* ]];\ + 'while [[ "$(npm run status)" == *"(starting)"* -o "$(npm run status)" == *"(Exited)"* ]];\ do echo "Waiting for services" && sleep 2;\ done' } From 801f97e3b5d2ee60ca19eb41081467e4afb58463 Mon Sep 17 00:00:00 2001 From: Dani Tseitlin Date: Sat, 28 Sep 2024 03:24:50 +0300 Subject: [PATCH 17/30] . --- .github/workflows/ci.yml | 2 ++ scripts/healthcheck.bash | 2 +- scripts/healthcheck2.bash | 12 ++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 scripts/healthcheck2.bash diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 77882b2..68184c9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,6 +47,8 @@ jobs: run: sudo docker compose -f docker-compose.yml -p reportportal up -d --force-recreate - name: Waiting for services to be up run: ./scripts/healthcheck.bash + - name: Waiting for services to be up + run: ./scripts/healthcheck2.bash - name: Report Portal server status run: npm run status - name: Creating a .env file from existing example diff --git a/scripts/healthcheck.bash b/scripts/healthcheck.bash index 64422f8..39009eb 100755 --- a/scripts/healthcheck.bash +++ b/scripts/healthcheck.bash @@ -5,7 +5,7 @@ wait-for-status() { echo "Waiting for services status" echo "" bash -c \ - 'while [[ "$(npm run status)" == *"(starting)"* -o "$(npm run status)" == *"(Exited)"* ]];\ + 'while [[ "$(npm run status)" == *"(starting)"* ]];\ do echo "Waiting for services" && sleep 2;\ done' } diff --git a/scripts/healthcheck2.bash b/scripts/healthcheck2.bash new file mode 100644 index 0000000..befbad6 --- /dev/null +++ b/scripts/healthcheck2.bash @@ -0,0 +1,12 @@ +#!/bin/bash +set -eux + +wait-for-status() { + echo "Waiting for services status" + echo "" + bash -c \ + 'while [[ "$(npm run status)" == *"(Exited)"* ]];\ + do echo "Waiting for services" && sleep 2;\ + done' +} +wait-for-status \ No newline at end of file From 520442492c40cb3b6a324e3b00393c3f8cf672d0 Mon Sep 17 00:00:00 2001 From: Dani Tseitlin Date: Sat, 28 Sep 2024 03:28:41 +0300 Subject: [PATCH 18/30] . --- .github/workflows/ci.yml | 4 ++-- scripts/healthcheck.bash | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 68184c9..c23941c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,8 +47,8 @@ jobs: run: sudo docker compose -f docker-compose.yml -p reportportal up -d --force-recreate - name: Waiting for services to be up run: ./scripts/healthcheck.bash - - name: Waiting for services to be up - run: ./scripts/healthcheck2.bash + #- name: Waiting for services to be up + # run: ./scripts/healthcheck2.bash - name: Report Portal server status run: npm run status - name: Creating a .env file from existing example diff --git a/scripts/healthcheck.bash b/scripts/healthcheck.bash index 39009eb..9f2e2dd 100755 --- a/scripts/healthcheck.bash +++ b/scripts/healthcheck.bash @@ -6,7 +6,7 @@ wait-for-status() { echo "" bash -c \ 'while [[ "$(npm run status)" == *"(starting)"* ]];\ - do echo "Waiting for services" && sleep 2;\ + do echo "Waiting for services" && sleep 30;\ done' } wait-for-status \ No newline at end of file From bbc46aa7545765302a1bb55ae5bd368c5e5ee61c Mon Sep 17 00:00:00 2001 From: Dani Tseitlin Date: Sat, 28 Sep 2024 03:37:43 +0300 Subject: [PATCH 19/30] . --- scripts/healthcheck.bash | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/scripts/healthcheck.bash b/scripts/healthcheck.bash index 9f2e2dd..f2d3189 100755 --- a/scripts/healthcheck.bash +++ b/scripts/healthcheck.bash @@ -1,12 +1,26 @@ #!/bin/bash -set -eux +#set -eux +# +#wait-for-status() { +# echo "Waiting for services status" +# echo "" +# bash -c \ +# 'while [[ "$(npm run status)" == *"(starting)"* ]];\ +# do echo "Waiting for services" && sleep 30;\ +# done' +#} +#wait-for-status -wait-for-status() { - echo "Waiting for services status" - echo "" - bash -c \ - 'while [[ "$(npm run status)" == *"(starting)"* ]];\ - do echo "Waiting for services" && sleep 30;\ - done' -} -wait-for-status \ No newline at end of file +while true; do + # Run the command and capture the output + output=$(npm run start) + + # Check if the output contains 'starting' or 'exited' + if echo "$output" | grep -q -e "starting" -e "exited"; then + echo "Detected 'starting' or 'exited' in the output. Sleeping for 2 seconds..." + sleep 2 + else + echo "No 'starting' or 'exited' found in the output. Continuing..." + break + fi +done \ No newline at end of file From 0e28fdef14815f829eeaf9f9bc2bfe853e592604 Mon Sep 17 00:00:00 2001 From: Dani Tseitlin Date: Sat, 28 Sep 2024 03:37:58 +0300 Subject: [PATCH 20/30] . --- scripts/healthcheck.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/healthcheck.bash b/scripts/healthcheck.bash index f2d3189..3f4ee56 100755 --- a/scripts/healthcheck.bash +++ b/scripts/healthcheck.bash @@ -13,7 +13,7 @@ while true; do # Run the command and capture the output - output=$(npm run start) + output=$(npm run status) # Check if the output contains 'starting' or 'exited' if echo "$output" | grep -q -e "starting" -e "exited"; then From 72ad900ebbc5d50e0026589a93e908b72c9829b7 Mon Sep 17 00:00:00 2001 From: Dani Tseitlin Date: Sat, 28 Sep 2024 04:05:11 +0300 Subject: [PATCH 21/30] . --- tests/unit/mock.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/mock.ts b/tests/unit/mock.ts index e03d10c..c9f0956 100644 --- a/tests/unit/mock.ts +++ b/tests/unit/mock.ts @@ -1,7 +1,7 @@ import { Route, Request } from 'dmock-server'; export const mock: Route[] = [{ - path: '/api/v1/user', + path: '/api/users', method: 'get', response: {} },{ From 6ce500be0b21735a3cbc954fae90e06ce5d43142 Mon Sep 17 00:00:00 2001 From: Dani Tseitlin Date: Sat, 28 Sep 2024 04:05:59 +0300 Subject: [PATCH 22/30] . --- .github/workflows/ci.yml | 2 -- scripts/healthcheck2.bash | 12 ------------ 2 files changed, 14 deletions(-) delete mode 100644 scripts/healthcheck2.bash diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c23941c..77882b2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,8 +47,6 @@ jobs: run: sudo docker compose -f docker-compose.yml -p reportportal up -d --force-recreate - name: Waiting for services to be up run: ./scripts/healthcheck.bash - #- name: Waiting for services to be up - # run: ./scripts/healthcheck2.bash - name: Report Portal server status run: npm run status - name: Creating a .env file from existing example diff --git a/scripts/healthcheck2.bash b/scripts/healthcheck2.bash deleted file mode 100644 index befbad6..0000000 --- a/scripts/healthcheck2.bash +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -set -eux - -wait-for-status() { - echo "Waiting for services status" - echo "" - bash -c \ - 'while [[ "$(npm run status)" == *"(Exited)"* ]];\ - do echo "Waiting for services" && sleep 2;\ - done' -} -wait-for-status \ No newline at end of file From a8c6ef06d95b0f99131921e9447974e689344969 Mon Sep 17 00:00:00 2001 From: Dani Tseitlin Date: Sat, 28 Sep 2024 10:45:45 +0300 Subject: [PATCH 23/30] updating docker compose --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f57010d..8f1899f 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "run-full-unit-tests": "npm run build-local-reporter && npm run unit-tests && npm run unit-retry-tests && npm run unit-no-live-reporting-tests && npm run unit-display-debug-logs-tests", "integration-tests": "npm run test ./tests/integration/integration.executor.ts -- --display-debug-logs", "run-integration-tests": "npm run build-local-reporter && npm run integration-tests", - "download-report-portal-docker-compose-file": "curl https://raw.githubusercontent.com/reportportal/reportportal/087acfad30b8c04588783e530b355f500e876694/docker-compose-release.yml -o docker-compose.yml", + "download-report-portal-docker-compose-file": "curl https://raw.githubusercontent.com/reportportal/reportportal/f388a37cd3a96817f37a081ae3290304d13a17c3/docker-compose.yml -o docker-compose.yml", "download-report-portal-latest-docker-compose-file": "curl https://raw.githubusercontent.com/reportportal/reportportal/master/docker-compose.yml -o docker-compose.yml", "up": "docker compose -p reportportal up", "start": "docker compose -p reportportal start", From 310f47195c53650c34833e24b3b5682ab86670c5 Mon Sep 17 00:00:00 2001 From: Dani Tseitlin Date: Sat, 28 Sep 2024 10:56:31 +0300 Subject: [PATCH 24/30] . --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8f1899f..58fadc2 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "run-full-unit-tests": "npm run build-local-reporter && npm run unit-tests && npm run unit-retry-tests && npm run unit-no-live-reporting-tests && npm run unit-display-debug-logs-tests", "integration-tests": "npm run test ./tests/integration/integration.executor.ts -- --display-debug-logs", "run-integration-tests": "npm run build-local-reporter && npm run integration-tests", - "download-report-portal-docker-compose-file": "curl https://raw.githubusercontent.com/reportportal/reportportal/f388a37cd3a96817f37a081ae3290304d13a17c3/docker-compose.yml -o docker-compose.yml", + "download-report-portal-docker-compose-file": "curl https://raw.githubusercontent.com/reportportal/reportportal/a9f2fe18dfe9cb2a631d8a60fdbe254ced6963e7/docker-compose.yml -o docker-compose.yml", "download-report-portal-latest-docker-compose-file": "curl https://raw.githubusercontent.com/reportportal/reportportal/master/docker-compose.yml -o docker-compose.yml", "up": "docker compose -p reportportal up", "start": "docker compose -p reportportal start", From 44b892ae9c8e2d5e521073c697da631b318b167d Mon Sep 17 00:00:00 2001 From: Dani Tseitlin Date: Sat, 28 Sep 2024 11:21:11 +0300 Subject: [PATCH 25/30] . --- scripts/healthcheck.bash | 12 -------- src/{uat.js => api-testing-client.js} | 34 +++++------------------ src/index.js | 8 +++--- tests/integration/integration.executor.ts | 15 +++++----- tests/integration/integration.testcafe.ts | 4 +-- 5 files changed, 20 insertions(+), 53 deletions(-) rename src/{uat.js => api-testing-client.js} (84%) diff --git a/scripts/healthcheck.bash b/scripts/healthcheck.bash index 3f4ee56..3d193f1 100755 --- a/scripts/healthcheck.bash +++ b/scripts/healthcheck.bash @@ -1,16 +1,4 @@ #!/bin/bash -#set -eux -# -#wait-for-status() { -# echo "Waiting for services status" -# echo "" -# bash -c \ -# 'while [[ "$(npm run status)" == *"(starting)"* ]];\ -# do echo "Waiting for services" && sleep 30;\ -# done' -#} -#wait-for-status - while true; do # Run the command and capture the output output=$(npm run status) diff --git a/src/uat.js b/src/api-testing-client.js similarity index 84% rename from src/uat.js rename to src/api-testing-client.js index 5cd2577..3300d09 100644 --- a/src/uat.js +++ b/src/api-testing-client.js @@ -1,6 +1,6 @@ const axios = require('axios'); -class UAT { +class ApiTestingClient { constructor (options) { this.baseURL = `${options.protocol}://${options.domain}${options.apiPath}`; this.token = options.token; @@ -70,32 +70,12 @@ class UAT { } /** - * Generating an API token - * @param {*} token The UI token to authenticate with - * @returns A response obj with the API token data + * We create an API key to use it later on in our tests. + * @param {*} token + * @param {*} userId + * @param {*} name + * @returns */ - async generateApiToken(token) { - this.setApiToken(token); - try { - const response = await this.client.post('uat/sso/me/apitoken?authenticated=true'); - return this.handleResponse(response); - } - catch(error) { - return this.handleError(error); - } - } - - async getApiKeys(token, userId) { - try { - this.setApiToken(token); - const response = await this.client.get(`uat/api/users/${userId}/api-keys`); - return this.handleResponse(response).items; - } - catch (error) { - return this.handleError(error); - } - } - async createApiToken(token, userId, name) { try { this.setApiToken(token); @@ -172,4 +152,4 @@ class UAT { } } -module.exports = UAT; +module.exports = ApiTestingClient; diff --git a/src/index.js b/src/index.js index b1d9037..4344421 100644 --- a/src/index.js +++ b/src/index.js @@ -77,14 +77,14 @@ exports['default'] = () => { }, async reportLogs(testId, level, message, time, attachment) { if(message !== undefined) { - const isJSON = this.reporter.client.isJSON(message) || Array.isArray(message); - const isException = isJSON && JSON.parse(message).errMsg !== undefined; + const isJSON = (msg) => { return this.reporter.client.isJSON(msg) || Array.isArray(msg); } + const isException = isJSON(message) && JSON.parse(message).errMsg !== undefined; //If the log is a stacktrace, and we want to focus on printing the error message itself. if(isException) message = JSON.parse(message).errMsg; //If the log is a JS Object - else if(isJSON) message = JSON.parse(message); + else if(isJSON(message)) message = JSON.parse(message); else if(typeof message === 'object') message = `"${message}"`; - message = isJSON ? JSON.stringify(message): message; + message = isJSON(message) ? JSON.stringify(message): message; } await this.reporter.sendTestLogs(testId, level, message, time, attachment); }, diff --git a/tests/integration/integration.executor.ts b/tests/integration/integration.executor.ts index c11e4ad..f18f3ee 100644 --- a/tests/integration/integration.executor.ts +++ b/tests/integration/integration.executor.ts @@ -2,23 +2,22 @@ import { loadArguments } from '../utils/cli-loader'; import createTestCafe from 'testcafe'; import { cliArguments } from 'cli-argument-parser'; import { expect } from 'chai'; -import UAT from '../../src/uat.js' +import ApiTestingClient from '../../src/api-testing-client.js' let testcafeServer: TestCafe; describe('Performing Integration testing', async function() { this.timeout(10 * 60 * 60 * 60); before(async () => { loadArguments(); - let client = new UAT({ - protocol: 'http', - domain: 'localhost:8080', + let client = new ApiTestingClient({ + protocol: cliArguments.rprotocol, + domain: cliArguments.rdomain, apiPath: '/', }); - const token = await client.getApiToken('default', '1q2w3e'); - console.log(JSON.stringify(token)) - const apiToken = await client.createApiToken(token.access_token, 1, 'testing'+new Date().getTime() ); - console.log(JSON.stringify(apiToken)) + //Using the default user provided by report portal + const token = await client.getApiToken('default', '1q2w3e'); + const apiToken = await client.createApiToken(token.access_token, 1, `testing-${new Date().getTime()}` ); cliArguments.rtoken = apiToken.api_key; testcafeServer = await createTestCafe('localhost', 1337, 1338); }); diff --git a/tests/integration/integration.testcafe.ts b/tests/integration/integration.testcafe.ts index f55e50d..66e0a33 100644 --- a/tests/integration/integration.testcafe.ts +++ b/tests/integration/integration.testcafe.ts @@ -13,8 +13,8 @@ fixture `First fixture` .page('https://google.com') .before(async () => { api = new API({ - protocol: 'http', - domain: 'localhost:8080', + protocol: cliArguments.rprotocol, + domain: cliArguments.rdomain, apiPath: '/api', token: cliArguments.rtoken, }) From 1ddc463c30e8f55fa8309785064ea9fefa4fc965 Mon Sep 17 00:00:00 2001 From: Dani Tseitlin Date: Sat, 28 Sep 2024 11:22:35 +0300 Subject: [PATCH 26/30] . --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 4344421..4a586c6 100644 --- a/src/index.js +++ b/src/index.js @@ -77,7 +77,7 @@ exports['default'] = () => { }, async reportLogs(testId, level, message, time, attachment) { if(message !== undefined) { - const isJSON = (msg) => { return this.reporter.client.isJSON(msg) || Array.isArray(msg); } + const isJSON = (msg) => { return this.reporter.client.isJSON(msg) || Array.isArray(msg); }; const isException = isJSON(message) && JSON.parse(message).errMsg !== undefined; //If the log is a stacktrace, and we want to focus on printing the error message itself. if(isException) message = JSON.parse(message).errMsg; From e4d0a43e29a57a6ab07e7b9325adfd0be68bfa9c Mon Sep 17 00:00:00 2001 From: Dani Tseitlin Date: Sat, 28 Sep 2024 11:30:52 +0300 Subject: [PATCH 27/30] . --- src/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 4a586c6..b1d9037 100644 --- a/src/index.js +++ b/src/index.js @@ -77,14 +77,14 @@ exports['default'] = () => { }, async reportLogs(testId, level, message, time, attachment) { if(message !== undefined) { - const isJSON = (msg) => { return this.reporter.client.isJSON(msg) || Array.isArray(msg); }; - const isException = isJSON(message) && JSON.parse(message).errMsg !== undefined; + const isJSON = this.reporter.client.isJSON(message) || Array.isArray(message); + const isException = isJSON && JSON.parse(message).errMsg !== undefined; //If the log is a stacktrace, and we want to focus on printing the error message itself. if(isException) message = JSON.parse(message).errMsg; //If the log is a JS Object - else if(isJSON(message)) message = JSON.parse(message); + else if(isJSON) message = JSON.parse(message); else if(typeof message === 'object') message = `"${message}"`; - message = isJSON(message) ? JSON.stringify(message): message; + message = isJSON ? JSON.stringify(message): message; } await this.reporter.sendTestLogs(testId, level, message, time, attachment); }, From 06b9359e38098c28ca5debac20f4579e0b713154 Mon Sep 17 00:00:00 2001 From: Dani Tseitlin Date: Sat, 28 Sep 2024 11:31:41 +0300 Subject: [PATCH 28/30] . --- tests/integration/integration.executor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/integration.executor.ts b/tests/integration/integration.executor.ts index f18f3ee..64faec9 100644 --- a/tests/integration/integration.executor.ts +++ b/tests/integration/integration.executor.ts @@ -9,7 +9,7 @@ describe('Performing Integration testing', async function() { this.timeout(10 * 60 * 60 * 60); before(async () => { loadArguments(); - let client = new ApiTestingClient({ + const client = new ApiTestingClient({ protocol: cliArguments.rprotocol, domain: cliArguments.rdomain, apiPath: '/', From 58c2ea30baed44a6d1c8a7191c7c073e3381405a Mon Sep 17 00:00:00 2001 From: Dani Tseitlin Date: Sat, 28 Sep 2024 17:30:00 +0300 Subject: [PATCH 29/30] . --- src/api-testing-client.js | 10 +++--- src/api.js | 41 ++++++++++++----------- tests/integration/integration.executor.ts | 2 +- tests/integration/integration.testcafe.ts | 11 ++---- 4 files changed, 30 insertions(+), 34 deletions(-) diff --git a/src/api-testing-client.js b/src/api-testing-client.js index 3300d09..1241faa 100644 --- a/src/api-testing-client.js +++ b/src/api-testing-client.js @@ -71,12 +71,12 @@ class ApiTestingClient { /** * We create an API key to use it later on in our tests. - * @param {*} token - * @param {*} userId - * @param {*} name - * @returns + * @param {*} token The UAT token to gain permissions to create an API key + * @param {*} userId The id of the user + * @param {*} name The name of the token + * @returns The api key object */ - async createApiToken(token, userId, name) { + async createApiKey(token, userId, name) { try { this.setApiToken(token); const response = await this.client.post(`api/users/${userId}/api-keys`, {name: name}); diff --git a/src/api.js b/src/api.js index 310f8a2..b7072d6 100644 --- a/src/api.js +++ b/src/api.js @@ -172,6 +172,11 @@ class API { } } + /** + * Retrieves a list of the project latest launches + * @param {*} projectName The project name + * @returns A list of the latest project launches + */ async getLaunches(projectName) { try { const response = await this.client.get(`/v1/${projectName}/launch/latest`); @@ -182,7 +187,13 @@ class API { } } - async getItems(projectName, launchId) { + /** + * Retrieves a list of test items + * @param {*} projectName The project name + * @param {*} launchId The launch id + * @returns A list of test items that are part of a project and a launch + */ + async getTestItems(projectName, launchId) { try { const response = await this.client.get(`/v1/${projectName}/item?filter.eq.launchId=${launchId}&isLatest=false&launchesLimit=0`); return this.handleResponse(response).content; @@ -192,10 +203,17 @@ class API { } } - async getItemLogs(projectName, itemId, logLevel='info') { + /** + * Retrieves a list of logs under a test item + * @param {*} projectName The project name + * @param {*} itemId The test item id + * @param {*} logLevel The log level. Default: info + * @returns A list of test item logs + */ + async getTestItemLogs(projectName, testItemId, logLevel='info') { try { const response = await this.client.post(`/v1/${projectName}/log/under`, { - itemIds: [itemId], + itemIds: [testItemId], logLevel: logLevel }); return this.handleResponse(response)[itemId]; @@ -204,24 +222,9 @@ class API { return this.handleError(error); } } - - /** - * Retrieving all logs in a project - * @param {*} projectName The name of the project - * @returns A list of logs - */ - async getLogs(projectName) { - try { - const response = await this.client.get(`/v1/${projectName}/log`); - return this.handleResponse(response); - } - catch (error) { - return this.handleError(error); - } - } /** - * Checking if item is a valid JSON + * Checking if item is a valid JSON by attempting to parse it * @param {*} json The string of the JSON */ isJSON (json) { diff --git a/tests/integration/integration.executor.ts b/tests/integration/integration.executor.ts index 64faec9..b569b9b 100644 --- a/tests/integration/integration.executor.ts +++ b/tests/integration/integration.executor.ts @@ -17,7 +17,7 @@ describe('Performing Integration testing', async function() { //Using the default user provided by report portal const token = await client.getApiToken('default', '1q2w3e'); - const apiToken = await client.createApiToken(token.access_token, 1, `testing-${new Date().getTime()}` ); + const apiToken = await client.createApiKey(token.access_token, 1, `testing-${new Date().getTime()}` ); cliArguments.rtoken = apiToken.api_key; testcafeServer = await createTestCafe('localhost', 1337, 1338); }); diff --git a/tests/integration/integration.testcafe.ts b/tests/integration/integration.testcafe.ts index 66e0a33..7a9e6c8 100644 --- a/tests/integration/integration.testcafe.ts +++ b/tests/integration/integration.testcafe.ts @@ -1,12 +1,5 @@ import { t } from 'testcafe'; import { cliArguments } from 'cli-argument-parser'; -declare global { - interface TestController { - testRun: { - name: string; - }; - } -} const API = require('../../src/api.js'); let api: typeof API; fixture `First fixture` @@ -51,10 +44,10 @@ async function logAndVerify(testName: string, logMsg: any) { let launches = await api.getLaunches(cliArguments.rproject); launches = launches.filter(l => l.name === cliArguments.rlaunch) const launchId = launches[0].id; - const items = await api.getItems(cliArguments.rproject, launchId, testName) + const items = await api.getTestItems(cliArguments.rproject, launchId, testName) const item = items.find(item => item.name === testName && item.type === 'TEST') - const logs = await api.getItemLogs(cliArguments.rproject, item.id) + const logs = await api.getTestItemLogs(cliArguments.rproject, item.id) const filteredLogs = logs.filter(l => l.message === message); From 6145098ed99329c81de198093f9694e1c36356bc Mon Sep 17 00:00:00 2001 From: Dani Tseitlin Date: Sat, 28 Sep 2024 17:33:49 +0300 Subject: [PATCH 30/30] . --- src/api.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/api.js b/src/api.js index b7072d6..65f2167 100644 --- a/src/api.js +++ b/src/api.js @@ -206,7 +206,7 @@ class API { /** * Retrieves a list of logs under a test item * @param {*} projectName The project name - * @param {*} itemId The test item id + * @param {*} testItemId The test item id * @param {*} logLevel The log level. Default: info * @returns A list of test item logs */ @@ -216,7 +216,7 @@ class API { itemIds: [testItemId], logLevel: logLevel }); - return this.handleResponse(response)[itemId]; + return this.handleResponse(response)[testItemId]; } catch (error) { return this.handleError(error);