Function to trigger events in phamtomjs. Adapted from ng-scenario