I had nightmare because of Nightmare (.js)

Jelena Jovanovic
Vanila Blog
Published in
6 min readAug 16, 2016

--

Community of digital makers — Join now

It’s been for an hour or two now since I woke up, and I’m still sitting on my bed because my floor is full of bugs. Yes, bugs.. and no, I have no idea where they came from. I just wanna get up and do my morning stuff, but I can’t walk obviously. It is not that I am scared, it’s just that I would feel bad if I would accidentally squash any of those little ones.

They started looking so cute and friendly to me after watching them for so long now. I always have that problem. I start thinking about how small the bug is and how it has it’s own life, family and then I feel sorry to hurt it. I even started talking with these ones which is crazy, I know. My mom though the same when wanted to come in my room and I told here, pretty loud, to stay away until I save all these bugs.I picked up each of those and after solving their problems, I putted them outside my window.

But there was this big red one that had a big problem and I was struggling a lot to help it. Its wings got caught up in some spider net and it was hard to clean it. But to be worse, in one moment sister asked me something and when I focused back on bug I saw that spider ate her. There was only shell left in my hand. I was sooo sad and mad! I should first remove all the spider net and save the little buggy and then talk with sister.

And then I woke up! Again. This time for real, I promise! This was one of the strangest dream, or better say nightmare, I ever had. Why? Because always when there are bugs in my dream, I wake up screaming if I touch them. This time there was so many bugs that there was not even 1cm free space on floor from bugs, and that didn’t scared me at all. I was thinking about it and I realized why.

Too much coding?

Few days earlier I started playing around with Nightmarejs , which is: “A high-level browser automation library”.

Before this, I knew about Casper.js and Phantom.js and through that I found out about it. So I never tried to do anything with it. But now, since I am looking for new ways to improve my JavaScript skills I though this would be fun way to do it. Nightmare use only pure JavaScript and not jQuery, which is exactly what I need. So I decided to practice by giving myself task to make some simple scripts. As always, I had a lot of errors and bugs, but it was super exciting because it was something new.

Same thing always

When I discover new library, framework or anything that makes me so excited, I can’t get proper rest. First I have problem to even fall asleep. And when I do, I continue coding in my dreams.I wake up tired, feeling like I didn’t even slept. Because reality and dream became same now, errors here and errors there. I am sure many of you experienced the same.

The good thing to do is to try your best to analyze your dreams and see what good can you get from it. But don’t look into those books about dreams meanings, look into yourself. What I do, is figure out what didn’t made sense in dream.

What in your dream is something that don’t belong in there? What is weird thing? Is there anything (person, object) that was now projected in different way than usual?

In this mine, strange thing for me was that I wasn’t scared of bugs. That means that bugs in this case was representing something else than just insects that they are. So with that realization I succeeded to analyze it completely:

  • For two days I had a lot of struggles to make my code work in exact way I wanted to. A lot of googling, stackoverflow questions, errors and bugs. Which my brain projected as real actual insects on my floor.
  • They were stopping me from doing my usual morning routine. In real life, I couldn’t move on and make my script work because of constant errors.
  • Then I was saving those little ones, one by one. Because I did solve lots of code problems and moved on eventually.
  • But there was new issue that I couldn’t solve and I left in bed with that in mind. That is what the big red one bug was.
  • It died because I talked with my sister. This is the KEY PART! Means that my subconscious is telling me that I was not focused that day enough. I was distracted by talking too much.

Tip for not dreaming codes

Coding while sleep too — programmer life

Before you go to bed, do something unrelated to codes. Watch some movie, read a book, call a friend or whatever it crosses your mind. That way you won’t fall asleep with your mind being fully in your last error. :D It will take a little break and you will have better rest for sure.

This may not work for everyone but it works for me, although I don’t always do it.

Tips to save you from nightmare because of Nightmare

I didn’t spent too much time with this library, but I did learned a few tricks after many failures.

1. Don’t forget that Nightmare.js use only pure JavaScript so don’t try to make jQuery work.

2. Use .wait(selector) instead of .wait(ms) . This way you will be sure that element you need is present. Not just assume that you setup enough time for your code to work good.

3. Use .screenshot([path][, clip]) — This is helpful to discover at what step your script fails. I make screenshots after every step. When you finish script you can remove those.

4. From documentation I couldn’t understand what exactly is .evaluate(). Here is good explanation I got on Stackoverflow:

The code in evaluate will be executed in the window opened by nightmarejs. So basically, it’s like you open a new tab on your browser, you type the website address and you paste the content of evaluate function inside the console. That’s why pure javascript works

5. If you need to use console parameters u need vo . Here is simple example:

Simple example how to use console parameters with vo

Do you also have some tips and tricks related to this story to share? Please write in comments, because someone might find it helpful. :)

Also, if you liked it, please recommend ❤ and share with your friends.

About the author

Hi, my name is Jelena and thank you for reading this post!

I am 23 yo Co Founder & Front End Developer at Vanila.io . I learn new stuff everyday and here I will share all my experiences and thoughts with you.

You can also find me on Twitter and Instagram . :)

Peace!

Community of digital makers — Join now

--

--

Digital Maiden — Co-Founder & Web Developer at @vanila_io | twitter: plavookac | instagram: plavookac