Skip to content

Commit 7aef115

Browse files
committed
SonarQube Changes
1 parent f09347f commit 7aef115

File tree

15 files changed

+74
-22
lines changed

15 files changed

+74
-22
lines changed

.scannerwork/.sonar_lock

Whitespace-only changes.

.scannerwork/report-task.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
projectKey=playwright-sonar
2+
serverUrl=http://localhost:9000
3+
serverVersion=9.1.0.47736
4+
dashboardUrl=http://localhost:9000/dashboard?id=playwright-sonar
5+
ceTaskId=AXz6mn6PehyB8Jds9Zty
6+
ceTaskUrl=http://localhost:9000/api/ce/task?id=AXz6mn6PehyB8Jds9Zty

README.md

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
</li>
2020
<li><a href="#usage">Usage</a></li>
2121
<li><a href="#reports">Reports</a></li>
22+
<li><a href="#sonar">SonarQube</a></li>
2223
</ol>
2324
</h5>
2425
</details>
@@ -39,28 +40,28 @@ Top Features:
3940
- Generates trace file, which gives in-depth details of Test Case execution.
4041
- Execution of test case is faster when compared with other competitive framework in market.
4142
- Supports Headful/Headless mode execution for Firefox/Webkit/Google Chrome/Chromium/MS Edge on Windows/Linux/Mac machines.
43+
- It supports API testing (From Playwright version 1.16 onwards)
4244
- It can be used to simulate browser behaviour on mobile devices, and supports over 100+ devices.
4345
- It has ability to produce and visually compare screenshots.
4446
- To slow down execution slowMo option is available.
4547
- Supports 'download' event monitoring, so there is no need for user to actually wait for downloads to finish.
4648
- Supports Serial and Parallel execution.
47-
- Allure Reports are generated after execution with an option to capture screenshot/video/trace file on failure.
49+
- Allure/HTML Reports are generated after execution with an option to capture screenshot/video/trace file on failure.
4850
- Nonetheless Support from Microsoft so FREQUENT RELEASES and turn arounf time for any queries is 48 hours.
4951

5052
Bonus:
5153

52-
- Supports API testing using 'supertest' module.
5354
- Supports PostgresSQL using 'pg' module.
5455
- Supports Excel File Read/Write using 'excel-js' module.
5556

5657
### Built With
5758

5859
- [Playwright](https://playwright.dev)
5960
- [Typescript](https://www.typescriptlang.org/)
60-
- [Supertest](https://github.com/visionmedia/supertest)
6161
- [node-postgres](https://github.com/brianc/node-postgres)
6262
- [excel-js](https://github.com/exceljs/exceljs)
6363
- [ESLint](https://eslint.org/)
64+
- [SonarQube](https://www.sonarqube.org/)
6465

6566
## Getting Started
6667

@@ -73,11 +74,21 @@ The following software are required:
7374
https://nodejs.org/en/download/
7475
```
7576
- Install Java 8 or above, Allure Reports require Java 8 or higher.
76-
77+
- Install Java 11 instead of Java 8 if you intend to use Sonar Qube.
7778
- allure commandline : Install allure command line for generating Allure Reports using
7879
```sh
7980
npm install -g allure-commandline
8081
```
82+
- If you wish to include SonarQube follow the below steps:
83+
- Install Java 11 and add java path to "PATH" environment variable.
84+
- Download SonarQube community server from the below url and unzip it to desired location.
85+
```sh
86+
https://www.sonarqube.org/downloads/
87+
```
88+
- Download Sonar Scanner for your desired OS (Windows in my case) from below location and unzip it to desired location. Then navigate to bin location once unzipped and provide the path to "PATH" environment variable.
89+
```sh
90+
https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/
91+
```
8192

8293
### Installation
8394

@@ -178,8 +189,37 @@ npx playwright show-trace trace.zip
178189
- <b>Failure Report</b>
179190
![Failure Report Screenshot][failure-report-screenshot]
180191

192+
## SonarQube
193+
194+
Once you have completed setup for SonarQube given in Prerequisites section, configure SonarQube as given below
195+
- Go to the path where sonarqube server(For e.g. : C:\SonarQube\sonarqube-9.1.0.47736) is unzipped -> Go to conf Folder -> open sonar.properties file and add the below prperties and save the file, you can give any port you wish I have used port 9000.
196+
```JS
197+
sonar.host.url=http://localhost:9000
198+
sonar.sourceEncoding=UTF-8
199+
```
200+
- Go to the path where sonarqube server(For e.g. : C:\SonarQube\sonarqube-9.1.0.47736) is unzipped -> Go to bin section -> Go to the folder as per the OS you are using , in my case windows-x86-64 -> Double click on Start Sonar and wait for it to display SonarQube is up (you might encounter some java errors but its fine don't close the terminal).
201+
- Go to the browser and naigate to http://localhost:9000 , default username is `admin`, default password is `admin`. It might ask you to provide a new password for if you have logged in for first time, I have changed default password to `password`.
202+
- In your working project (playwright-typescipt-playwright-test), navigate to `sonar-project.properties` file and provide the credentials configured on server webpage username value in `sonar.login` and password in `sonar.password`, in my case username is `admin` and password was changed to `password`.
203+
```JS
204+
sonar.login=admin
205+
sonar.password=password
206+
```
207+
- You can provide any project name in `sonar.projectKey`.
208+
- Specify a version in `sonar.projectVersion`.
209+
- Provide `UTF-8` in `sonar.sourceEncoding`.
210+
- In `sonar.language` provide the language you want to run scan on (For e.g. for typescipt its ts and for javascript its js).
211+
- If you have eslint file in your project provide the location in `sonar.eslint.eslintconfigpath`.
212+
- You can exclude file from scanning like node_modules, results , Downloads section in `sonar.exclusions`.
213+
- You can give your project location in `sonar.sources` section I have provided it as `./` because my `sonar-project.properties` file is within my project. If your properties files is somewhere else you have to provide the complete project path.
214+
- Now go to the location where `sonar-project.properties` is present and run `sonar-scanner` command (In my case I will diectly run it inside my project), and wait for scan to get over with success message.
215+
- Now navigate to `http://localhost:9000/` and click on your project key displayed and go to Issues section, you can find all the suggestions and issues here. You can fix the issues ans rerun `sonar-scanner` command once again.
216+
- <b>SonarQube Report</b>
217+
![SonarQube Report Screenshot][sonar-report-screenshot]
218+
181219
<!-- MARKDOWN LINKS & IMAGES -->
182220

183221
[overall-report-screenshot]: ReadMeImages/OverallReport.PNG
184222
[detailed-report-screenshot]: ReadMeImages/DetailedReport.PNG
185223
[failure-report-screenshot]: ReadMeImages/FailureReport.PNG
224+
[sonar-report-screenshot]: ReadMeImages/SonarReport.PNG
225+

ReadMeImages/SonarReport.PNG

100 KB
Loading

lib/APIActions.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ export class APIActions {
1717
let fieldNames = `Parameter`;
1818
const headers = expectedResponseBodyParams.split("|");
1919
const responseToString = JSON.stringify(responsePart).trim();
20-
for (let i = 0; i < headers.length; i++) {
21-
if (!(responseToString.includes(headers[i].trim()))) {
20+
for (let headerKey of headers) {
21+
if (!(responseToString.includes(headerKey.trim()))) {
2222
status = false;
23-
fieldNames = fieldNames + `, ` + headers[i];
23+
fieldNames = fieldNames + `, ` + headerKey;
2424
break;
2525
}
2626
}
@@ -35,10 +35,10 @@ export class APIActions {
3535
async verifyResponseHeader(expectedResponseHeaderParams: string, responsePart: Array<{ name: string, value: string }>, responseType: string): Promise<void> {
3636
let status = true;
3737
let fieldNames = `Parameter`;
38-
for (let i = 0; i < responsePart.length; i++) {
39-
if (!(expectedResponseHeaderParams.includes(responsePart[i].name.trim()))) {
38+
for (let responseKey of responsePart) {
39+
if (!(expectedResponseHeaderParams.includes(responseKey.name.trim()))) {
4040
status = false;
41-
fieldNames = fieldNames + ' ,' + responsePart[i].name;
41+
fieldNames = fieldNames + ' ,' + responseKey.name;
4242
break;
4343
}
4444
}
File renamed without changes.

lib/DBActions.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import pg from 'pg';
21
import type { Client } from 'pg';
32

43
let pgClient: Client;
@@ -12,6 +11,6 @@ export class DBActions {
1211
}
1312

1413
async query(queryString: string): Promise<void> {
15-
return await pgClient.query(queryString);
14+
return pgClient.query(queryString);
1615
}
1716
}

lib/WebActions.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export class WebActions {
8585

8686
async getTextFromWebElements(locator: string): Promise<string[]> {
8787
await this.waitForElementAttached(locator);
88-
return await this.page.$$eval(locator, elements => elements.map(item => item.textContent.trim()));
88+
return this.page.$$eval(locator, elements => elements.map(item => item.textContent.trim()));
8989
}
9090

9191
async downloadFile(locator: string): Promise<string> {
@@ -103,11 +103,10 @@ export class WebActions {
103103

104104
async readDataFromExcel(fileName: string, sheetName: string, rowNum: number, cellNum: number): Promise<string> {
105105
const workbook = new Workbook();
106-
const data = await workbook.xlsx.readFile(`./Downloads/${fileName}`).then(function () {
106+
return workbook.xlsx.readFile(`./Downloads/${fileName}`).then(function () {
107107
const sheet = workbook.getWorksheet(sheetName);
108108
return sheet.getRow(rowNum).getCell(cellNum).toString();
109109
});
110-
return data;
111110
}
112111

113112
async readValuesFromTextFile(filePath: string): Promise<string> {

pageFactory/pageRepository/MyAccountPage.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { MyAccountPageObjects } from "../objectRepository/MyAccountPageObjects";
22
import { WebActions } from "../../lib/WebActions";
33
import type { Page } from 'playwright';
4-
import fs from 'fs';
54

65
let webActions: WebActions;
76

sonar-project.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
sonar.login=admin
2+
sonar.password=password
3+
sonar.projectKey=playwright-sonar
4+
sonar.projectVersion=1.0
5+
sonar.sourceEncoding=UTF-8
6+
sonar.language=ts
7+
sonar.eslint.eslintconfigpath=.eslintrc.js
8+
sonar.exclusions=node_modules/*,test-results/*,allure-results/*,allure-report/*,html-report/*,Downloads/*
9+
sonar.sources=./

0 commit comments

Comments
 (0)