Testing a Google Polymer Project using InternJS

For the pas few days I had the opportunity to play with Google Polymer project and start implementing something very interesting.

But no project gets pretty fun until it is testable. And testing Polymer projects is not as easy as it is expected to be.

There are some existing tools to test including:

But we have had InternJS fully setup for our project and we’ve been happy with it [1]. So moving to yet another JS testing framework is the least we would want to do.

Getting InternJS up and running to test the Web-Components is not easy. I was lucky enough to stumble upon Chris Storm‘s blog posts (1, 2) around the same time I was looking in to this. Those posts helped me to get me on my foot. Although they are not fully functional.

The nature of problem is because of Shadow DOM. Each Web-Component is encapsulated in its own DOM and are completely independent from the rest and also the main DOM.
So even if you capture a reference to the element you want to test you suddenly face the following error from Intern:

stale element reference: element is not attached to the page document

Finally I was able to get a sample test running. It is pretty ugly but at least it could be a start.

The problem

Imagine we have a structure of Web-Components as follow:

<custom-element-one flex>
 <custom-nested-element id="someId">

What we want to test is to get the `id` of `custom-nested-element` and assert its value. So you are expecting the following would work:

return this.remote
.then(pollUntil('return document.querySelector(&amp;quot;custom-element-one&amp;quot;).shadowRoot;', 20000))
.then(function (doc) {
        .then(function (value) {
            assert.equal(value, 'someId');

But unfortunately it won’t work.

The Solution

The problem is coming from WebDriver rather than Intern or Leadfoot. The issue is you can get a reference to the element, but WebDriver thinks that the reference is stale and is not attached to the document. As it only checks the DOM of the main document.

The solution is just a work around on WebDriver’s limitation. Here is a sample which could make it work, if you want to test lets say `id` attribute of that specific nested web-component element.

The same approach would work for result of exposed methods as well.

return this.remote
.then(pollUntil(function () {
    if (document.querySelector('custom-element-one').shadowRoot) {
        return document.querySelector('custom-element-one').shadowRoot.querySelector('custom-nested-element').id;
    return null;
}, [] , 20000))
.then(function (idValue) {
    assert.equal(idValue, 'someId');

At the core what we are doing is using `pollUntil` helper function to fetch the `shadowRoot` of the first web-component when it is ready and use that to fetch the second one.

Response of `pollUntil` is wrapped in a Promise, so having a `then` afterwards would receive the value of the returned `id`.

[1] If you are interested to know more about the architectural approach and tools we are using, I highly recommend reading Dominique’s detailed write up, JavaScript technology Stack.

Node.JS module install behind a corporate proxy

If you happen to be behind a corporate firewall like me, chances are you have tons of problems with Node’s package manager,npm.

So here are some steps which might help you.

1. Setup NPM to use your proxy configuration

sudo npm config set proxy http://proxy.mycompany.comg:3128
sudo npm config set https-proxy https://proxy.mycompany.com:3128

2. Force your npm to use HTTP over HTTPS
You could do this by doing :

sudo npm config set registry http://registry.npmjs.org/


The above steps should work for majority of modules but it may not work for some.

3. If the module has a HTTPS reference explicitly in its package.json dependencies
Some modules specify the full URL in their dependencies other than just the name. If that is the case NPM would go and fetch the module from that URL . If the URL contains HHTPS although you have specified to use HHTP only but it would try to access HTTPS, so it would freeze there specially if your proxy server blocks that.

In this case:
3.1 Clone the repository to your local machine

3.2 Modify the package.json file and replace any HTTPS with HTTP

3.3 Install the local module
To install the module located in your local hard drive, use NPM and instead of module’s name, specify the path:

npm install module/


This should fix most of the issues with installing a module behind a corporate proxy.

Extending VirtualBoxes Virtual hard Drive

I usually have one Windows available in hand in a VM. Knowing windows, it would eat all the hard drive you dedicate to it. So at the setup time I decided to give it a flexible size but maximum of 25GB, which seemed fair for Windows 7. But now that I have had it for a while it got quite big and when I wanted to install a new application, I was running out of space.

Extending an existing drive is not possible, but the whole process to achieve what’s needed is very very simple. All you need to is:

  1. Go to VM’s setting / storage and create a new bigger storage, which would be your only HDD
  2. clone the hard drive from the old one to the new one. Here is the VirtualBox’s command:
    $VBoxManage  clonehd /Path/to/old/Windows7.vdi  /path/to/new/Win7_30GB.vdi --existing
  3. Now remove the HDD from your existing VM. (VM/Setting/Storage)
  4. Add your new HDD to the VM.
  5. Boot the VM
  6. In the guest OS, go to “Control Panel/ Administrative Tools/ Computer Management/ Storage”   and you should be able to see the extra space as unallocated. Just extend the existing drive to the maximum to use it

Enjoy your extended HDD.

yum behind a proxy

If you happen to be behind a corporate proxy and need to get “yum” working you could easily set your proxy settings in the “yum.conf” file. The file is usually located here:


And all you need to do is to set the following variables:

# If your proxy server happen to need user/pass credentials for Authentication

“True North PHP” Talk + Slides

The first day of TrueNorthPHP 2013 is over and there were quite interesting talks to listen and amazing people to meet.

My talk was at 11:00 AM and it went well. It was an honor for me to speak at this conference.

In case you’re interested, you can take a look at the slides on slideshare.

JavaScript Date Object Chrome vs. Firefox

There is a very tiny yet important difference between how Chrome and Firefox treats “Date” object, when you are creating one from a String:

new Date("1980-03-14T00:00:00.0000000");

The difference is that Firefox (tested on v23.0.1) considers the passed string is on the local timezone so the output is:

new Date("1980-03-14T00:00:00.0000000").toString();
"Fri Mar 14 1980 00:00:00 GMT-0400 (Eastern Standard Time)"

While Chrome, considers the passed string in UTC/GMT timezone and then converts it to a local timezone:

new Date("1980-03-14T00:00:00.0000000").toString();
"Thu Mar 13 1980 20:00:00 GMT-0400 (Eastern Daylight Time)"

As you can see, that would be a potential for some Front-End Date/Time processing.

If you are using the Date object just for showing, using the UTC format would be very useful and would avoid any discrepancies.

var my_time =  new Date("1980-03-14T00:00:00.0000000");

Leveling up

Kate Matsudaira is one of the very few technical people who shares very beneficial knowledge and experiences for leadership, leveling up and management.

Her talk at Velocity about Leveling Up for engineers, is a very useful guide line for all tech people to set a goal and road-map for themselves to improve and be better at their work.

Here is the video of the conference and below you can find my notes.

[The following notes are a summary of what is mentioned in the video and they are not mine]

Work is not just about contributions and features. It’s not about what you do, it’s how you do it.

Figure out what you want to be doing!
Where you’re at… what are your skills. Depth is not enough. You have to have breadth. Also Social skills and soft-skills.

  1. Identify success
  2. Be specific about it – The path
  3. Create if-then-else for all the obstacles.( if I couldn’t do it this weekend I will do it Sunday)
  4. Schedule the time with yourself. Every month. to look where you are at and what you are doing.

Game Play

# Hard work
# Become indispensible to the team. Become the person who is most important to the organization. If it’s not you, so how could you become the one.
It’s not enough to do what you are told to do. You have to look to other places to contribute. Fill the gaps. Do the right things. It’s also important to do the right things.
# It’s your job to manage your manager. Asking the right questions and giving them the right questions that they need to be successful.
# Does your manager knows what you are doing?

Assessing performance

It’s about trust. How much you manager trusts you? You have to build trust.

– Do the hard work first.
– Use your time effectively.
– Work hardest in the office



be precise with the questions: What was the one thing I could have done to make the project better.
Be open to feedback :

  1. Don’t be defensive
  2. Fight the urge to jump in and answer
  3. Ask for clarification – What would you have done differently?
  4. Listen for emotion
  5. Be thankful
  6. Change and adopt

Teaming Up

  • Who is the person you admire the most at your job?
  • What do they do and what do they do differently?

When people come to you, be open. Take the time to understand what they are saying.
Bring solutions to the table.
Empathy and attitude. You have the most control about how you feel about things.

Reverse – Take the time to put yourself in others shoes.
Long term – How you feel about the situation in a year from now. If you won’t care, there no reason to get upset
Chance for growth –


  • The tone and the words you use makes a difference.
  • Improve written messages.
  • Know your audience. VP of engineering, business person, or team-mates
  • Start the message with what’s important.
  • Be concise
  • “Let me know if you would like more info”.
  • Make it easy to understand for everyone.
  • Most successful people are the ones who are able to communicate with everyone and talk at a level that’s accessible for everyone.


Making people feel important:

  1. Be present (at conferences). If you’re in a meeting, engage and be in the meeting.
  2. Repeat what you heard. You make people feel heard and important.
  3. Ask questions.
  4. Don’t interrupt


If you are not doing a good job, people don’t want to work with you and they won’t respect you.
Influence : No one cares about how much you know, until the know how much you care.
Improve relationships :
1 – Make list of the most important people in your team
2 – Make a list of people who you have best relationships with
How can you improve your relationships ?
You are the average of your 5 closest friends. and if your 5 closest friends at work are not the most important people. Improve your relationships.

Do you know 3 things you could do, to make your life and career better?

You can’t become the person who you want to be by staying who you are.