CodeceptJS icon indicating copy to clipboard operation
CodeceptJS copied to clipboard

Cannot read property 'browser' of undefined using custom helper methods

Open andreluizbnu opened this issue 9 years ago • 3 comments

What are you trying to achieve?

Im using WebDriverIO as default helper and im trying to create a custom helper using Nightmare methods. Returning browser undefined when executing the custom action.

What do you get instead?

I.refreshPage();

  • I refresh page FAIL Cannot read property 'browser' of undefined
'use strict';

class SampleHelper extends Helper {

  refreshPage() {
    const browser = this.helpers['Nightmare'].browser;

    return browser.refresh();
  }
}

module.exports = SampleHelper;

Details

  • CodeceptJS version: 1.0.2
  • NodeJS Version: v6.11.0
  • Operating System: Windows 10
  • Protractor || WebDriverIO || Nightmare version (if related) WebDriverIO / Nightmare
  • Configuration file:
{
  "output": "./output",
  "helpers": {
    "WebDriverIO": {
      "smartWait": 5000,
      "browser": "chrome",
      "url": "/",
      "restart": false,
      "keepCookies": true,
      "windowSize": "maximize",
      "timeouts": {
        "script": 60000,
        "page load": 10000
      }
    },
    "SampleHelper": {
      "require": "./samplehelper_helper.js"
    }
  },
  "include": {
    "I": "./steps_file.js",
    "fcx": "./pages/fcx.js",
    "gpo": "./pages/gpo.js"
  },
  "mocha": {
    "reporterOptions": {
      "codeceptjs-cli-reporter": {
        "stdout": "-",
        "options": {
          "verbose": false,
          "steps": true
        }
      },
      "mocha-junit-reporter": {
        "stdout": "./output/console.log",
        "options": {
          "reportDir": "./output",
          "reportFilename": "./output/test-results.xml"
        }
      }
    }
  },
  "bootstrap": false,
  "teardown": "./sincronizador.js",
  "hooks": [],
  "tests": "tests/*/*/*/*.js",
  "timeout": 10000
}

andreluizbnu avatar Aug 29 '17 20:08 andreluizbnu

@sivnz You didn't add Nightmare helper to config, because of this you can't get accexx to nightmare browser. FYI you have to choose one helper WebdriverIO or Nightmare, not both. Also there is default refresh methods for Nightmare and WebdriverIO

Hope it helps!

APshenkin avatar Aug 30 '17 08:08 APshenkin

Close due inactivity

APshenkin avatar Sep 05 '17 19:09 APshenkin

I have the similar issue however I was using WebdriverIO in both my config file and where I define my custom helper.

New issue submitted here: https://github.com/Codeception/CodeceptJS/issues/702

ZozoZoeLi avatar Sep 06 '17 21:09 ZozoZoeLi