Skip to content
Merged
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
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16.16.0
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM node:16.16.0 as base

# Create app directory
WORKDIR /usr/src/app

FROM base as install
CMD ["npm", "install"]

FROM base as test
CMD ["npm", "test"]
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,66 @@
# selenium-webdriver-cucumber-js-example-project
This project demonstrates the usage of selenium-webdriver, cucumberjs in a Node.js project with Docker and Jenkins CI

## Project file structure

```
├── cucumber.js
├── package-lock.json
└── package.json
└── README.md
```
1. Scenarios are defined in .feature files, which are stored in the features directory
2. Step definitions are defined in .js files which are stored in the step_definitions directory
3. Reports in,
- html format is stored in cucumber-report.html
- json format is stored in cucumber-report.json
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
5. README.md file to communicate important information about Selenium WebDriver, CucumberJS example project
6. Dockerfile informs Docker what base image we would like to use for the Node.js application project
7. Jenkinsfile is a text file that contains the definition of a Jenkins Pipeline and is checked into source control

## Development

### Install

Install dependencies

```sh
npm install
```

### Test

Run standalone

```sh
npx cucumber-js
```

# Docker CI

## Docker multi-stage build for install
docker build command with --target install flag so that we specifically run the install build stage
```sh
docker build -t selenium-webdriver-cucumber-js-example-project-install --target install .
```

### Docker run install

Docker command to start the container and run install
```sh
docker run --rm -v ${PWD}:/usr/src/app/ --name selenium-webdriver-cucumber-js-example-project-install selenium-webdriver-cucumber-js-example-project-install
```

## Docker multi-stage build for testing
docker build command with --target test flag so that we specifically run the test build stage
```sh
docker build -t selenium-webdriver-cucumber-js-example-project-test --target test .
```

### Docker run test

Docker command to start the container and run test
```sh
docker run --rm -v ${PWD}:/usr/src/app/ --name selenium-webdriver-cucumber-js-example-project-test selenium-webdriver-cucumber-js-example-project-test
```
7 changes: 7 additions & 0 deletions cucumber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
default: {
format: ['progress', 'json:cucumber-report.json', 'html:cucumber-report.html'],
formatOptions: { 'snippetInterface':'synchronous' },
publishQuiet: true
}
}
6 changes: 6 additions & 0 deletions features/is_it_akarsh_portfolio_website.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: Is it Akarsh portfolio website?

Scenario: Finding the title of the portfolio website
Given The website "akarsh.github.io" is available
When I navigate to "akarsh.github.io"
Then the page title should start with "Akarsh SEGGEMU"
49 changes: 49 additions & 0 deletions features/step_definitions/stepdefs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const { Given, When, Then, AfterAll } = require("@cucumber/cucumber");
const webdriver = require("selenium-webdriver");
const assert = require("assert");
const http2 = require("node:http2");

// Local development test
// let driver = new Builder()
// .forBrowser("chrome")
// .setChromeOptions(new chrome.Options().headless())
// .build();

let driver = new webdriver.Builder()
.forBrowser(webdriver.Browser.CHROME)
.usingServer("http://localhost:4444/wd/hub")
.build();

function isConnected(string) {
return new Promise((resolve) => {
const client = http2.connect("https://" + string);
client.on("connect", () => {
resolve(true);
client.destroy();
});
client.on("error", () => {
resolve(false);
client.destroy();
});
});
}

Given("The website {string} is available", async function (string) {
return await isConnected(string);
});

When("I navigate to {string}", async function (string) {
return await driver.get("https://" + string);
});

Then(
"the page title should start with {string}",
{ timeout: 60 * 1000 },
async function (string) {
return assert((await driver.getTitle()) == "Akarsh SEGGEMU");
}
);

AfterAll(async function () {
await driver.quit();
});
Loading