webdriverio / webdriverio

Next-gen browser and mobile automation test framework for Node.js
http://webdriver.io
MIT License
9.06k stars 2.51k forks source link

step definitions are undefined #2583

Closed girishkumar517 closed 6 years ago

girishkumar517 commented 6 years ago

The problem

             I am using webdriverio+cucumber+nodejs.while executing feature files,in console it is displaying "step definitions are undefined

Environment

Link to Selenium/WebdriverIO logs

11:21:21.184 INFO - Selenium build info: version: '3.7.1', revision: '8a0099a' 11:21:21.185 INFO - Launching a standalone Selenium Server 2018-02-02 11:21:21.212:INFO::main: Logging initialized @355ms to org.seleniumhq.jetty9.util.log.StdErrLog 11:21:21.278 INFO - Driver class not found: com.opera.core.systems.OperaDriver 11:21:21.326 INFO - Driver provider class org.openqa.selenium.ie.InternetExplorerDriver registration is skipped: registration capabilities Capabilities {browserName: internet explorer, ensureCleanSession: true, platform: WINDOWS, version: } does not match the current platform MAC 11:21:21.326 INFO - Driver provider class org.openqa.selenium.edge.EdgeDriver registration is skipped: registration capabilities Capabilities {browserName: MicrosoftEdge, platform: WINDOWS, version: } does not match the current platform MAC 11:21:21.385 INFO - Using the passthrough mode handler 2018-02-02 11:21:21.418:INFO:osjs.Server:main: jetty-9.4.5.v20170502 2018-02-02 11:21:21.454:WARN:osjs.SecurityHandler:main: ServletContext@o.s.j.s.ServletContextHandler@458c1321{/,null,STARTING} has uncovered http methods for path: / 2018-02-02 11:21:21.458:INFO:osjsh.ContextHandler:main: Started o.s.j.s.ServletContextHandler@458c1321{/,null,AVAILABLE} 2018-02-02 11:21:21.519:INFO:osjs.AbstractConnector:main: Started ServerConnector@6c78a34e{HTTP/1.1,[http/1.1]}{0.0.0.0:4444} 2018-02-02 11:21:21.520:INFO:osjs.Server:main: Started @664ms 11:21:21.521 INFO - Selenium Server is up and running 2018-02-02 11:21:21.747:INFO:osjshC.ROOT:qtp1910163204-10: org.openqa.selenium.remote.server.WebDriverServlet-5ec0a365: Initialising WebDriverServlet 11:21:21.796 INFO - Found handler: org.openqa.selenium.remote.server.commandhandler.Status@f4cfcaf 11:21:21.800 INFO - /status: Executing GET on /status (handler: Status) 11:21:22.688 INFO - Found handler: org.openqa.selenium.remote.server.commandhandler.BeginSession@410c0d0b 11:21:22.688 INFO - /session: Executing POST on /session (handler: BeginSession) 11:21:22.762 INFO - Capabilities are: Capabilities {browserName: chrome, chromeOptions: {prefs: {credentials_enable_service: false, profile: {default_content_setting_values: {images: 2}, password_manager_enabled: false}}}, handlesAlerts: true, javascriptEnabled: true, locationContextEnabled: true, loggingPrefs: org.openqa.selenium.logging..., maxInstances: 1, proxy: {proxyType: system}, requestOrigins: {name: webdriverio, url: http://webdriver.io, version: 4.9.11}, rotatable: true} 11:21:22.766 INFO - Capabilities {browserName: chrome, chromeOptions: {prefs: {credentials_enable_service: false, profile: {default_content_setting_values: {images: 2}, password_manager_enabled: false}}}, handlesAlerts: true, javascriptEnabled: true, locationContextEnabled: true, loggingPrefs: org.openqa.selenium.logging..., maxInstances: 1, proxy: {proxyType: system}, requestOrigins: {name: webdriverio, url: http://webdriver.io, version: 4.9.11}, rotatable: true} matched class org.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService) Starting ChromeDriver 2.33.506106 (8a06c39c4582fbfbab6966dbb1c38a9173bfb1a2) on port 13184 Only local connections are allowed. 11:21:25.361 INFO - Detected dialect: OSS 11:21:30.888 INFO - Found handler: org.openqa.selenium.remote.server.ServicedSession@9f6a040 11:21:30.888 INFO - Handler thread for session 79efc34096bd9eaba0d734e421e08107 (chrome): Executing POST on /session/79efc34096bd9eaba0d734e421e08107/window/current/size (handler: ServicedSession) 11:21:30.892 INFO - To upstream: {"width":1280,"height":800} 11:21:30.913 INFO - Found handler: org.openqa.selenium.remote.server.ServicedSession@9f6a040 11:21:30.915 INFO - Handler thread for session 79efc34096bd9eaba0d734e421e08107 (chrome): Executing DELETE on /session/79efc34096bd9eaba0d734e421e08107/cookie (handler: ServicedSession) 11:21:31.022 INFO - To downstream: {"sessionId":"79efc34096bd9eaba0d734e421e08107","status":0,"value":null} 11:21:31.032 INFO - To downstream: {"sessionId":"79efc34096bd9eaba0d734e421e08107","status":0,"value":null} 11:21:31.038 INFO - Found handler: org.openqa.selenium.remote.server.ServicedSession@9f6a040 11:21:31.038 INFO - Handler thread for session 79efc34096bd9eaba0d734e421e08107 (chrome): Executing DELETE on /session/79efc34096bd9eaba0d734e421e08107 (handler: ServicedSession) 11:21:31.092 INFO - To downstream: {"sessionId":"79efc34096bd9eaba0d734e421e08107","status":0,"value":null} 11:21:31.143 INFO - Removing session org.openqa.selenium.remote.server.ServicedSession@9f6a040

Code To Reproduce Issue [ Good To Have ]

'use strict';

const fs = require('fs-extra'); const path = require('path');

const getAllFilesIn = function (dir, filelist) { let files = filelist || []; const dirFiles = fs.readdirSync(dir); dirFiles.forEach(function (file) { if (fs.statSync(path.join(dir, file)).isDirectory()) { files = getAllFilesIn(path.join(dir, file), files); } else { files.push('./' + path.join(dir, file)); } });

return files; };

const cucumberOptsRequire = getAllFilesIn('./src/step-definitions').concat([ './src/support/world.js', './src/support/hooks.js', ]);

exports.config = { // ================== // Specify Test Files // ================== // Define which test specs should run. The pattern is relative to the directory // from which wdio was called. Notice that, if you are calling wdio from an // NPM script (see https://docs.npmjs.com/cli/run-script) then the current working // directory is where your package.json resides, so wdio will be called from there. specs: [ './src/features/*/.feature', ],

// Patterns to exclude. // exclude: [ // 'path/to/excluded/files' // ],

// ============ // Capabilities // ============ // Define your capabilities here. WebdriverIO can run multiple capabilities at the same // time. Depending on the number of capabilities, WebdriverIO launches several test // sessions. Within your capabilities you can overwrite the spec and exclude options in // order to group specific specs to a specific capability. // // First, you can define how many instances should be started at the same time. Let's // say you have 3 different capabilities (Chrome, Firefox, and Safari) and you have // set maxInstances to 1; wdio will spawn 3 processes. Therefore, if you have 10 spec // files and you set maxInstances to 10, all spec files will get tested at the same time // and 30 processes will get spawned. The property handles how many capabilities // from the same test should run tests. // maxInstances: 1,

// If you have trouble getting all important capabilities together, check out the // Sauce Labs platform configurator - a great tool to configure your capabilities: // https://docs.saucelabs.com/reference/platforms-configurator // capabilities: [ { // maxInstances can get overwritten per capability. So if you have an in-house Selenium // grid with only 5 firefox instance available you can make sure that not more than // 5 instance gets started at a time. maxInstances: 1,

  browserName: 'chrome',
  chromeOptions: {
    // args: ['--headless'], // To run in headless mode
    prefs: {
      profile: {
        default_content_setting_values: { images: 2 }, // Do not load images for tests to run faster
        password_manager_enabled: false, // Deactivate password manager
      },
      credentials_enable_service: false, // Deactivate password manager
    },
  },

  proxy: {
    proxyType: 'system',
  },
},

// {
//   maxInstances: 1,
//
//   browserName: 'firefox',
//   acceptInsecureCerts: true,
//
//   proxy: {
//     proxyType: 'system',
//   },
//
// },

],

// =================== // Test Configurations // =================== // Define all options that are relevant for the WebdriverIO instance here // // By default WebdriverIO commands are executed in a synchronous way using // the wdio-sync package. If you still want to run your tests in an async way // e.g. using promises you can set the sync option to false. sync: false,

// Level of logging verbosity: silent | verbose | command | data | result | error logLevel: 'error', logOutput: './log',

// Enables colors for log output. coloredLogs: true,

// Saves a screenshot to a given path if a command fails. //screenshotPath: './errorShots/', // // Set a base URL in order to shorten url command calls. If your url parameter starts // with "/", then the base url gets prepended. baseUrl: 'http://localhost:8080',

// Default timeout for all waitFor* commands. waitforTimeout: 10000,

// Default timeout in milliseconds for request // if Selenium Grid doesn't send response connectionRetryTimeout: 90000,

// Default request retries count connectionRetryCount: 0,

// Initialize the browser instance with a WebdriverIO plugin. The object should have the // plugin name as key and the desired plugin options as properties. Make sure you have // the plugin installed before running any tests. The following plugins are currently // available: // WebdriverCSS: https://github.com/webdriverio/webdrivercss // WebdriverRTC: https://github.com/webdriverio/webdriverrtc // Browserevent: https://github.com/webdriverio/browserevent // plugins: { // webdrivercss: { // screenshotRoot: 'my-shots', // failedComparisonsRoot: 'diffs', // misMatchTolerance: 0.05, // screenWidth: [320,480,640,1024] // }, // webdriverrtc: {}, // browserevent: {} // }, // // Test runner services // Services take over a specific job you don't want to take care of. They enhance // your test setup with almost no effort. Unlike plugins, they don't add new // commands. Instead, they hook themselves up into the test process. services: ['selenium-standalone'], seleniumLogs: './log/selenium.log', port: '4444',

seleniumInstallArgs: { // proxy: 'http://localhost:3128', },

// Framework you want to run your specs with. // The following are supported: Mocha, Jasmine, and Cucumber // see also: http://webdriver.io/guide/testrunner/frameworks.html // // Make sure you have the wdio adapter package for the specific framework installed // before running any tests. framework: 'cucumber',

// Test reporter for stdout. // The only one supported by default is 'dot' // see also: http://webdriver.io/guide/testrunner/reporters.html reporters: ['cucumber', 'junit', 'json', 'allure'], reporterOptions: { json: { outputDir: 'output/json', }, junit: { outputDir: 'output/junit-results', }, allure: { outputDir: 'output/allure', }, },

// If you are using Cucumber you need to specify the location of your step definitions. cucumberOpts: {

// DO NOT REQUIRE scripts that should be included and executed at runtime,
// otherwise there will be loaded and executed first and will raise weird issues.
require: cucumberOptsRequire,

// <boolean> show full backtrace for errors
backtrace: true,

// <string[]> ("extension:module") require files with the given EXTENSION after requiring MODULE (repeatable)
compiler: [],

// <boolean> invoke formatters without executing steps
dryRun: false,

// <boolean> abort the run on first failure
failFast: false,

// <string[]> (type[:path]) specify the output format, optionally supply PATH to redirect formatter output (repeatable)
format: 'pretty',

// <boolean> disable colors in formatter output
colors: true,

// <boolean> hide step definition snippets for pending steps
snippets: true,

// <boolean> hide source uris
source: true,

// <string[]> (name) specify the profile to use
profile: [],

// <boolean> fail if there are any undefined or pending steps
strict: false,

// <tag-expression> only execute the features or scenarios with tags matching the expression
// tagExpression: '@smoke',

// <number> timeout for step definitions
timeout: 30000,

// <boolean> Enable this config to treat undefined definitions as warnings.
ignoreUndefinedDefinitions: false,

},

// Size of the browser window windowHandleSize: { height: 800, width: 1280, },

// Additional timeouts. See http://webdriver.io/guide/testrunner/timeouts.html for more details timeouts: { script: 3000, implicit: 3000, },

// ===== // Hooks // ===== // WebdriverIO provides several hooks you can use to interfere with the test process in order to enhance // it and to build services around it. You can either apply a single function or an array of // methods to it. If one of them returns with a promise, WebdriverIO will wait until that promise got // resolved to continue. // // Gets executed once before all workers get launched. // onPrepare: function (config, capabilities) { // }, // // Gets executed before test execution begins. At this point you can access all global // variables, such as browser. It is the perfect place to define custom commands. before() { browser.windowHandleSize({ width: browser.options.windowHandleSize.width, height: browser.options.windowHandleSize.height, }); },

// Hook that gets executed before the suite starts // beforeSuite: function (suite) { // }, // // Hook that gets executed before a hook within the suite starts (e.g. runs before calling // beforeEach in Mocha) // beforeHook: function () { // }, // // Hook that gets executed after a hook within the suite starts (e.g. runs after calling // afterEach in Mocha) // afterHook: function () { // }, // // Function to be executed before a test (in Mocha/Jasmine) or a step (in Cucumber) starts. // beforeTest: function (test) { // }, // // Runs before a WebdriverIO command gets executed. // beforeCommand: function (commandName, args) { // }, // // Runs after a WebdriverIO command gets executed // afterCommand: function (commandName, args, result, error) { // }, // // Function to be executed after a test (in Mocha/Jasmine) or a step (in Cucumber) starts. // afterTest: function (test) { // }, // // Hook that gets executed after the suite has ended // afterSuite: function (suite) { // }, // // Gets executed after all tests are done. You still have access to all global variables from // the test. // after: function (result, capabilities, specs) { // }, // // Gets executed after all workers got shut down and the process is about to exit. It is not // possible to defer the end of the process using a promise. // onComplete: function(exitCode) { // }

};

feature files

Feature: Login a content manager

Scenario: Successful login with valid credentials from the user menu Given I am a content manager When I log in from login page with valid credentials

step definitions

'use strict'; require('src/support/business-object/login.bo'); /const dataObject = require('src/support/data/user.data');/

module.exports = function () { this.Given(/^I am a content manager$/, function () { console.log("IN first"); /*return browser.url('http://shield:3$87uOjb71oj@hn2.nestledsu.acsitefactory.com/user/login/').url('/');**/ return browser.url('http://hn2.nestledsu.acsitefactory.com/user/login/').url('/');

});

this.When(/^I log in from login page with valid credentials$/, function () { console.log("IN Second"); return browser.loginUser(); });

/this.Then(/^I should be a logged$/, function () { return browser.seeLoggedFromPage(); });/ };

christian-bromann commented 6 years ago

Sorry but I have to close this. I have no idea what error you are experiencing. If you have a reproducible example create a git repo where I can look into it. Also join our Gitter if you have questions.