Skip to content

Commit

Permalink
demo the failure issue
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-yao committed Nov 25, 2022
1 parent 9ae0c2f commit e65f88f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
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

0 comments on commit e65f88f

Please sign in to comment.