Skip to content

Commit cb2d006

Browse files
committed
DockerFileRewrite
1 parent bdaa096 commit cb2d006

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

Dockerfile

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
FROM mcr.microsoft.com/playwright:next
22

3-
WORKDIR /app
3+
#Create a new Folder to provide permissions for non root user
4+
RUN mkdir -p /newfolder
5+
6+
WORKDIR /newfolder
7+
8+
#Switched to root user to install dependencies
9+
USER root
410

511
COPY package.json package-lock.json ./
612

@@ -10,8 +16,13 @@ COPY . .
1016

1117
RUN npx playwright install chrome
1218

13-
CMD ["npm","run","test:serial"]
14-
19+
#Creating a User(Turing) with non Root Permissions
20+
RUN useradd -u 8877 Turing
1521

22+
#Permission inside newfolder so that reports can be generated
23+
RUN chown Turing /newfolder
1624

25+
#Switch from root user to non root user
26+
USER Turing
1727

28+
CMD ["npx","cross-env","ENV=qa","npm","run","test:serial"]

README.md

+19-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<li><a href="#usage">Usage</a></li>
2121
<li><a href="#reports">Reports</a></li>
2222
<li><a href="#sonarqube">SonarQube</a></li>
23+
<li><a href="#docker">Docker</a></li>
2324
</ol>
2425
</h5>
2526
</details>
@@ -79,7 +80,7 @@ The following software are required:
7980
- Install Java 11 instead of Java 8 if you intend to use Sonar Qube.
8081
- allure commandline : Install allure command line for generating Allure Reports using
8182
```sh
82-
npm install -g allure-commandline
83+
npm ci -g allure-commandline
8384
```
8485
- If you wish to include SonarQube follow the below steps:
8586
- Install Java 11 and add java path to "PATH" environment variable.
@@ -103,7 +104,7 @@ https://github.com/akshayp7/playwright-typescipt-playwright-test.git
103104
2. Navigate to folder and install npm packages using:
104105

105106
```sh
106-
npm install
107+
npm ci
107108
```
108109

109110
<!-- USAGE EXAMPLES-->
@@ -220,6 +221,22 @@ sonar.password=password
220221
- <b>SonarQube Report</b>
221222
![SonarQube Report Screenshot][sonar-report-screenshot]
222223

224+
## Docker
225+
For running the tests on Docker container we have to first build a image from Dockerfile and then run the image to spawn container on which the test scripts will run.
226+
- For building image from Docker run below command, where path to Dockerfile must be provided after -f tag and name of the image must be provided after -t tag.
227+
```JS
228+
docker build . -f Dockerfile -t playtest
229+
```
230+
- Once the image is generated we can run the image to spawn container and run scrips using below command. In Below Command "playContainer" is name of the container created using "playtest" image.
231+
```JS
232+
docker run --name playContainer playtest
233+
```
234+
- If you want to run a different test or provide custom command, Go to Dockerfile and edit the last line which is CMD section. The below sample runs test cases serially on QA environment.
235+
Once you have edited the CMD section we have to follow Step 1 to build a new image and ten run the Container from that image.
236+
```JS
237+
CMD ["npx","cross-env","ENV=qa","npm","run","test:serial"]
238+
```
239+
223240
<!-- MARKDOWN LINKS & IMAGES -->
224241

225242
[overall-report-screenshot]: ReadMeImages/OverallReport.PNG

0 commit comments

Comments
 (0)