Giter Site home page Giter Site logo

Comments (6)

kevinsawicki avatar kevinsawicki commented on July 24, 2024

Hmm, that is really strange that the response value would be null.

I might need to see your example to be able to debug it further.

I tried the following test using the sample app loaded from electron-prebuilt and did see it pass:

var Application = require('spectron').Application
var path = require('path')
var test = require('tape')

test('getWindowWidth test', function (t) {
    t.plan(1)

    var app = new Application({
      path: path.join(__dirname, 'node_modules', '.bin', 'electron')
    })

    app.start().then(function () {
      app.client.getWindowWidth().then(function (width) {
        t.equal(width, 800)
      }).then(function () {
        app.stop()
      }, function () {
        app.stop()
      })
    })
});
> tape test.js 
TAP version 13
# getWindowWidth test
ok 1 should be equal

1..1
# tests 1
# pass  1

# ok

from spectron.

LizzHale avatar LizzHale commented on July 24, 2024

Thanks for the reply, @kevinsawicki! Your sample works for me so it must have something to do with how I'm setting up the test? Here's my example:

var Application = require('spectron').Application
var test = require('tape')

// pass the path to the built application from the command line
var path = process.argv[2]

function setup() {
    app = new Application({
        path: path
    })
    return app.start()
}

function teardown() {
    if (app && app.isRunning()) {
        app.stop()
    }
}
function wrapper(description, fn) {
    test(description, function(t) {
        setup()
            .then(function() {
                return fn(t)
            })
            .then(function() {
                return teardown()
            })

    })
}
wrapper('upon application launch', function(t) {
    app.client.getWindowWidth().then(function(width) {
        t.equal(width, 900, 'client window width should equal 900')
    })
    t.end()
})
$ node test.js <path to electron executable>
TAP version 13
# upon application launch

1..0
# tests 0
# pass  0

# ok

from spectron.

kevinsawicki avatar kevinsawicki commented on July 24, 2024

Thanks for the example, I think it needed a few tweaks to properly chain all the promises together:

var Application = require('spectron').Application
var test = require('tape')

// pass the path to the built application from the command line
var path = process.argv[2]

var app = null

function setup() {
    app = new Application({
        path: path
    })
    return app.start()
}

function teardown(t) {
    if (app && app.isRunning()) {
        return app.stop().then(function () {
            t.end()
        }, function (error) {
            t.end(error)
        })
    } else {
        t.end()
    }
}
function wrapper(description, fn) {
    test(description, function(t) {
        setup()
            .then(function() {
                return fn(t)
            })
            .then(function() {
                return teardown(t)
            })

    })
}
wrapper('upon application launch', function(t) {
    return app.client.getWindowWidth().then(function(width) {
        t.equal(width, 900, 'client window width should equal 900')
    })
})
$ node test.js <path to electron executable>
TAP version 13
# upon application launch
ok 1 client window width should equal 900

1..1
# tests 1
# pass  1

# ok

from spectron.

kevinsawicki avatar kevinsawicki commented on July 24, 2024

I updated my previous comment to pass the failure from app.stop() to t.end so stopping errors would be reported.

from spectron.

LizzHale avatar LizzHale commented on July 24, 2024

Ah yes! That works perfectly and has the added bonus of forcing me to isolate my tests. Thank you so much for the help!

from spectron.

kevinsawicki avatar kevinsawicki commented on July 24, 2024

Thank you so much for the help!

My pleasure, happy to hear things are working now 👍

from spectron.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.