Comments (4)
Since Spectron is a framework to help with testing, then it would make sense to show a test on its main page :)
Spectron is test framework agnostic so I'd like to keep an example on that page that doesn't assume any specific library like mocha, jasmine, etc.
The current example shows the basic start/stop flow, promise chaining, and node's built-in asserts so it should be able to get you up and going testing your app without worrying about which framework to pick and how to integrate it.
I'm going to close this out. I think it makes sense to have lots of examples in the readme for different framework, but for the main marketing page I think it is better to show an example using only node built-ins.
from spectron.
For example here is an simple API wrapper for spectron
Spectron_API
require 'fluentnode'
spectron = require 'spectron'
class Spectron_API
constructor: (options)->
@.options = options || {}
@.Application = spectron.Application
@.app = null
@.root_Path = wallaby?.localProjectDir || __dirname.path_Combine '../'
is_Running: =>
@.app?.isRunning() || false
setup: =>
@.options.path = @.root_Path.path_Combine 'node_modules/.bin/electron'
@.options.args = [ __dirname.path_Combine '../electron-apps/web-view' ]
@.app = new @.Application @.options
@
start: =>
@.app.start()
stop: =>
@.app.stop()
module.exports = Spectron_API
Spectron-API.test
Spectron_API = require '../../src/Spectron-API'
describe 'constructor',->
it 'constructor', ->
using new Spectron_API(), ->
@.options .assert_Is {}
@.Application.assert_Is_Function()
@.root_Path .assert_Folder_Exists()
.path_Combine('node_modules').assert_Folder_Exists()
assert_Is_Null @.app
it 'isRunning', ->
using new Spectron_API(), ->
@.is_Running().assert_Is_False()
it 'setup', ->
using new Spectron_API(), ->
@.setup().assert_Is @
using @.app, ->
@.host .assert_Is '127.0.0.1'
@.port .assert_Is 9515
@.quitTimeout .assert_Is 1000
@.startTimeout .assert_Is 5000
@.waitTimeout .assert_Is 5000
@.connectionRetryCount.assert_Is 10
@.nodePath .assert_Is process.execPath
@.env .assert_Is {}
@.workingDirectory .assert_Is __dirname.path_Combine('../..')
@.api.app .assert_Is @
@.api.requireName .assert_Is 'require'
@.transferPromiseness .assert_Is_Function()
@.path.assert_File_Exists()
.assert_Contains '.bin/electron'
@.args.assert_Size_Is(1).first()
.assert_Folder_Exists()
.assert_Contains 'electron-apps/web-view'
it 'start and stop', ()->
@.timeout 4000
using new Spectron_API().setup(), ->
@.start().then =>
@.is_Running().assert_Is_True()
@.stop()
# other tests
it 'expected files inside electron-apps/web-view folder', ->
using new Spectron_API().setup(), ->
app_Folder = @.options.args.first()
app_Folder.assert_Folder_Exists().assert_Contains '/electron-apps/web-view'
.files().file_Names() .assert_Contains ['index.html', 'main.js', 'package.json', 'web-view.html']
it 'check title', ->
@.timeout 4000
using new Spectron_API().setup(), ->
@.start().then =>
@.app.client.getTitle().then (title)=>
title.assert_Is 'Electron App - with WebView'
@.stop()
index.html
<!DOCTYPE html>
<html>
<head>
<title>Electron App - with WebView</title>
<style>
html, body {
width: 100%; height: 100%; margin: 0; padding: 0;
},
webview {
display: block; border: none; height: 80vh; width: 95vw;
}
</style>
<script>
</script>
</head>
<body style="background-color:lightslategray">
<webview id='google' src="http://www.google.com" style='height:100vh; width:110vw' autosize="on" ></webview>
</body>
</html>
main.js
var app = require('electron').app
var BrowserWindow = require('electron').BrowserWindow
var mainWindow = null
app.on('ready', function () {
mainWindow = new BrowserWindow({
show : false,
center : true,
width : 800,
height : 400,
minHeight : 100,
minWidth : 100
})
mainWindow.loadURL('file://' + __dirname + '/index.html')
mainWindow.on('closed', function () { mainWindow = null })
})
from spectron.
For reference here are the tests above running in travis
from spectron.
ok @kevinsawicki fair enough
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.