Skip to content
Draft
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
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run test -- --tags "@google" --retry 2 --parallel 4
- run: npm run test -- --tags "@fail" --retry 2 --parallel 4
env:
NIGHTWATCH_HEADLESS: true
CUCUMBER_PUBLISH_ENABLED: true
CN_DEBUG: true
NIGHTWATCH_OUTPUT: true

test-serial:
runs-on: ubuntu-latest
Expand All @@ -46,8 +47,9 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run test -- --tags "@google"
- run: npm run test -- --tags "@fail"
env:
NIGHTWATCH_HEADLESS: true
CUCUMBER_PUBLISH_ENABLED: true
CN_DEBUG: true
NIGHTWATCH_OUTPUT: true
4 changes: 4 additions & 0 deletions features/googleSearch.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Background: Background name
Given I open the url "https://google.com"
Then I expect that the title is "Google"

@fail
Scenario: should fail
When I looking for a not existing element

@google
Scenario: Searching Google for Nightwatch
When I set "nightwatchjs" to the inputfield "input[name=q]"
Expand Down
32 changes: 31 additions & 1 deletion features/step_definitions/steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ When(
}
)

When(/^I press "([^"]*)?"$/, async function (key: string) {
When(/^I press "([^"]*)?"$/, async function (this: World, key: string) {
/* eslint-disable @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-return */
await this.browser!.perform(function (this: any) {
const actions = this.actions({ async: true })
Expand All @@ -22,6 +22,36 @@ When(/^I press "([^"]*)?"$/, async function (key: string) {
/* eslint-enable @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-return */
})

When(/^I looking for a not existing element$/, async function (this: World) {
try {
// These won't throw an error
await this.browser!.waitForElementVisible(
'#not-existing-element',
1000,
0,
true,
function (result) {
console.log('result', result)
}
)
await this.browser!.waitForElementPresent(
'css selector',
'#not-existing-element'
)
// await this.browser!.click('#not-existing-element')
// await this.browser!.ensure.elementIsVisible('#not-existing-element')

// Below works fine
// await this.browser!.expect.element('#not-existing-element').to.be.present;
// await this.browser!.expect.element('#not-existing-element').to.be.visible;
// await this.browser!.assert.visible('#not-existing-element')
console.log('No error has been caught')
} catch (error) {
console.log('We expect error from failed command: ', error)
throw new Error('Expected error has been caught')
}
})

Then(
/^I expect that the title is( not)* "([^"]*)?"$/,
function (this: World, negativeCase: string, expectedTitle: string) {
Expand Down
2 changes: 1 addition & 1 deletion features/support/NightwatchWorld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const nightwatchClient = function () {
output: process.env.NIGHTWATCH_OUTPUT === 'true',
silent: !(process.env.NIGHTWATCH_SILENT === 'false'), // set to false to enable verbose logging
browserName: process.env.NIGHTWATCH_BROWSER, // can be either: firefox, chrome, safari, or edge

always_async_commands: true,
// set the global timeout to be used with waitFor commands and when retrying assertions/expects
timeout: process.env.NIGHTWATCH_TIMEOUT || 10000,

Expand Down
149 changes: 22 additions & 127 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@types/node": "^18.11.7",
"@typescript-eslint/eslint-plugin": "^5.43.0",
"@typescript-eslint/parser": "^5.43.0",
"chromedriver": "^106.0.0",
"chromedriver": "^108.0.0",
"dotenv": "^16.0.3",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
Expand Down