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.

Why I believe “Coursera, blocking access from sanctioned countries” is bad? Really bad!

Today my country’s name was on home page of Hacker News. Wow! It feels great to see your country’s being mentioned. For a country that even on many websites’ forms it is not even listed to choose as your country. Has it ever happened to you to fill a form and choose your country as “Other…” in a list of over a 180 countries? It’s really painful, you feel like are not even being seen.

But today, “Iran” was on home page of Hacker news. It felt good on the first sight. But only on the first sight. It was the news that Coursera is blocking access for students from Iran, Cuba, Sudan and Syria. [link]

This is what they mention as the main reason:

Certain aspects of Coursera’s course offerings are considered services and are therefore subject to restrictions in sanctioned countries

I understand that is the US law and they want to be safe. But I always had the impression that Coursera has a very ambitious goal in its heart: “Best courses, for free, for everyone!”. Well the later is not applicable anymore. It won’t be for “everyone”.

I don’t support the Iranian government and their behaviours which are causing all these sanctions, but a sanction like this is terrible. Who is paying the price for such a sanction? Isn’t the purpose of all these sanctions to prevent the government from continuing their nuclear program? I think on the contrary, this one works completely in their favour:

Sanction on Education!

What could be possibly worse than this?

Sanction on food? It is very harsh, the poor would starve, but it’s possible to work around it.

Sanction on medication? Yes it is terrible and people are struggling with it by paying with their lives. But even that is not as horrible as “Sanction on Education”.

I believe if something is going to change in Iran, it will be through education, through a very slow process of an ancient nation educating itself to take better care of itself. To grow. To live and to live freely. To learn the democracy.

In a society which all the education is controlled by government, this will never happen. Government’s golden age relies on ignorance of people. They censor the books and the movies. They filter the internet. They decide what you can or can not read, watch or even think.
In such situation having access to education without any burden and with no charge, is like finding the Treasure box. Or maybe even more valuable.

One may think, what Coursera was offering couldn’t lead to any of these. I should oppose you.

If i learn about “Drugs and Brain”, I would never go close to the drugs, and will educate my acquaintances about it as well.
If I attend a course on “World music”, I might have few words to say, which could be interesting for some.
If i will be more informed about “How to change the world”, I might really do something that does.
and if I learn more about “Global Sustainable Energy”, I may eventually realize that my country doesn’t need nuclear energy, there are plenty of other resources.

Those are the baby steps that takes for change. Indeed, it is slow. But that’s the only way. No revolution has ever worked for the benefit of the revolutionaries. Change will never happen over night.

If there is a way to the future for Iran, it is through education, period.

And today Coursera just blocked access for Students in Cuba, Iran, Sudan, and Syria.

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.

I submited a Talk for Confoo

I submitted a talk for Confoo 2014. The title is:

SQL or NoSQL that’s the question

With the emerge of new NoSQL databases, it’s very important to understand their abilities and the use-cases for a scalable web application. Understanding what they provide and what sort of problems they can solve is vital to successful usage of NoSQL databases in the web architectures and infra structures.

The key is that Relational Databases are not dead and they won’t be. They have specific abilities which would facilitate implementing a lot of ideas in the data modelling.

By experience, we realized that using a Hybrid system is the best solution. While you benefit from bests of the both worlds, you can improve the quality of product and availability of service to the customers.

In this presentation, an example from game-industry would be provided. A UbiSoft, Montreal game which was fully based on Relational databases, has been restructured to a Hybrid system to benefit from both Relational database and a NoSQL database.

The major design decisions, and the benefits of each would be discussed in details to give audience a perspective of what could be achieved within a Hybrid system.

The process of migrating the previous architecture to the new one in a live system, without having any downtime would be explained as well, to show how approachable and easy is this new Hybrid design.

The new architecture has been beneficial for the community of players and also for the development team, which they will be explained.

The Hybrid system has been on Production since October.2012 with no downtime since.


ConFoo. February 26 - February 28, 2014 | Montreal, Canada