n1k0/casperjs — Issue #4: Halting script when calling wait
Author: marchugon
Created: 2011-11-08 08:58:00+00:00
State: open

Is it possible to halt main script to wait for the return of a function like waitForSelector ?

My concern is that in my tests, if I write something like this :

```javascript
...
self.waitForSelector('.tweet-row', function(self) {
self.test.assert(true, '.tweet-row has appeared');
}, function (self) {
self.test.assert(true, '.tweet-row not coming, failure');
});
self.click('somewhere');
```
the last line is called asynchronously of the call to waitForSelector, which causes problem in my case because I want to do something in the element I'm waiting for.

My workaround is simple :

```javascript
...
self.waitForSelector('.tweet-row', function(self) {
self.test.assert(true, '.tweet-row has appeared');
continueMytests(self);
}, function (self) {
self.test.assert(true, '.tweet-row not coming, failure');
});
function continueMyTests(self) {
self.click('somewhere');
}
```

Can't Casper stop the tests until "waitFor" returns something ?