I’m running some Nightwatch automated tests, and am having some problems parsing the reports with Jenkins and the nightwatch-html-reporter package.
The assertion in question is (basically checking for an alt tag value on a lot of links):
alts.value.forEach(alt => {
this.verify.notEqual('', alt.value || '', '\nImage URL: ' + src.value + '\nImage Tag: ' + tagName + '\n');
}
And I’m catching several failures in the report that look like this, one after another in the report (probably 10 of them with different url’s):
<failure message="Failed [notEqual]: (
Image URL: https://<url>/bc/wp-content/uploads/blog-placeholder-img.jpg
Image Tag: img
) - expected [0;32m""[0m but got: [0;31m""[0m">Image URL: https://<url>/bc/wp-content/uploads/blog-placeholder-img.jpg
Image Tag: img
at NightwatchAPI.<anonymous> (/workspace/WebsiteLaunchAutomation/custom_commands/verifyImgAltTag.js:13:23)
at processTicksAndRejections (internal/process/task_queues.js:89:5)</failure>
<failure message="Failed [notEqual]: (
Image URL: https://<url>/bc/wp-content/uploads/Cars.jpg
Image Tag: img
) - expected [0;32m""[0m but got: [0;31m""[0m">Image URL: https://<url>/bc/wp-content/uploads/Cars.jpg
Image Tag: img
at NightwatchAPI.<anonymous> (/workspace/WebsiteLaunchAutomation/custom_commands/verifyImgAltTag.js:13:23)
at processTicksAndRejections (internal/process/task_queues.js:89:5)</failure>
My problem is when Jenkins reads the report, it only ever displays the first failure, when I am expecting it to display all the failures in the xml report.
Even worse, the nightwatch-html-reporter stops after the opening failure tag, and doesn’t print the stacktrace, or to the end of the first closing failure tag. Here is a bad example:
<failure message =“some message”> (stack trace and other ignored stuff)</failure>
So my question is, am I doing something to cause it to cut off like this? Can I change anything in the report so either of these tools can parse the report properly? (I’m not normally a javascript dev, I usually do selenium + java, and testng reports have always been fine)
Related
My script crashes and debugger is unable to catch the error. I even tried to try catch some functions but it didnt work.
Any suggestion how to narrow down where the problem could be?
The script is a testing script for a game. It works good for previous games, but for new game there are some new cases. Unfortunately I cannot know where is the error. Probably when unique case object is received from server.
The script is testing against the server and writing output to either console or file. In both cases error happens.
Error: Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)
edit:
here is SegfaultHandler output:
PID 2645 received SIGSEGV for address: 0x0
0 segfault-handler.node 0x00000001034ae1c8 _ZL16segfault_handleriP9__siginfoPv + 280
1 libsystem_platform.dylib 0x00007fff9364b52a _sigtramp + 26
2 ??? 0x0000000000000010 0x0 + 16
3 node 0x000000010067bbdc _ZN2v88internal23Runtime_GetFrameDetailsEiPPNS0_6ObjectEPNS0_7IsolateE + 2364
4 ??? 0x00000a107710961b 0x0 + 11065833330203
5 ??? 0x00000a107795c134 0x0 + 11065842057524
The exit code (139) means a segmentation fault occurred (128 + 11 (for segfault)).
You can use the segfault-handler module to debug the segmentation fault. You can use it like so:
var SegfaultHandler = require('segfault-handler');
SegfaultHandler.registerHandler("crash.log"); // With no argument, SegfaultHandler will generate a generic log file name
// Write the cause that causes the segmentation fault here
You should see a stack trace that you can now debug using tools like objdump -dS module.node.
objdump displays information about one or more object files.
I am getting an error which seems to be originating from one of the page scripts.
file://cdn.widgets.webengage.com/js/widget/webengage-min-v-3.0.js:1
return c.apply(undefined,a)}catch(d){webengage.eLog(d);if(!b){throw d}}}else{t
^
TypeError: Cannot call method 'call' of undefined
at new exports.NOT_IMPLEMENTED (/usr/local/lib/node_modules/jsdom/lib/jsdom/browser/utils.js:9:13)
at Object.webengage.eLog (file://cdn.widgets.webengage.com/js/widget/webengage-min-v-3.0.js:1:366)
at t.extend.u (file://cdn.widgets.webengage.com/js/widget/webengage-min-v-3.0.js:1:19160)
at Object.t.extend.error (file://cdn.widgets.webengage.com/js/widget/webengage-min-v-3.0.js:1:19299)
at file://cdn.widgets.webengage.com/js/widget/webengage-min-v-3.0.js:1:66518
at Object.webengage.withELog (file://cdn.widgets.webengage.com/js/widget/webengage-min-v-3.0.js:1:640)
at Timer.<anonymous> (file://cdn.widgets.webengage.com/js/widget/webengage-min-v-3.0.js:1:937)
at Timer.exports.setInterval.timer.ontimeout (timers.js:234:14)
I am getting this error from the following code:
try {
var document = jsdom.jsdom(str, null, {});
} catch(e) {
console.log("Got ERROR...");
console.log(e);
}
console.log("Page Document Loaded.");
var window = document.parentWindow;
//console.log(window.document.innerHTML);
console.log(window.innerWidth);
console.log(typeof window.document.getElementsByClassName);
here str is the html that i got earlier. I am able to see printed results, the html the innerWidth and the typeof getElementsByClassName i.e.. function. But after around 20 seconds i am getting the above error and my application crashes, without printing Got ERROR... from above.
The first question that i have is why is my application still running after printing the last thing. Is this a normal behavior for jsdom that it keeps on running like how in a browser a script keeps on running until window.close() is given.
The actual problem is, how can i resolve this. I want to trigger few events in this window object and interact with it but it keeps on crashing.
The url for the script is a little confusing:
file://cdn.widgets.webengage.com/js/widget/webengage-min-v-3.0.js:1
this is because the page is fetching this script resource in an ajax call with the url:
//cdn.widgets.webengage.com/js/widget/webengage-min-v-3.0.js:1
although jsdom is able to get the resource, i checked that this script has that line where it is showing the error.
For example, I want to run this part of code every time user click a new link in my UIWebView,
NSString* js =
#"var meta = document.createElement('meta'); "
"meta.setAttribute( 'name', 'viewport' ); "
"meta.setAttribute( 'content', 'width = device-width;initial-scale=1.0; maximum-scale=1.0' ); "
"document.getElementsByTagName('head')[0].appendChild(meta)";
[webView stringByEvaluatingJavaScriptFromString: js];
how can I do that? which API should I look at?
And I want this JS run in new page. How should I determine if the new page is fully loaded? –
There are two things likely to go wrong in this scenario: 1) your Js throws an exception and 2) the page reloads after your Js has run, and therefore reset the effects of your script.
In my experience, when a Javascript doesn't seem to run in a UIWebView, it's almost always the Javascript that is throwing an exception.
Try surrounding the script in try { ... } catch { ... } to capture the exception:
NSString* js =
#"try {"
"var meta = document.createElement('meta'); "
// [rest of the script...]
"document.getElementsByTagName('head')[0].appendChild(meta)";
" } catch (exc) { "
" window.ERR = exc.toString(); "
" } "
Now you can set a breakpoint in Xcode after your call to stringByEvaluatingJavaScriptFromString:. An error message might be available if you run
po [webView stringByEvaluatingJavaScriptFromString:#"window.ERR"]
In your debug prompt.
A good idea when you try out Javascript on your UIWebView is to first do exploratory
work in something like the Chrome Developer Tools to weed out the worst errors (e.g. syntax errors). If your code works there, the next step is to connect to the view using
Safaris Web inspector for iOS and see if it still does what it should.
#nilveryboring's point that you add scripts in webViewDidFinishLoading rather than in shouldStartLoadWithRequest is correct. In shouldStartLoadWithRequest the page hasn't been loaded yet, and any state you introduce at that point will be discarded by the loading page.
You can detect when the user clicks a link with:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
Once you have detected that he has clicked on a link, perform your js.
More on it in the Docs.
My add-on creates a FireFox File menu command that triggers callback function 'launchApp'.
function launchApp() {
var ww = Cc["#mozilla.org/embedcomp/window-watcher;1"]
.getService(Components.interfaces.nsIWindowWatcher);
var appUrl='chrome://mrT2/mrT00.xul'; // production (fails)
var appUrl='file:///C:/mpa/##mrT-2.0/mrT00.xul'; // testing (works)
var win = ww.openWindow(null, appUrl, "mrT2-window", "chrome,resizable", null);
// Summary of results of ww.openWindow() for various appUrl values:
// 'chrome:///mrT2/mrT00.xul' 'No chrome package registered for ...' (true)
// 'chrome://mrT00.xul' 'Invalid chrome URI: /' (true)
// 'chrome:///mrT00.xul' and 'chrome://mrT2/mrT00.xul' seem valid yet both give:
//Error: NS_ERROR_ILLEGAL_VALUE: Component returned failure code: 0x80070057 ...
// ... (NS_ERROR_ILLEGAL_VALUE) [nsIWindowWatcher.openWindow] (unexplained)
return true;
The above code works nicely and is great for testing mrT00.xul (because it collects the file directly from where I am editing it).
However when I interchange the two appUrl vars to try and open the exact same file as shipped via the xpi (and now internal to firefox) I get the dreaded 'illegal value' 0x80070057.
After 2 long days of research and study I cannot fault my code. Can you?
Otherwise, how may I begin tracing nsiWindowWatcher to pinpoint the error?
Bad things can happen when an extension attempts to open a xul file outside the /content directory or inside it when the chrome.manifest file in the .xpi root is not in order. Firefox handling of both these situations is not above reproach, warnings being offered in neither case.
I wrote a PhantomJS app to crawl over a site I built and check for a JavaScript file to be included. The JavaScript is similar to Google where some inline code loads in another JS file. The app looks for that other JS file which is why I used Phantom.
What's the expected result?
The console output should read through a ton of URLs and then tell if the script is loaded or not.
What's really happening?
The console output will read as expected for about 50 requests and then just start spitting out this error:
2013-02-21T10:01:23 [FATAL] QEventDispatcherUNIXPrivate(): Can not continue without a thread pipe
QEventDispatcherUNIXPrivate(): Unable to create thread pipe: Too many open files
This is the block of code that opens a page and searches for the script include:
page.open(url, function (status) {
console.log(YELLOW, url, status, CLEAR);
var found = page.evaluate(function () {
if (document.querySelectorAll("script[src='***']").length) {
return true;
} else { return false; }
});
if (found) {
console.log(GREEN, 'JavaScript found on', url, CLEAR);
} else {
console.log(RED, 'JavaScript not found on', url, CLEAR);
}
self.crawledURLs[url] = true;
self.crawlURLs(self.getAllLinks(page), depth-1);
});
The crawledURLs object is just an object of urls that I've already crawled. The crawlURLs function just goes through the links from the getAllLinks function and calls the open function on all links that have the base domain of the domain that the crawler started on.
Edit
I modified the last block of the code to be as follows, but still have the same issue. I have added page.close() to the file.
if (!found) {
console.log(RED, 'JavaScript not found on', url, CLEAR);
}
self.crawledURLs[url] = true;
var links = self.getAllLinks(page);
page.close();
self.crawlURLs(links, depth-1);
From the documentation:
Due to some technical limitations, the web page object might not be completely garbage collected. This is often encountered when the same object is used over and over again.
The solution is to explicitly call close() of the web page object (i.e. page in many cases) at the right time.
Some included examples, such as follow.js, demonstrate multiple page objects with explicit close.
Open Files Limit.
Even with closing files properly, you might still run into this error.
After scouring the internets I discovered that you need to increase your limit of the number of files a single process is allowed to have open. In my case, I was generating PDFs with hundreds to thousands of pages.
There are different ways to adjust this setting based on the system you are running but here is what worked for me on an Ubuntu server:
Add the following to the end of /etc/security/limits.conf:
# Sets the open file maximum here.
# Generating large PDFs hits the default ceiling (1024) quickly.
* hard nofile 65535
* soft nofile 65535
root hard nofile 65535 # Need these two lines because the wildcards (above)
root soft nofile 65535 # are not applied to the root user as well.
A good reference for the ulimit command can be found here.
I hope that puts some people on the right track.
I had this error come up while running multiple threads in my ruby program.
I was running phantomjs with Capybara-poltergeist and each thread was visiting a page opening up the same CSV file and writing to it.
I was able to fix it by using the Mutex class.
lock = Mutex.new
lock.synchronize do
CSV.open("reservations.csv", "w") do |file|
file << ["Status","Name","Res-Code","LS-Num","Check-in","Check-out","Talk-URL"]
$status.length.times do |i|
file << [$status[i],$guest_name[i],$reservation_code[i],$listing_number[i],$check_in[i],$check_out[i], $talk_url[i]]
end
end
puts "#{user.email} PAGE NUMBER ##{p+1} WRITTEN TO CSV"
end
end