Skip to content
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

Basic Test doesn't work #20

Closed
cliff76 opened this issue May 1, 2016 · 2 comments
Closed

Basic Test doesn't work #20

cliff76 opened this issue May 1, 2016 · 2 comments

Comments

@cliff76
Copy link

cliff76 commented May 1, 2016

Hi,

I am trying to get a basic test working as per the documentation. I've copied/pasted from the README and adjusted my path to point to the Electron executable but I get a test failure. Here's my test code:

/**
 * Created by Clifton Craig on 4/30/16.
 */
describe('Initial spec', function () {
    it('Should be easy to test.');
});

var Application = require('spectron').Application;
var assert = require('assert');

describe('application launch', function () {
    this.timeout(10000);

    beforeEach(function () {
        this.app = new Application({
            path: '/Applications/Electron.app/Contents/MacOS/Electron'
        });
        return this.app.start()
    });

    afterEach(function () {
        if (this.app && this.app.isRunning()) {
            return this.app.stop()
        }
    });

    it('shows an initial window', function () {
        return this.app.client.getWindowCount().then(function (count) {
            assert.equal(count, 1)
        })
    })
});

And here's the output:

SFO1212474815A:nightmare 212474815$ npm test

> nightmare@1.0.0 test /Users/212474815/dev/nightmare
> mocha



  Initial spec
    - Should be easy to test.

  application launch
    1) "before each" hook for "shows an initial window"


  0 passing (5s)
  1 pending
  1 failing

  1) application launch "before each" hook for "shows an initial window":
     Error: ChromeDriver did not start within 5000ms
      at Error (native)
      at node_modules/spectron/lib/chrome-driver.js:58:25
      at Request._callback (node_modules/spectron/lib/chrome-driver.js:116:45)
      at Request.self.callback (node_modules/request/request.js:200:22)
      at Request.<anonymous> (node_modules/request/request.js:1067:10)
      at IncomingMessage.<anonymous> (node_modules/request/request.js:988:12)
      at endReadableNT (_stream_readable.js:905:12)



npm ERR! Test failed.  See above for more details.

Is there something I've missed from the documentation? Do I need to start ChromeDriver separately? I've never used ChromeDrive or WebDriver before. This is my 1st take at automated Electron testing. Thanks for any/all clarification!

@cliff76
Copy link
Author

cliff76 commented May 1, 2016

For some reason it started working when I opened a new terminal window. There must have been a foul env var at play. I'm closing this issue. My apologies!

@cliff76 cliff76 closed this as completed May 1, 2016
@Bharadwaj108
Copy link

Bharadwaj108 commented Nov 14, 2016

Hello,I exactly have the similar issue.I have created a mocha.opts file in my test directory and set a default time out to 10000 ms also I have modified my package.json script section and have inserted these statements
"test": "mocha 'test/**/*.js' --timeout 10000", "test-debug": "mocha --debug 'test/**/*.js' --timeout 10000"
Also I have modified the mocha.js file and changed the default time out from 2000 to 20000 ms but still nothing happens and still get the same issue. Am I missing anything here.Please help.
My Code
`var assert = require('assert');
const mochaTimeOut = 30000;
describe('Test Suite 1', function () {
it('Test 1', function () {
this.timeout(100000);
var Application = require('spectron').Application
var assert = require('assert')
var app = new Application({
path: '/CorumDispense-win32-ia32/CorumDispense.exe'

    })
    app.start().then(function () {
        // Check if the window is visible
        return app.browserWindow.isVisible()
    }).then(function (isVisible) {
        // Verify the window is visible
        assert.equal(isVisible, true)
    }).then(function () {
        // Get the window's title
        return app.client.getTitle()
    }).then(function (title) {
        // Verify the window's title
        assert.equal(title, 'My App')
    }).then(function () {
        // Stop the application
        return app.stop()
    }).catch(function (error) {
        // Log any failures
        console.error('Test failed', error.message)
    })
})

})`
Outupt
Test Name: Test Suite 1 Test 1
Test Outcome: Passed
Result StandardOutput:
mocha.json options file not found. Using default values: { ui: 'tdd', reporter: 'tap', timeout: 2000 }
1..1
ok 1 Test Suite 1 Test 1
tests 1
pass 1
fail 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants