These are chat archives for rosshinkley/nightmare

30th
Aug 2017
metacoin
@metacoin
Aug 30 2017 03:43
hi, is there any way to make sure the window does not close when testing ends?
i run the test, electron opens, but the test is done and electron closes immediately after 2-3 things happen on the page (it happens too quickly to see it)
Davide De Gennaro
@dege88
Aug 30 2017 06:41
@metacoin you can use the wait with a numeric parameter to wait for that amount of milliseconds
Max Malm
@benjick
Aug 30 2017 09:48
Hey
I'm trying to use nightmare + jest
First test works fines, the second one fails with Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
It doesn't even pop up the electron window
And if I only run the second test it works fine
Davide De Gennaro
@dege88
Aug 30 2017 09:54
you are ending the instance of electron in the first test (with .end)
@benjick
Max Malm
@benjick
Aug 30 2017 09:55
Ah, I see what you mean
I'll test, thanks
Davide De Gennaro
@dege88
Aug 30 2017 09:55
try with an instance per test
also you're not awaiting for nightmare in the line with the page declaration
Max Malm
@benjick
Aug 30 2017 09:56
I figured it was executed when I do evaluate()?
Davide De Gennaro
@dege88
Aug 30 2017 09:58
no, it should starts immediately
Max Malm
@benjick
Aug 30 2017 10:00
Thank you
Davide De Gennaro
@dege88
Aug 30 2017 10:01
you're welcome ;)
Max Malm
@benjick
Aug 30 2017 10:02
Also, what's the best method of persisting cache for just one test-run?
I need to persist over X instances, but clean it on every fresh run
Davide De Gennaro
@dege88
Aug 30 2017 10:04
in that case you can try to use a single instance of electron and to reuse it across the tests
for cache what do you mean?
Max Malm
@benjick
Aug 30 2017 10:05
localstorage, but I think I found a way
partition: persist: testing-${testString},
where testString = Date.now()
Max Malm
@benjick
Aug 30 2017 10:10
Can I clear an input?
Tried inserting ''
But it just appended I guess
Davide De Gennaro
@dege88
Aug 30 2017 10:13
type should do it according the documentation
Empty or falsey values provided for text will clear the selector's value.
Max Malm
@benjick
Aug 30 2017 10:14
Oops, thanks
Hm, it doesn't
Davide De Gennaro
@dege88
Aug 30 2017 10:16
can you show me how you're doing it?
Max Malm
@benjick
Aug 30 2017 10:17
  test.only('it can fail to log in', async () => {
    const page = visit()
      .type('#login_username', false)
      .type('#login_password', false)
      .type('#login_username', 'wrong')
      .type('#login_password', 'wrong')
      .click('#login_button')
      .wait('#login_error');

    const text = await page.evaluate(() => document.body.textContent).end();

    return expect(text).toContain('Login failed');
  });
Davide De Gennaro
@dege88
Aug 30 2017 10:17
if you type some text it gets written?
Max Malm
@benjick
Aug 30 2017 10:17
So "wrong" is appended to both inputs
Davide De Gennaro
@dege88
Aug 30 2017 10:17
ok
do you have jquery on the page?
Max Malm
@benjick
Aug 30 2017 10:18
Hm, no, but react, and the value is handled with state which is updated on keypress, so I guess just emptying the input wouldn't matter
Since I guess it doesn't trigger an event
Davide De Gennaro
@dege88
Aug 30 2017 10:21
ok
try with backspaces
\u0008
or empty the box with javascript run on the page with an evaluate
Max Malm
@benjick
Aug 30 2017 10:22
Backspaces works :D
Cool, thanks again
Davide De Gennaro
@dege88
Aug 30 2017 10:26
;)
Max Malm
@benjick
Aug 30 2017 10:55
Can my actions take parameters?
I wanna create an action that's like login('username', 'password')
Max Malm
@benjick
Aug 30 2017 11:07
nightmare.action('login', function(done) {
  this.evaluate_now(function(username, password) {
    this.type('#login_username', username).type(
      '#login_password',
      username,
    );
    return this;
  }, done);
});
This is what I tried
Davide De Gennaro
@dege88
Aug 30 2017 12:13
@benjick I'm sorry, I've never used the actions
I would have done it this way:
async function login(nightmare, user, pass) {
    await nightmare
        .type('#login_username', user)
        .type('#login_password', pass);
    return nightmare;
}