Giter Site home page Giter Site logo

Comments (6)

DinisCruz avatar DinisCruz commented on August 27, 2024

ok so this works (using code from spectron tests)

start-test-2.js

require('fluentnode')

var helpers = require('./global-setup')


electron_Prebuild = require('electron-prebuilt')

appPath      = __dirname.path_Combine('../../electron-apps/web-view')

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

describe('application launch 3', function () {
    this.timeout(10000)
    var app = null
    var path = [appPath]

    beforeEach(function (done) {
        helpers.setupTimeout(this)
        return helpers.startApplication({
            args: path
                    }).then(function (startedApp) { app = startedApp; done()  })
    })

    afterEach(function () {
        return helpers.stopApplication(app)
    })

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

    it('shows an initial window abc', function () {
        app.isRunning().assert_Is_True()
        return app.client.getWindowCount().then(function (count) {
            assert.equal(count, 2)
        })
    })
})

global-setup

var Application = require('spectron').Application
var assert = require('assert')
var chai = require('chai')
var chaiAsPromised = require('chai-as-promised')
var path = require('path')

global.before(function () {
  chai.should()
  chai.use(chaiAsPromised)
})

exports.getElectronPath = function () {
  var electronPath = path.join(__dirname, '../../../', 'node_modules', '.bin', 'electron')
  return electronPath
}

exports.setupTimeout = function (test) {
  if (process.env.CI) {
    test.timeout(30000)
  } else {
    test.timeout(10000)
  }
}

exports.startApplication = function (options) {
  options.path = exports.getElectronPath()
  if (process.env.CI) options.startTimeout = 30000

  var app = new Application(options)
  return app.start().then(function () {
    assert.equal(app.isRunning(), true)
    chaiAsPromised.transferPromiseness = app.transferPromiseness
    return app
  })
}

exports.stopApplication = function (app) {
  if (!app || !app.isRunning()) return

  return app.stop().then(function () {
    assert.equal(app.isRunning(), false)
  })
}

from spectron.

DinisCruz avatar DinisCruz commented on August 27, 2024

Here is the above code in coffee-script

start-test.coffee

require 'fluentnode'
helpers = require('./global-setup')

appPath = __dirname.path_Combine('../../electron-apps/web-view')

assert = require('assert')

describe 'application launch 4', ->
  @timeout 10000
  app   = null
  path  = [ appPath ]

  beforeEach (done) ->
    helpers.setupTimeout this
    helpers.startApplication(args: path)
           .then (startedApp) ->
              app = startedApp
              done()

  afterEach ->
    helpers.stopApplication app

  it 'shows an initial window abc', ->
    app.isRunning().assert_Is_True()
    app.client.getWindowCount()
              .then (count) ->
                assert.equal count, 2

global-setup.coffee

Application = require('spectron').Application
assert = require('assert')
chai = require('chai')
chaiAsPromised = require('chai-as-promised')
path = require('path')

global.before ->
  chai.should()
  chai.use chaiAsPromised


exports.getElectronPath = ->
  electronPath = path.join(__dirname, '../../../', 'node_modules', '.bin', 'electron')
  electronPath

exports.setupTimeout = (test) ->
  if process.env.CI
    test.timeout 30000
  else
    test.timeout 10000

exports.startApplication = (options) ->
  options.path = exports.getElectronPath()

  if process.env.CI
    options.startTimeout = 30000

  app = new Application(options)
  app.start()
     .then ->
        assert.equal app.isRunning(), true
        chaiAsPromised.transferPromiseness = app.transferPromiseness
        return app

exports.stopApplication = (app) ->
  if !app or !app.isRunning()
    return
  app.stop().then ->
    assert.equal app.isRunning(), false`

from spectron.

DinisCruz avatar DinisCruz commented on August 27, 2024

For reference the code that replicates this issue ('self.client.init if not a function') is at https://github.com/DinisCruz/BSIMM-Graphs-QA/tree/d416ec863afdc2a53550a5d8a2ea9f5184c3a57e

from spectron.

DinisCruz avatar DinisCruz commented on August 27, 2024

And the travis execution is at https://travis-ci.org/DinisCruz/BSIMM-Graphs-QA

image

from spectron.

DinisCruz avatar DinisCruz commented on August 27, 2024

ok found the prob and solved it

image

the issue was with an prototype method called keys (see o2platform/fluentnode#95)

Here is the version with the code that works

https://github.com/DinisCruz/BSIMM-Graphs-QA/tree/5f36e9ecf3333caf745e820ff617a04b72689ead

here is the test failing in travis on the final assertion (which means that everything worked as expected)

image

from spectron.

DinisCruz avatar DinisCruz commented on August 27, 2024

For reference here is a final refactored version of the sample code shown above

Global_Setup

require 'fluentnode'

Application = require('spectron').Application

class Global_Setup
  constructor: (options)->
    @.options   = options || {}
    @.app       = null
    @.root_Path = wallaby?.localProjectDir || __dirname.path_Combine '../'
    @.app_Path  = __dirname.path_Combine '../electron-apps/web-view'
    @.options.path = @.getElectronPath()
    @.options.args = [@.app_Path]

  getElectronPath: =>
    @.root_Path.path_Combine 'node_modules/.bin/electron'

  isRunning: =>
    @.app?.isRunning() || false

  startApplication: () =>
    @.app = new Application(@.options)
    @.app.start()

  stopApplication: () =>
    if !@.app or !@.app.isRunning()
      return
    @.app.stop()

module.exports = Global_Setup

start-test

assert      = require('assert')

Global_Setup = require('../../src/global-setup')


describe 'Global_Setup', ->

  it 'constructor', ->
    using new Global_Setup(), ->
      assert_Is_Null @.app

  it 'isRunning', ->
    using new Global_Setup(), ->
      @.isRunning().assert_Is_False()

  it 'getElectronPath', ->
    using new Global_Setup(), ->
      @.getElectronPath().assert_File_Exists()

  it 'appPath', ->
    using new Global_Setup(), ->
      @.app_Path.assert_Folder_Exists()


  it 'start, stop', ->
    @.timeout 5000
    using new Global_Setup(), ->
      console.log 'after setup'
      @.startApplication().then =>
        console.log 'after start Application'
        @.isRunning().assert_Is_True()
        @.app.client.getTitle().then (title)=>
          console.log title
          title.assert_Is 'Electron App - with WebView'
          @.stopApplication().then =>
            console.log 'after stop'
            @.isRunning().assert_Is_False()

  it 'stop', ->
    @.timeout 4000
    using new Global_Setup(), ->
      @.startApplication().then =>
        @.stopApplication().then =>
          @.stopApplication() 

describe 'test browserwindow and client', ->

  global_Setup   = null

  @.timeout 10000

  beforeEach () ->
    global_Setup = new Global_Setup()
    global_Setup.startApplication()

  afterEach ()->
    global_Setup.stopApplication()

  it 'gets window count', ()->
    global_Setup.isRunning().assert_Is_True()
    global_Setup.app.client.getWindowCount()
      .then (count) ->
        count.assert_Is 2

  it 'show an initial window', ()->
    using global_Setup.app.browserWindow, ->
      @.setBackgroundColor('#001122')
      @.setPosition(400,10)
      @.setSize(600,400)
      @.showInactive()

  return

  it 'check title', ()->
    app.client.windowByIndex(1)
      .then -> app.client.getTitle()
      .then (title)->
        title.assert_Is 'Google'

  it 'check HTML', ()->
    app.client.windowByIndex(1)
      .then -> app.client.getHTML('*')
      .then (text)->
        text[0].assert_Contains 'Google'

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.