Comments (6)
Thanks. I took a look this evening at what it would take to support the newer version. It looks like the page is now run in a sandbox that does not have access to the "phantom" object. The current approach enables the loaded webpage (ie the HTML test runner) to directly write to files via phantom.writeToFile. It looks like in 1.3.0 I would have to move the fs functions outside of the loaded webpage and into the JS file that is actually run by Phantom.
Does that sound correct, or am I missing something? As nice as sandboxing can be, in this case it will certainly make the reporter less straightforward as it will not be able to perform all actions directly.
Is there a better way?
from jasmine-reporters.
Does that sound correct, or am I missing something?
That sounds correct.
Is there a better way?
AFAIK there isn't any easier way. The only solution I'm aware of is doing as much processing in the webpage as possible (page.evaluate), then, passing messages (simple object responses) back and forth between phantom and the page, and communicating that way. That's about as easy as it can be, until we find a better method to do this without compromising security.
P.S. Argument passing to page.evaluate is very difficult at the moment. casperjs currently has a pretty good way of doing it, if you ever need to do this. Take a look at line 266 and line 1327.
from jasmine-reporters.
With argument passing to page.evaluate being difficult, what is the appropriate way to pass messages back and forth? I can see how the phantom script can force the loaded page to do work and return simple data objects to the phantom script using page.evaluate, but I do not see how the loaded page could initiate communication to the host script.
Is there some postMessage
support that I am missing, or is what I describe above what you meant by passing simple object responses back and forth -- in that it must always be initiated by the phantom-loaded script?
from jasmine-reporters.
This example might help better explain it... Hopefully it answers your questions! Basically, evaluate will return when all the code inside evaluate is done, so you just use return on anything you need. I know it can get really messy and complicated however; we're looking for ways to improve this, but it could take awhile.
A postMessage solution would be pretty nice, but could also be a vulnerability (sadly), since any script inside the page could use it and could post false messages back. We would have to get into patching QtWebKit itself to possibly fix that stuff, which could take awhile; and this would only really work with PhantomJS, and I don't know what we would do for PyPhantomJS regarding that. :/
var page = require('webpage').create();
page.onConsoleMessage = function(msg) {
console.log(msg);
}
function replaceFunctionPlaceholders(fn, replacements) {
if (replacements && typeof replacements === "object") {
fn = fn.toString();
for (var p in replacements) {
var match = '%' + p + '%';
do {
fn = fn.replace(match, replacements[p]);
} while(fn.indexOf(match) !== -1);
}
}
return fn;
}
page._evaluate = page.evaluate;
page.evaluate = function(fn, replacements) {
return page._evaluate(replaceFunctionPlaceholders(fn, replacements));
}
page.open('http://foobar.baz', function(status) {
// do some stuff
var passThis = 'somedata...';
var res = page.evaluate(function() {
// do some in page processing
var somedata = '%myData%';
if (somedata === 'somedata...') {
// success in processing something
return True;
} else if (somedata === 'fail...') {
// failed to process something...
return False;
}
// returning some string or message
return 'some message containing a result';
}, {
myData: passThis
});
if (res === True) {
console.log('we succeeded!');
}
});
from jasmine-reporters.
Wow, yes, I see what you mean by difficult. Ultimately it's just rewriting the function and passing that in as text...
But thanks for the example, it got me thinking / playing. I can kludge this by using page.evaluate to inject a writeFile
function into the global scope (or wherever) which stores filename=>data in a randomly-named hash; the host script can then check for the presence of data in that hash and, if found, do the work itself to write them out to disk. Definitely a kludgy solution but prototyping looks like it will work just fine, while still preventing the Jasmine runner script from knowing what is going on behind the scenes.
It restricts the jasmine reporter to writing files out via Phantom only if it is executed by a host script that injects / takes care of proxying the writeFile
requests to fs.write
but there are worse things.
Of course, this begs the question "is it worth it to upgrade from 1.1.0 to 1.3.0 in light of the required workaround." But I suppose since jasmine-reporters is intended as a helper library, I should probably bite the bullet and do the legwork to support the new version / bugfixes / features.
Not very often I feel like telling someone... thanks for the example and ideas for a horrendous, yet functional, hack.
from jasmine-reporters.
Resolved in 058612c
from jasmine-reporters.
Related Issues (20)
- Consider a JSON reporter HOT 3
- Consider adding an option to Not Show Skipped Tests
- JUnit xml output fails with Jenkins xUnit plugin HOT 5
- Jenkins xUnit 2.0.2 cannot parse JUnit file HOT 1
- Xml report not generated for failing testcase on compilation error HOT 1
- Time value being returned as NaN for testcases HOT 3
- PLease help me with the add log for this report
- Consolidate tests with same describe in multiple files
- request, files property in testcase element
- Test name should include 'describe' name when publishing protractor results HOT 1
- failure in beforeAll() and afterAll() not present in junit report
- xmloutput folder not getting generated in Azure devops
- Vulnerability: Misinterpretation of malicious XML input HOT 6
- Update needed as mkdirp:0.5.1 Legacy versions of mkdirp are no longer supported.
- JunitXmlReporter: Add ability to captureStdErr
- JUnitXmlReporter in docker container
- Multiple failures in testsuite for failures under single testcase HOT 1
- A new release and a new upload to npm ~2.5.1 would be nice. HOT 8
- Dependency @xmldom/xmldom 0.8.3 has a critical CVE vulnerability
- stack can be undefined on uncaught exceptions causing TerminalReporter to throw
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jasmine-reporters.