Skip to content

Commit 055a76f

Browse files
authored
Update README.md with project details (#1)
* Update README.md with project details - Add .node-version file - Add step definitions - Add Dockerfile * Update cucumber.js by removing space at the last line
1 parent 3a523fd commit 055a76f

File tree

8 files changed

+2401
-0
lines changed

8 files changed

+2401
-0
lines changed

.node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
16.16.0

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM node:16.16.0 as base
2+
3+
# Create app directory
4+
WORKDIR /usr/src/app
5+
6+
FROM base as install
7+
CMD ["npm", "install"]
8+
9+
FROM base as test
10+
CMD ["npm", "test"]

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,66 @@
11
# selenium-webdriver-cucumber-js-example-project
22
This project demonstrates the usage of selenium-webdriver, cucumberjs in a Node.js project with Docker and Jenkins CI
3+
4+
## Project file structure
5+
6+
```
7+
├── cucumber.js
8+
├── package-lock.json
9+
└── package.json
10+
└── README.md
11+
```
12+
1. Scenarios are defined in .feature files, which are stored in the features directory
13+
2. Step definitions are defined in .js files which are stored in the step_definitions directory
14+
3. Reports in,
15+
- html format is stored in cucumber-report.html
16+
- json format is stored in cucumber-report.json
17+
4. package.json holds important information about the project. It contains human-readable metadata about the project (like the project name and description) as well as functional metadata like the package version number and a list of dependencies required by the application
18+
5. README.md file to communicate important information about Selenium WebDriver, CucumberJS example project
19+
6. Dockerfile informs Docker what base image we would like to use for the Node.js application project
20+
7. Jenkinsfile is a text file that contains the definition of a Jenkins Pipeline and is checked into source control
21+
22+
## Development
23+
24+
### Install
25+
26+
Install dependencies
27+
28+
```sh
29+
npm install
30+
```
31+
32+
### Test
33+
34+
Run standalone
35+
36+
```sh
37+
npx cucumber-js
38+
```
39+
40+
# Docker CI
41+
42+
## Docker multi-stage build for install
43+
docker build command with --target install flag so that we specifically run the install build stage
44+
```sh
45+
docker build -t selenium-webdriver-cucumber-js-example-project-install --target install .
46+
```
47+
48+
### Docker run install
49+
50+
Docker command to start the container and run install
51+
```sh
52+
docker run --rm -v ${PWD}:/usr/src/app/ --name selenium-webdriver-cucumber-js-example-project-install selenium-webdriver-cucumber-js-example-project-install
53+
```
54+
55+
## Docker multi-stage build for testing
56+
docker build command with --target test flag so that we specifically run the test build stage
57+
```sh
58+
docker build -t selenium-webdriver-cucumber-js-example-project-test --target test .
59+
```
60+
61+
### Docker run test
62+
63+
Docker command to start the container and run test
64+
```sh
65+
docker run --rm -v ${PWD}:/usr/src/app/ --name selenium-webdriver-cucumber-js-example-project-test selenium-webdriver-cucumber-js-example-project-test
66+
```

cucumber.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
default: {
3+
format: ['progress', 'json:cucumber-report.json', 'html:cucumber-report.html'],
4+
formatOptions: { 'snippetInterface':'synchronous' },
5+
publishQuiet: true
6+
}
7+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Feature: Is it Akarsh portfolio website?
2+
3+
Scenario: Finding the title of the portfolio website
4+
Given The website "akarsh.github.io" is available
5+
When I navigate to "akarsh.github.io"
6+
Then the page title should start with "Akarsh SEGGEMU"
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const { Given, When, Then, AfterAll } = require("@cucumber/cucumber");
2+
const webdriver = require("selenium-webdriver");
3+
const assert = require("assert");
4+
const http2 = require("node:http2");
5+
6+
// Local development test
7+
// let driver = new Builder()
8+
// .forBrowser("chrome")
9+
// .setChromeOptions(new chrome.Options().headless())
10+
// .build();
11+
12+
let driver = new webdriver.Builder()
13+
.forBrowser(webdriver.Browser.CHROME)
14+
.usingServer("http://localhost:4444/wd/hub")
15+
.build();
16+
17+
function isConnected(string) {
18+
return new Promise((resolve) => {
19+
const client = http2.connect("https://" + string);
20+
client.on("connect", () => {
21+
resolve(true);
22+
client.destroy();
23+
});
24+
client.on("error", () => {
25+
resolve(false);
26+
client.destroy();
27+
});
28+
});
29+
}
30+
31+
Given("The website {string} is available", async function (string) {
32+
return await isConnected(string);
33+
});
34+
35+
When("I navigate to {string}", async function (string) {
36+
return await driver.get("https://" + string);
37+
});
38+
39+
Then(
40+
"the page title should start with {string}",
41+
{ timeout: 60 * 1000 },
42+
async function (string) {
43+
return assert((await driver.getTitle()) == "Akarsh SEGGEMU");
44+
}
45+
);
46+
47+
AfterAll(async function () {
48+
await driver.quit();
49+
});

0 commit comments

Comments
 (0)