0

I'm working on a electron(-nuxt) based application. End to End test re-written with AVA + Spectron. The .click() function however doesnt seem to work.

I used this template: https://github.com/michalzaq12/electron-nuxt

Everything seems to work except a simple button click.

<footer class="modal-card-foot">
  <button id="loginButton" class="button " type="button" @click="login">
    Login
  </button>
</footer>
test('app should login', async t => {
    let app = t.context.app
    await app.client.click('#loginButton')
})

The message i got is:

1 test failed

app should login

Error: Test finished without running any assertions

That is truthy because there aren't any assertions. BUT i can see that the Button is never clicked, because that would trigger a "Login failed" message from the app.

Community
  • 1
  • 1
KingRazer
  • 3
  • 3

2 Answers2

0

In your test case you should wait for element to be rendered on the page.

test('app should login', async t => {
    const ELEMENT_SELECTOR = '#loginButton'
    let app = t.context.app
     try {
      await app.client.nuxt.ready()
      await app.client.nuxt.navigate('/') //optional
      await app.client.waitForExist(ELEMENT_SELECTOR)
      await app.client.click(ELEMENT_SELECTOR)
      t.pass() //or other assertion
    } catch (e) {
      t.fail(e.message)
    }
})
michalzaq12
  • 91
  • 2
  • 2
0

Checkout this repo that is an example of how to test an electron app: https://github.com/StephenDavidson/electron-spectron-example

specifically this where they test the functionality of pressing a button. Notice how they import in the page at the top. Search.js

const SearchPage = require('./page-objects/search.page');


Then near the bottom they test the functionality of click

  it('should search', async() => {
    const input = 'this is a test';
    await app.client.url(config.url)
      .setValue(SearchPage.searchField, input)
      .getValue(SearchPage.searchField)
      .should.eventually.equal(input)
      .click(SearchPage.searchButton)
      .element(SearchPage.searchResult)
      .should.eventually.exist;
  });

See if this helps you get further along.

Dan
  • 361
  • 1
  • 5
  • 17