Comments (6)
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.
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.
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.
I updated my previous comment to pass the failure from app.stop()
to t.end
so stopping errors would be reported.
from spectron.
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.
Thank you so much for the help!
My pleasure, happy to hear things are working now 👍
from spectron.
Related Issues (20)
- Working docker image to run electron test headless HOT 10
- Element Wasn't Found After Upgrading my Spectron Version to 15 & Electron to 13 HOT 1
- Please release Spectron 16, compatible with electron 14 HOT 8
- api http mocking
- Module name "process" has not been loaded yet for context:
- This version of ChromeDriver only supports Chrome version 91 HOT 1
- failing to successfully launch Spectron headless in Docker on Jenkins
- Spectron test table contents
- export interface SpectronClient extends WebdriverIO.BrowserObject HOT 1
- test suddenly failing on Github Action Windows
- Support Electron 15
- is it possible to work with selenium grid using the image
- ChromeDriver / Chrome version mismatch HOT 2
- app.stop() not work, electron process stay in the background after the mocha test program exits HOT 2
- Rewrite Discussion HOT 12
- Spectron: Deprecation Announcement HOT 10
- This version of ChromeDriver only supports Chrome version HOT 1
- TypeError: waitUntilWindowLoaded Cannot read property 'isLoading' of undefined HOT 5
- --
- unknown error: call function result missing int 'status' HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spectron.