Skip to content

Commit

Permalink
[IMP] phantom tests
Browse files Browse the repository at this point in the history
- phantomjs more verbose
- revert to dumber console.log relay, dont try to be smart, just display it
- json is only optionally parsed for errors stack dumps

bzr revid: al@openerp.com-20140316160634-hh7br4mbg01xcrpk
  • Loading branch information
antonylesuisse committed Mar 16, 2014
1 parent 0772c99 commit eac5185
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
26 changes: 14 additions & 12 deletions openerp/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ def phantom_poll(self, phantom, timeout):
# OSError, and no errno/strerror/filename, only a pair of
# unnamed arguments (matching errno and strerror)
err, _ = e.args
if err == errno.EINTR: continue
if err == errno.EINTR:
continue
raise

if ready:
Expand All @@ -224,24 +225,24 @@ def phantom_poll(self, phantom, timeout):
# process lines
if '\n' in buf:
line, buf = buf.split('\n', 1)

line = str(line)
if 'CoreText' in line:
continue

# relay everything from console.log, even 'ok' or 'error...' lines
_logger.debug("phantomjs: %s", line)

if line == "ok":
break
if line.startswith("error"):
line_ = line[6:]
try: line_ = json.loads(line_)
except ValueError: pass
line_ = self.line[6:]
# when error occurs the execution stack may be sent as as JSON
try:
line_ = json.loads(line_)
except ValueError:
pass
self.fail(line_ or "phantomjs test failed")

try: line = json.loads(line)
except ValueError: pass
_logger.info("phantomjs: %s", line)

def phantom_run(self, cmd, timeout):
_logger.debug('executing `%s`', ' '.join(cmd))
_logger.debug('phantom_run executing %s', ' '.join(cmd))
try:
phantom = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
except OSError:
Expand All @@ -252,6 +253,7 @@ def phantom_run(self, cmd, timeout):
# kill phantomjs if phantom.exit() wasn't called in the test
if phantom.poll() is None:
phantom.terminate()
_logger.debug("phantom_run execution finished")

def phantom_jsfile(self, jsfile, timeout=30, **kw):
options = {
Expand Down
12 changes: 7 additions & 5 deletions openerp/tests/phantomtest.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,22 @@ function PhantomTest() {
console.log('loaded', url, status);
// process ready
waitFor(function() {
console.log("waiting for: calling page evaluate");
console.log("PhantomTest.run: wait for condition: " + ready);
return self.page.evaluate(function (ready) {
console.log("waiting for", ready);
var r = false;
try {
console.log("waiting for: page evaluating ", ready);
console.log("page.evaluate eval expr:", ready);
r = !!eval(ready);
} catch(ex) { }
console.log("waiting for: returning from page evaluate");
} catch(ex) {
}
console.log("page.evaluate eval result:", r);
return r;
}, ready);
// run test
}, function() {
console.log("PhantomTest.run: condition statified, executing: " + code);
self.page.evaluate(function (code) { return eval(code); }, code);
console.log("PhantomTest.run: execution launched, waiting for console.log('ok')...");
});
}
});
Expand Down

0 comments on commit eac5185

Please sign in to comment.