New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After block not properly executed if Scenario fails #543

Closed
SuneRadich opened this Issue May 31, 2017 · 0 comments

Comments

Projects
None yet
2 participants
@SuneRadich

SuneRadich commented May 31, 2017

What are you trying to achieve?

Run logout logic in an After block for each Scenario, also on Scenarios that fail

What do you get instead?

My After block logic is not run for the test that fails. It console.logs my debug statement, so the After block is called, but the steps are not executed. Maybe because Teardown has already been started?

Provide console output if related. Use --verbose mode for more details.

codeceptjs run --verbose --debug
CodeceptJS v0.6.3
Using test root "/Users/srv/Documents/Projects/nlpgmc"

POC --
   [1] Starting recording promises
   Emitted | suite.before ([object Object])
   [1] Queued | hook Protractor._beforeSuite()
 test something #1
 > [Session] Starting singleton browser session
   [2] Starting recording promises
   Emitted | test.before
   [2] Queued | hook Protractor._before()
LOGIN!
   Emitted | step.before (I am on page "/#/welcome")
   [2] Queued | amOnPage: "/#/welcome"
   Emitted | step.after (I am on page "/#/welcome")
   [2] Queued | return step result
   Emitted | step.before (I click ".button--primary")
   [2] Queued | click: ".button--primary"
   Emitted | step.after (I click ".button--primary")
   [2] Queued | return step result
   Emitted | step.before (I click {"css":"titlebar .align-left button"})
   [2] Queued | click: {"css":"titlebar .align-left button"}
   Emitted | step.after (I click {"css":"titlebar .align-left button"})
   [2] Queued | return step result
   Emitted | step.before (I click "Log på med testbruger")
   [2] Queued | click: "Log på med testbruger"
   Emitted | step.after (I click "Log på med testbruger")
   [2] Queued | return step result
   Emitted | step.before (I fill field ".ghostInput", "0801541089")
   [2] Queued | fillField: ".ghostInput", "0801541089"
   Emitted | step.after (I fill field ".ghostInput", "0801541089")
   [2] Queued | return step result
   Emitted | step.before (I click "Next")
   [2] Queued | click: "Next"
   Emitted | step.after (I click "Next")
   [2] Queued | return step result
   Emitted | step.before (I click "No, enter this later")
   [2] Queued | click: "No, enter this later"
   Emitted | step.after (I click "No, enter this later")
   [2] Queued | return step result
   Emitted | step.before (I wait for text "Savings", 5, "h1")
   [2] Queued | waitForText: "Savings", 5, "h1"
   Emitted | step.after (I wait for text "Savings", 5, "h1")
   [2] Queued | return step result
   Emitted | step.start (I am on page "/#/welcome")
 • I am on page "/#/welcome"
   Emitted | step.start (I click ".button--primary")
 • I click ".button--primary"
   Emitted | step.start (I click {"css":"titlebar .align-left button"})
 • I click {"css":"titlebar .align-left button"}
   Emitted | step.start (I click "Log på med testbruger")
 • I click "Log på med testbruger"
   Emitted | step.start (I fill field ".ghostInput", "0801541089")
 • I fill field ".ghostInput", "0801541089"
   Emitted | step.start (I click "Next")
 • I click "Next"
   Emitted | step.start (I click "No, enter this later")
 • I click "No, enter this later"
   Emitted | step.start (I wait for text "Savings", 5, "h1")
 • I wait for text "Savings", 5, "h1"
   Emitted | test.start ([object Object])
   Emitted | step.before (I see in current url "/overview/savings")
   [2] Queued | seeInCurrentUrl: "/overview/savings"
   Emitted | step.after (I see in current url "/overview/savings")
   [2] Queued | return step result
   Emitted | step.before (I see "Savings", ".bottom-nav")
   [2] Queued | see: "Savings", ".bottom-nav"
   Emitted | step.after (I see "Savings", ".bottom-nav")
   [2] Queued | return step result
   Emitted | step.before (I see "Disbursement", ".bottom-nav")
   [2] Queued | see: "Disbursement", ".bottom-nav"
   Emitted | step.after (I see "Disbursement", ".bottom-nav")
   [2] Queued | return step result
   Emitted | step.before (I see "Insurance", ".bottom-nav")
   [2] Queued | see: "Insurance", ".bottom-nav"
   Emitted | step.after (I see "Insurance", ".bottom-nav")
   [2] Queued | return step result
   [2] Queued | fire test.passed
   [2] Queued | finish test
   Emitted | step.start (I see in current url "/overview/savings")
 • I see in current url "/overview/savings"
   Emitted | step.start (I see "Savings", ".bottom-nav")
 • I see "Savings", ".bottom-nav"
   Emitted | step.start (I see "Disbursement", ".bottom-nav")
 • I see "Disbursement", ".bottom-nav"
   Emitted | step.start (I see "Insurance", ".bottom-nav")
 • I see "Insurance", ".bottom-nav"
   Emitted | test.passed ([object Object])
 ✓ OK in 200ms

   Emitted | test.after
   [2] Queued | hook Protractor._after()
LOGOUT!
   Emitted | step.before (I click {"css":"titlebar .align-right button"})
   [2] Queued | click: {"css":"titlebar .align-right button"}
   Emitted | step.after (I click {"css":"titlebar .align-right button"})
   [2] Queued | return step result
   Emitted | step.before (I click "Log out")
   [2] Queued | click: "Log out"
   Emitted | step.after (I click "Log out")
   [2] Queued | return step result
 > [Session] cleaning cookies and localStorage
   Emitted | step.start (I click {"css":"titlebar .align-right button"})
 • I click {"css":"titlebar .align-right button"}
   Emitted | step.start (I click "Log out")
 • I click "Log out"
 test something #2
   [3] Starting recording promises
   Emitted | test.before
   [3] Queued | hook Protractor._before()
LOGIN!
   Emitted | step.before (I am on page "/#/welcome")
   [3] Queued | amOnPage: "/#/welcome"
   Emitted | step.after (I am on page "/#/welcome")
   [3] Queued | return step result
   Emitted | step.before (I click ".button--primary")
   [3] Queued | click: ".button--primary"
   Emitted | step.after (I click ".button--primary")
   [3] Queued | return step result
   Emitted | step.before (I click {"css":"titlebar .align-left button"})
   [3] Queued | click: {"css":"titlebar .align-left button"}
   Emitted | step.after (I click {"css":"titlebar .align-left button"})
   [3] Queued | return step result
   Emitted | step.before (I click "Log på med testbruger")
   [3] Queued | click: "Log på med testbruger"
   Emitted | step.after (I click "Log på med testbruger")
   [3] Queued | return step result
   Emitted | step.before (I fill field ".ghostInput", "0801541089")
   [3] Queued | fillField: ".ghostInput", "0801541089"
   Emitted | step.after (I fill field ".ghostInput", "0801541089")
   [3] Queued | return step result
   Emitted | step.before (I click "Next")
   [3] Queued | click: "Next"
   Emitted | step.after (I click "Next")
   [3] Queued | return step result
   Emitted | step.before (I click "No, enter this later")
   [3] Queued | click: "No, enter this later"
   Emitted | step.after (I click "No, enter this later")
   [3] Queued | return step result
   Emitted | step.before (I wait for text "Savings", 5, "h1")
   [3] Queued | waitForText: "Savings", 5, "h1"
   Emitted | step.after (I wait for text "Savings", 5, "h1")
   [3] Queued | return step result
   Emitted | step.start (I am on page "/#/welcome")
 • I am on page "/#/welcome"
   Emitted | step.start (I click ".button--primary")
 • I click ".button--primary"
   Emitted | step.start (I click {"css":"titlebar .align-left button"})
 • I click {"css":"titlebar .align-left button"}
   Emitted | step.start (I click "Log på med testbruger")
 • I click "Log på med testbruger"
   Emitted | step.start (I fill field ".ghostInput", "0801541089")
 • I fill field ".ghostInput", "0801541089"
   Emitted | step.start (I click "Next")
 • I click "Next"
   Emitted | step.start (I click "No, enter this later")
 • I click "No, enter this later"
   Emitted | step.start (I wait for text "Savings", 5, "h1")
 • I wait for text "Savings", 5, "h1"
   Emitted | test.start ([object Object])
   Emitted | step.before (I see "SavingsMEFFE", ".bottom-nav")
   [3] Queued | see: "SavingsMEFFE", ".bottom-nav"
   Emitted | step.after (I see "SavingsMEFFE", ".bottom-nav")
   [3] Queued | return step result
   [3] Queued | fire test.passed
   [3] Queued | finish test
   Emitted | step.start (I see "SavingsMEFFE", ".bottom-nav")
 • I see "SavingsMEFFE", ".bottom-nav"
   [3] Error | Error
   [3] Starting <teardown> session
   Emitted | test.failed ([object Object])
   [3] <teardown> Queued | hook Protractor._failed()
   [3] <teardown> Queued | () => done(err)
   [3] <teardown> Stopping recording promises
 > Screenshot has been saved to /Users/srv/Documents/Projects/nlpgmc/UITest/output/test_something_#2.failed.png
 ✖ FAILED in 558ms

   Emitted | test.after
   [3] <teardown> Queued | hook Protractor._after()
LOGOUT!
   Emitted | step.before (I click {"css":"titlebar .align-right button"})
   Emitted | step.after (I click {"css":"titlebar .align-right button"})
   Emitted | step.before (I click "Log out")
   Emitted | step.after (I click "Log out")
 > [Session] cleaning cookies and localStorage
 test something #3
   [4] Starting recording promises
   Emitted | test.before
   [4] Queued | hook Protractor._before()
LOGIN!
   Emitted | step.before (I am on page "/#/welcome")
   [4] Queued | amOnPage: "/#/welcome"
   Emitted | step.after (I am on page "/#/welcome")
   [4] Queued | return step result
   Emitted | step.before (I click ".button--primary")
   [4] Queued | click: ".button--primary"
   Emitted | step.after (I click ".button--primary")
   [4] Queued | return step result
   Emitted | step.before (I click {"css":"titlebar .align-left button"})
   [4] Queued | click: {"css":"titlebar .align-left button"}
   Emitted | step.after (I click {"css":"titlebar .align-left button"})
   [4] Queued | return step result
   Emitted | step.before (I click "Log på med testbruger")
   [4] Queued | click: "Log på med testbruger"
   Emitted | step.after (I click "Log på med testbruger")
   [4] Queued | return step result
   Emitted | step.before (I fill field ".ghostInput", "0801541089")
   [4] Queued | fillField: ".ghostInput", "0801541089"
   Emitted | step.after (I fill field ".ghostInput", "0801541089")
   [4] Queued | return step result
   Emitted | step.before (I click "Next")
   [4] Queued | click: "Next"
   Emitted | step.after (I click "Next")
   [4] Queued | return step result
   Emitted | step.before (I click "No, enter this later")
   [4] Queued | click: "No, enter this later"
   Emitted | step.after (I click "No, enter this later")
   [4] Queued | return step result
   Emitted | step.before (I wait for text "Savings", 5, "h1")
   [4] Queued | waitForText: "Savings", 5, "h1"
   Emitted | step.after (I wait for text "Savings", 5, "h1")
   [4] Queued | return step result
   Emitted | step.start (I am on page "/#/welcome")
 • I am on page "/#/welcome"
   Emitted | step.start (I click ".button--primary")
 • I click ".button--primary"
   [4] Error | NoSuchElementError: No element found using locator: By(css selector, .button--primary)
   Emitted | test.failed ([object Object])
   [4] Queued | hook Protractor._failed()
 ✖ "before each" hook: Before for "test something #3" in 3151ms
   [4] Error | NoSuchElementError: No element found using locator: By(css selector, .button--primary)
NoSuchElementError: No element found using locator: By(css selector, .button--primary)
   [4] Stopping recording promises
   Emitted | test.after
   [4] Queued | hook Protractor._after()
LOGOUT!
   Emitted | step.before (I click {"css":"titlebar .align-right button"})
   Emitted | step.after (I click {"css":"titlebar .align-right button"})
   Emitted | step.before (I click "Log out")
   Emitted | step.after (I click "Log out")
 > [Session] cleaning cookies and localStorage
   [5] Starting recording promises
   Emitted | suite.after ([object Object])
   [5] Queued | hook Protractor._afterSuite()

-- FAILURES:

  1) POC: test something #2:

      expected element .bottom-nav to include "SavingsMEFFE"
      + expected - actual

      -| Savings
      -Disbursement
      -Insurance
      +SavingsMEFFE
      
  
  Scenario Steps:
  
  - I.see("SavingsMEFFE", ".bottom-nav") at Test.Scenario (UITest/tests/dummy_test.js:19:4)
  
  Error
      at /Users/srv/.nvm/versions/node/v6.10.3/lib/node_modules/codeceptjs-protractor/node_modules/codeceptjs/lib/helper/SeleniumWebdriver.js:801:51
      at next (native)
      at onFulfilled (/Users/srv/.nvm/versions/node/v6.10.3/lib/node_modules/codeceptjs-protractor/node_modules/co/index.js:65:19)
      at process._tickCallback (internal/process/next_tick.js:109:7)

  2) POC "before each" hook: Before for "test something #3":
     No element found using locator: By(css selector, .button--primary)
  oSuchElementError: No element found using locator: By(css selector, .button--primary)
      at WebDriverError (/Users/srv/.nvm/versions/node/v6.10.3/lib/node_modules/codeceptjs-protractor/node_modules/selenium-webdriver/lib/error.js:27:5)
      at NoSuchElementError (/Users/srv/.nvm/versions/node/v6.10.3/lib/node_modules/codeceptjs-protractor/node_modules/selenium-webdriver/lib/error.js:168:5)
      at elementArrayFinder.getWebElements.then (/Users/srv/.nvm/versions/node/v6.10.3/lib/node_modules/codeceptjs-protractor/node_modules/protractor/built/element.js:814:27)
      at ManagedPromise.invokeCallback_ (/Users/srv/.nvm/versions/node/v6.10.3/lib/node_modules/codeceptjs-protractor/node_modules/selenium-webdriver/lib/promise.js:1366:14)
      at TaskQueue.execute_ (/Users/srv/.nvm/versions/node/v6.10.3/lib/node_modules/codeceptjs-protractor/node_modules/selenium-webdriver/lib/promise.js:2970:14)
      at TaskQueue.executeNext_ (/Users/srv/.nvm/versions/node/v6.10.3/lib/node_modules/codeceptjs-protractor/node_modules/selenium-webdriver/lib/promise.js:2953:27)
      at asyncRun (/Users/srv/.nvm/versions/node/v6.10.3/lib/node_modules/codeceptjs-protractor/node_modules/selenium-webdriver/lib/promise.js:2813:27)
      at /Users/srv/.nvm/versions/node/v6.10.3/lib/node_modules/codeceptjs-protractor/node_modules/selenium-webdriver/lib/promise.js:676:7
      at process._tickCallback (internal/process/next_tick.js:109:7)


  FAIL  | 1 passed, 2 failed   // 32s
   Emitted | global.result ([object Object])

Provide test source code if related

// my steps
'use strict';
// in this file you can append custom step methods to 'I' object

module.exports = function() {

	return actor({

		login: function() {
			console.log('LOGIN!')

			this.amOnPage('/#/welcome');
			this.click('.button--primary');
			this.click({ css: 'titlebar .align-left button' } );
			this.click('Log på med testbruger');
			this.fillField('.ghostInput', '0801541089');
			this.click('Next');
			this.click('No, enter this later');
			this.waitForText('Savings', 5, 'h1');
		},

		logout: function() {
			console.log('LOGOUT!')
			this.click({ css: 'titlebar .align-right button' } );
			this.click('Log out');

		}

  });
}

//my tests
Feature('POC');

Before((I) => {
	I.login();
});

After((I) => {
	I.logout();
});

Scenario('test something #1', (I) => {
	I.seeInCurrentUrl('/overview/savings');
	I.see('Savings', '.bottom-nav');
	I.see('Disbursement', '.bottom-nav');
	I.see('Insurance', '.bottom-nav');
});

Scenario('test something #2', (I) => {
	I.see('SavingsMEFFE', '.bottom-nav');

});

Scenario('test something #3', (I) => {
	I.amOnPage('/#/overview/savings');
	I.see('Savings', '.bottom-nav');
	I.see('Disbursement', '.bottom-nav');
	I.see('Insurance', '.bottom-nav');
});

Details

  • CodeceptJS version: 0.6.3
  • NodeJS Version: 6.10.3
  • Operating System: OSX
  • Protractor || WebDriverIO || Nightmare version (if related) Protractor 5.1.2
  • Configuration file:
exports.config = {
	"tests": "./UITest/tests/*_test.js",
	"timeout": 10000,
	"output": "./UITest/output",
	"helpers": {
		"Protractor": {
			'url': 'http://localhost:8080',
			'driver': 'hosted',
			"browser": "chrome",
			"rootElement": "body"
		}
	},
	"include": {
		"I": "./UITest/steps_file.js"
	},
	"bootstrap": false,
	"mocha": {},
	"name": "POC"
}

@APshenkin APshenkin referenced this issue Jun 22, 2017

Merged

Fix work with promise chains #568

10 of 10 tasks complete

@APshenkin APshenkin added the bug label Jun 28, 2017

@DavertMik DavertMik closed this in #568 Jun 28, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment