Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

zombie browser won't open a window after calling open function

tools

attempt 1

  • Darwin 14.3.0 Darwin Kernel Version 14.3.0
  • io.js v1.8.1
  • zombie Version 4.0.7 2015-04-10

attempt 2

  • Linux ubuntuG5 3.13.0-48-powerpc64-smp
  • node.js v0.10.38
  • zombie Version 3.1.0 2015-03-15

commands:

const Browser = require('zombie');
var url = 'https://google.com'
var browser = new Browser();
browser.open(url=url)
browser.open('http://google.com', function(err) { browser.assert.success();
});
browser.assert.text('title', 'Google');

Results on both machines minus filepath differences:

    assert.js:93
  throw new assert.AssertionError({
        ^
AssertionError: No open window with an HTML document
    at Browser.queryAll (/home/dmmmd/Dropbox/node_js_projects/node_modules/zombie/lib/index.js:432:5)
    at Assert.text (/home/dmmmd/Dropbox/node_js_projects/node_modules/zombie/lib/assert.js:307:33)
    at Object.<anonymous> (/home/dmmmd/Dropbox/node_js_projects/affinity-zombie/sample_zombie.js:7:16)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:935:3

What am I missing after reading the docs at zombie browser? Thanks in advance.

I tried some other urls, too, even localhost ones without any success.

JavaScript, node.js, io.js, and zombie are all new to me so I am basically just following recipes from the documentation and stackoverflow questions. I would appreciate any suggestions. I suspect I am missing something very simple.

like image 811
dmmfll Avatar asked Apr 23 '15 23:04

dmmfll


1 Answers

This question has been unanswered for a while but I've been working around a similar error message recently.

TL;DR - User browser.visit instead of browser.open() and pass in a callback function to ensure browser's state is populated correctly.

You can do this in a number of ways:

  1. Use the static method Browser.visit()
const Browser = require('zombie');
var url = 'https://stackoverflow.com'
Browser.visit(url, function(error, browser) {
    browser.assert.text('title', 'Stack Overflow');
});
  1. Use the instance method browser.visit()
const Browser = require('zombie');
var url = 'https://stackoverflow.com'
var browser = new Browser();
browser.visit(url, function() {
    browser.assert.text('title', 'Stack Overflow');
});
  1. Use the promise returned by browser.visit()
const Browser = require('zombie');
var url = 'https://stackoverflow.com'
var browser = new Browser();
browser.visit(url).then(function() {
    browser.assert.text('title', 'Stack Overflow');
});
  1. If you want to reuse the browser object after the visit, pass a no-op callback to browser.visit() to ensure the browser's state is populated.
const Browser = require('zombie');
var url = 'https://stackoverflow.com'
var browser = new Browser();
browser.visit(url, function(){}); // NB: no-op callback!
browser.assert.text('title', 'Stack Overflow');

The browser.open() method opens a new browser tab and takes a JavaScript Object containing an url property, so your original code had a syntax error, the line

browser.open(url=url)

should read

browser.open({url: url})

but it's not clear whether the open method actually makes the new tab visit the url - at least not from a cursory read over the source. Use browser.visit() to be on the safe side.

like image 62
Jim Riordan Avatar answered Oct 12 '22 18:10

Jim Riordan