Search code examples
node.jsacceptance-testingcodeceptjs

codeceptjs - Error: Couldn't connect to selenium server / A session id is required for this command but wasn't found in the response payload


I used this quick start guide to install this test framework: https://github.com/codeception/codeceptjs/ .

After successful installation I edited my "mytest_test.js" with following additions:

Feature('CodeceptJS Demonstration');

Scenario('test some forms', (I) => {
  I.amOnPage('http://simple-form-bootstrap.plataformatec.com.br/documentation');
  I.fillField('Email', 'hello@world.com');
  I.fillField('Password', '123456');
  I.checkOption('Active');
  I.checkOption('Male');
  I.click('Create User');
  I.see('User is valid');
  I.dontSeeInCurrentUrl('/documentation');
});

Afterwards I started my test:

codeceptjs run --debug

My results are:

C:\laragon\www\codeceptjs2  (codeceptjs2@1.0.0) 31.01.2017 10:46:30,41                       
λ codeceptjs run --debug                                                                     
CodeceptJS v0.4.16                                                                           
Using test root "C:\laragon\www\codeceptjs2"                                                 

CodeceptJS Demonstration --                                                                  
 test some forms                                                                             
 > Error: Couldn't connect to selenium server                                                
 * I am on page "http://simple-form-bootstrap.plataformatec.com.br/documentation"            
 > Screenshot has been saved to C:\laragon\www\codeceptjs2\output\test_some_forms.failed.png 
 > Error: A session id is required for this command but wasn't found in the response payload 

I don't get any screenshots in the output folder and this framework doesn't work and I don't understand why.

package.json

{
  "name": "codeceptjs2",
  "version": "1.0.0",
  "description": "",
  "main": "mytest_test.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "codeceptjs": "^0.4.16",
    "selenium-webdriver": "^3.0.1",
    "webdriverio": "^4.6.2"
  }
}

codecept.json

{
  "tests": "./*_test.js",
  "timeout": 10000,
  "output": "./output",
  "helpers": {
    "WebDriverIO": {
      "url": "http://localhost",
      "browser": "firefox"
    }
  },
  "include": {
    "I": "./steps_file.js"
  },
  "bootstrap": false,
  "mocha": {},
  "name": "codeceptjs2"
}

steps_file.js

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

module.exports = function() {
  return actor({

    // Define custom steps here, use 'this' to access default methods of I.
    // It is recommended to place a general 'login' function here.

  });
}

Solution

  • For a quickstart with CodeceptJs I would recommend you to use Nightmare helper. So in codecept.conf you should have something similar to this

    'helpers': {
            'Nightmare': {
                'url': 'http://localhost:3000',
                'waitForTimeout': 10000,
                'show': false
            }
        },
    

    And don't forget to install nightmare

     npm install --save-dev nightmare nightmare-upload