Skip to content

Commit

Permalink
Add tests in nightwatch framework
Browse files Browse the repository at this point in the history
  • Loading branch information
SwikritiT committed Dec 3, 2021
1 parent 78526a4 commit 79b3a2a
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 1 deletion.
17 changes: 17 additions & 0 deletions nightwatch.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const LAUNCH_URL = process.env.LAUNCH_URL || 'http://localhost:3000';
module.exports = {
src_folders : ['tests'],
test_settings: {
default: {
launch_url: LAUNCH_URL,
selenium: {
start_process: false,
host: 'localhost',
port: 4444,
},
desiredCapabilities: {
browserName: 'chrome',
},
},
},
};
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
"eject": "react-scripts eject",
"test:e2e": "cucumber-js --require tests/acceptance/cucumber.conf.js --require tests/acceptance/stepDefinitions"
},
"eslintConfig": {
"extends": [
Expand All @@ -34,5 +35,14 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@cucumber/cucumber": "^8.0.0-rc.1",
"@cucumber/pretty-formatter": "^1.0.0-alpha.1",
"chromedriver": "^96.0.0",
"geckodriver": "^2.0.4",
"nightwatch": "^1.7.12",
"nightwatch-api": "^3.0.2",
"selenium-server": "^3.141.59"
}
}
22 changes: 22 additions & 0 deletions tests/acceptance/cucumber.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const {setDefaultTimeout, BeforeAll, Before, AfterAll, After} = require('@cucumber/cucumber')
const {startWebDriver, stopWebDriver, createSession, closeSession} = require('nightwatch-api')

setDefaultTimeout(60000)



BeforeAll(async function (){
await startWebDriver({})
})

Before((async function(){
await createSession({})
}))

AfterAll(async function(){
await stopWebDriver()
})

After(async function(){
await closeSession()
})
9 changes: 9 additions & 0 deletions tests/acceptance/feature/todo.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Feature: todo
As a user
I want to add an item to the todo list
So that I can organize task

Scenario: Add item to the todo list
Given a user has navigated to the homepage
When the user adds "test" to the todo list using the webUI
Then card "test" should be displayed on the webUI
26 changes: 26 additions & 0 deletions tests/acceptance/stepDefinitions/todoContext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const {Given, When, Then} = require('@cucumber/cucumber')
const {client} = require('nightwatch-api')

//css selectors
const todoInputField = '.todo-input'
const todoCreateButton = '.todo-button'
const todoListItem = '.todo .todo-item'

Given('a user has navigated to the homepage', function () {
return client.url("http://localhost:3000");
});


When('the user adds {string} to the todo list using the webUI', async function (item) {
await client.waitForElementVisible(todoInputField)
.click(todoInputField)
.setValue(todoInputField, item)
.click(todoCreateButton)
return client
});

Then('card {string} should be displayed on the webUI', function (item) {
return client.getText(todoListItem, function (result) {
this.assert.equal(result.value, item)
})
});

0 comments on commit 79b3a2a

Please sign in to comment.