tools
attempt 1
attempt 2
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.
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:
const Browser = require('zombie');
var url = 'https://stackoverflow.com'
Browser.visit(url, function(error, browser) {
browser.assert.text('title', 'Stack Overflow');
});
const Browser = require('zombie');
var url = 'https://stackoverflow.com'
var browser = new Browser();
browser.visit(url, function() {
browser.assert.text('title', 'Stack Overflow');
});
const Browser = require('zombie');
var url = 'https://stackoverflow.com'
var browser = new Browser();
browser.visit(url).then(function() {
browser.assert.text('title', 'Stack Overflow');
});
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With