How to access client window javascript global variable with Spectron












1















I'm trying test of Electron app with Spectron.
But I can't test client window javascript global variable.
Here is my simplified code.
Please help me.
Thanks.



index.html



<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>MY ELECTRON</title>
<script type="text/javascript" src="script.js"></script>
<link href="./style.css" rel="stylesheet">
</head>
<body>
</body>
</html>


script.js



let mode;
function onload_func(){
mode = 'normal';
}
window.onload = onload_func;


spec.js



const Application = require('spectron').Application
const assert = require('assert')
const electronPath = require('electron')
const path = require('path')
let app;
describe('Application launch', function () {
this.timeout(10000)
beforeEach(function () {
app = new Application({
path: electronPath,
args: [path.join(__dirname, '../src')]
})
return app.start()
})
afterEach(function () {
if (app && app.isRunning()) {
return app.stop()
}
})
it('initial mode',function(){
assert.equal(app.client.mode,'normal');
})
})









share|improve this question



























    1















    I'm trying test of Electron app with Spectron.
    But I can't test client window javascript global variable.
    Here is my simplified code.
    Please help me.
    Thanks.



    index.html



    <!DOCTYPE html>
    <html lang="ja">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>MY ELECTRON</title>
    <script type="text/javascript" src="script.js"></script>
    <link href="./style.css" rel="stylesheet">
    </head>
    <body>
    </body>
    </html>


    script.js



    let mode;
    function onload_func(){
    mode = 'normal';
    }
    window.onload = onload_func;


    spec.js



    const Application = require('spectron').Application
    const assert = require('assert')
    const electronPath = require('electron')
    const path = require('path')
    let app;
    describe('Application launch', function () {
    this.timeout(10000)
    beforeEach(function () {
    app = new Application({
    path: electronPath,
    args: [path.join(__dirname, '../src')]
    })
    return app.start()
    })
    afterEach(function () {
    if (app && app.isRunning()) {
    return app.stop()
    }
    })
    it('initial mode',function(){
    assert.equal(app.client.mode,'normal');
    })
    })









    share|improve this question

























      1












      1








      1








      I'm trying test of Electron app with Spectron.
      But I can't test client window javascript global variable.
      Here is my simplified code.
      Please help me.
      Thanks.



      index.html



      <!DOCTYPE html>
      <html lang="ja">
      <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta http-equiv="X-UA-Compatible" content="ie=edge">
      <title>MY ELECTRON</title>
      <script type="text/javascript" src="script.js"></script>
      <link href="./style.css" rel="stylesheet">
      </head>
      <body>
      </body>
      </html>


      script.js



      let mode;
      function onload_func(){
      mode = 'normal';
      }
      window.onload = onload_func;


      spec.js



      const Application = require('spectron').Application
      const assert = require('assert')
      const electronPath = require('electron')
      const path = require('path')
      let app;
      describe('Application launch', function () {
      this.timeout(10000)
      beforeEach(function () {
      app = new Application({
      path: electronPath,
      args: [path.join(__dirname, '../src')]
      })
      return app.start()
      })
      afterEach(function () {
      if (app && app.isRunning()) {
      return app.stop()
      }
      })
      it('initial mode',function(){
      assert.equal(app.client.mode,'normal');
      })
      })









      share|improve this question














      I'm trying test of Electron app with Spectron.
      But I can't test client window javascript global variable.
      Here is my simplified code.
      Please help me.
      Thanks.



      index.html



      <!DOCTYPE html>
      <html lang="ja">
      <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta http-equiv="X-UA-Compatible" content="ie=edge">
      <title>MY ELECTRON</title>
      <script type="text/javascript" src="script.js"></script>
      <link href="./style.css" rel="stylesheet">
      </head>
      <body>
      </body>
      </html>


      script.js



      let mode;
      function onload_func(){
      mode = 'normal';
      }
      window.onload = onload_func;


      spec.js



      const Application = require('spectron').Application
      const assert = require('assert')
      const electronPath = require('electron')
      const path = require('path')
      let app;
      describe('Application launch', function () {
      this.timeout(10000)
      beforeEach(function () {
      app = new Application({
      path: electronPath,
      args: [path.join(__dirname, '../src')]
      })
      return app.start()
      })
      afterEach(function () {
      if (app && app.isRunning()) {
      return app.stop()
      }
      })
      it('initial mode',function(){
      assert.equal(app.client.mode,'normal');
      })
      })






      javascript electron spectron






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 25 '18 at 22:52









      ShinShinShinShinShinShinShinShin

      62




      62
























          1 Answer
          1






          active

          oldest

          votes


















          0














          I'm not sure if it will solve your specific tests, but app.browserWindow should do the trick since as they say:




          It provides you access to the current BrowserWindow and contains all
          the APIs.




          Note that it's an alias to require('electron').remote.getCurrentWindow()



          Read more: https://github.com/electron/spectron#browserwindow






          share|improve this answer
























          • I tried it but it doesn't work. AssertionError [ERR_ASSERTION]: undefined == 'normal'

            – ShinShinShinShin
            Nov 27 '18 at 12:51













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53472817%2fhow-to-access-client-window-javascript-global-variable-with-spectron%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          I'm not sure if it will solve your specific tests, but app.browserWindow should do the trick since as they say:




          It provides you access to the current BrowserWindow and contains all
          the APIs.




          Note that it's an alias to require('electron').remote.getCurrentWindow()



          Read more: https://github.com/electron/spectron#browserwindow






          share|improve this answer
























          • I tried it but it doesn't work. AssertionError [ERR_ASSERTION]: undefined == 'normal'

            – ShinShinShinShin
            Nov 27 '18 at 12:51


















          0














          I'm not sure if it will solve your specific tests, but app.browserWindow should do the trick since as they say:




          It provides you access to the current BrowserWindow and contains all
          the APIs.




          Note that it's an alias to require('electron').remote.getCurrentWindow()



          Read more: https://github.com/electron/spectron#browserwindow






          share|improve this answer
























          • I tried it but it doesn't work. AssertionError [ERR_ASSERTION]: undefined == 'normal'

            – ShinShinShinShin
            Nov 27 '18 at 12:51
















          0












          0








          0







          I'm not sure if it will solve your specific tests, but app.browserWindow should do the trick since as they say:




          It provides you access to the current BrowserWindow and contains all
          the APIs.




          Note that it's an alias to require('electron').remote.getCurrentWindow()



          Read more: https://github.com/electron/spectron#browserwindow






          share|improve this answer













          I'm not sure if it will solve your specific tests, but app.browserWindow should do the trick since as they say:




          It provides you access to the current BrowserWindow and contains all
          the APIs.




          Note that it's an alias to require('electron').remote.getCurrentWindow()



          Read more: https://github.com/electron/spectron#browserwindow







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 25 '18 at 23:19









          rafaelcastrocoutorafaelcastrocouto

          7,75312656




          7,75312656













          • I tried it but it doesn't work. AssertionError [ERR_ASSERTION]: undefined == 'normal'

            – ShinShinShinShin
            Nov 27 '18 at 12:51





















          • I tried it but it doesn't work. AssertionError [ERR_ASSERTION]: undefined == 'normal'

            – ShinShinShinShin
            Nov 27 '18 at 12:51



















          I tried it but it doesn't work. AssertionError [ERR_ASSERTION]: undefined == 'normal'

          – ShinShinShinShin
          Nov 27 '18 at 12:51







          I tried it but it doesn't work. AssertionError [ERR_ASSERTION]: undefined == 'normal'

          – ShinShinShinShin
          Nov 27 '18 at 12:51






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53472817%2fhow-to-access-client-window-javascript-global-variable-with-spectron%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Wiesbaden

          Marschland

          Dieringhausen