CasperJS "Syntax error: Parse error" - phantomjs

I've just been starting to experiment with CasperJS for some testing purposes, but I'm apparently pretty crappy at it because I've isolated my code down to the very first task,:
"use strict";
var casper = require('casper').create({
verbose: true,
logLevel: 'debug'
waitTimeout: 10000
});
phantom.cookiesEnabled = true;
casper.start('http://foobar.com', function afterstart() {
if (this.exists('.logo-link')) {
this.echo('BOOYA! Page is loaded', 'INFO');
} else {
this.echo('Page didnt load, something went all screwy.', 'ERROR');
}
});
casper.run();
run it through a linter, made the appropriate changes, and I still get this error:
Test file: Test.js
FAIL SyntaxError: Parse error
# type: uncaughtError
# error: "SyntaxError: Parse error"
SyntaxError: Parse error
FAIL 1 tests executed in 0.103s, 0 passed, 1 failed.
Details for the 1 failed test:
In Test.js:0
uncaughtError: SyntaxError: Parse error
I've looked up some possible explanations, I added the phantom.cookiesEnabled = true, but I simply can't figure it out.

Two best answers taken from similar question getting more information from phantomjs "SyntaxError: Parse error" message are:
1) run it with node:
node Test.js
2) use online syntax checker like http://esprima.org/demo/validate.html

You're missing a comma:
logLevel: 'debug' <--- Right here
waitTimeout: 10000

Related

WebRTC Error - Session error description: Data channel type mismatch. Expected RTP, got SCTP

I am new to WebRTC and triyng to create my first app. I have found this article https://www.tutorialspoint.com/webrtc/webrtc_quick_guide.htm and did as it was said there. The resulted app works fine if I test it in the Chrome. But when I try to test this app in 2 browser (Chrome and Mozilla) it gives me this error:
Uncaught (in promise) DOMException: Failed to execute
'setRemoteDescription' on 'RTCPeerConnection': Session error code:
ERROR_CONTENT. Session error description: Data channel type mismatch.
Expected RTP, got SCTP..
This happens when I send an offer from Mozilla client and Chrome client tries to give an answer to this offer in this part of code:
myConnection.setRemoteDescription(new RTCSessionDescription(offer));
myConnection.createAnswer(function (answer) {
myConnection.setLocalDescription(answer);
send({
type: "answer",
answer: answer
});
}, function (error) {
alert("oops...error"); //<-- this alert fires all the time
});
I have googled this and all I have found is set new RTCPeerConnection(configuration, { optional: [{RtpDataChannels: false}] }) but if I do so then when I try to send a message it says that dataChannel.readyState is not openned.
What do I do wrong? Any help appriciated!
Thanks!
Remove optional: [{RtpDataChannels: true}] and then wait for the datachannel.onopen event to fire before attempting to send messages.

TestCafe - Test fails onGetBposShellInfoNavBarData

I am running TestCafe version 0.22.0 on Win10. I am not sure if my issue has something with the Win10 or not but unfortunately, I donĀ“t have another computer to test on. The issue is that my tests fail with error message "GetBposShellInfoNavBarData failed: SyntaxError: Unexpected end of JSON input"
Here is the simple code I use:
Error on page "https://outlook.live.com/mail/inbox": GetBposShellInfoNavBarData failed: SyntaxError: Unexpected end of JSON input
Browser: Chrome 69.0.3497 / Windows 10.0.0
await t.click('body > section > div > div > nav > div > div > div > a');
await t.typeText('#i0116', login);
await t.click('#idSIButton9');
await t.typeText('#i0118', password);
await t.click('#idSIButton9');
await t.maximizeWindow();
Test fails on this t.maximizeWindow(). It also fails with same error on next "t.click(Selector...) if I comment out t.maximizeWindow() line.
As #ioseph properly mentioned, this error occurs on your web page and is not related to TestCafe.
I recommend that you address this error on your website and run your tests again.
Alternatively, you can use the --skip-js-errors argument to ignore such errors.

react-apollo Error: Network error: Unexpected token < in JSON at position 1

I want to send a request to this server via Apollo and get a query :
const client = new ApolloClient({
link: new HttpLink({
uri:'http://mfapat.com/graphql/mfaapp/'}),
cache: new InMemoryCache()
})
const FeedQuery = gql
query{
allFmr{
fmrId,
name,
studio,
bedRm1,
bedRm2,
bedRm3,
bedRm4
}
}
`
But I'm facing this error message:
Unhandled (in react-apollo:Apollo(FMRScreen)) Error: Network error: Unexpected token < in JSON at position 1
at new ApolloError (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:109336:32)
at ObservableQuery.currentResult (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:109447:28)
at GraphQL.dataForChild (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:103192:66)
at GraphQL.render (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:103243:37)
....
But I can easily open "http://mfapat.com/graphql/mfaapp/" in my browser and get a query. Does anyone know where the problem is?
Right now, Apollo treats everything sent from the server as JSON. However, if there is an error, then your server might be sending HTML to show a basic error page.
To see the error, open your dev tools, and look at the network tab. This shows an example 401 error:
As you can see, if you were to parse this as JSON you would stumble over the first character: < which is where our error message comes from.
Reading the specific error sent enables you to fix the bug.
To fix the general error, configure your server to send JSON on HTTP errors, not HTML code. This should allow Apollo to parse it and display a sensible error page.
EDIT: Also see this discussion - hopefully they will change the default Apollo behavior, or at least provide useful discussion.
Base on #eedrah answer, I managed to resolve this issue by using an error handler middleware to always return erros as JSONs, so that Apollo Client error link can parse the errors.
// On Apollo server
// Error handler
const errorHandler = (err, req, res, next) => {
if (res.headersSent) {
return next(err);
}
const { status } = err;
res.status(status).json(err);
};
app.use(errorHandler);

How to use spiderable with a meteor app hosted on modulus.io

I'm trying to make spiderable works on my meteor app hosted on modulus with SSL.
I have Meteor 1.0, iron:router 1.0, spiderable and node package of phantomjs
All is working on localhost. But once I deploy on Modulus, first I had the error
spiderable: phantomjs failed: null
Then, I added the following environment variable in the modulus panel:
METEOR_PKG_SPIDERABLE_PHANTOMJS_ARGS = --ssl-protocol=tlsv1 --ignore-ssl-errors=yes --debug=true
This is still not working and the debug is outputting multiple times (like it's looping over an error) the following message in the modulus console:
2014-12-03T17:01:00 [DEBUG] WebPage - evaluateJavaScript "(function() { return (function () {
if (typeof Meteor === 'undefined'
|| Meteor.status === undefined
|| !Meteor.status().connected) {
return false;
}
if (typeof Package === 'undefined'
|| Package.spiderable === undefined
|| Package.spiderable.Spiderable === undefined
|| !Package.spiderable.Spiderable._initialSubscriptionsStarted) {
return false;
}
Tracker.flush();
return DDP._allSubscriptionsReady();
})(); })()"
2014-12-03T17:01:00 [DEBUG] WebPage - evaluateJavaScript result QVariant(bool, false)
If anyone knows how to solve this or succeeded to deploy a meteor project on modulus.io with SSL and spiderable. Let's me know the good way to do it :)
Thank a lot !
I solved my problem as follows:
I installed phantomjs locally and run the test script available at http://www.meteorpedia.com/read/spiderable/
phantomjs phantomtest.js
This gave me more details about the error: Parse Error.
Then, it was a javascript file that once compiled/minified, rendered an error caused by select2. The js library that was using it was flat-ui.js (http://designmodo.github.io/Flat-UI/).
I discover this by testing many deploys on *.meteor.com and by adding/removing .js file.
I edit the flat-ui.js library to avoid Parsing Error.
I redeployed on both modulus.io and *.meteor.com. All was working fine on *.meteor.com but still didn't work on modulus.io. That let me thinking about an SSL error but I only saw "spiderable: phantomjs failed: null" in the modulus.io logs.
I add the following environment variable in the modulus panel:
METEOR_PKG_SPIDERABLE_PHANTOMJS_ARGS = --debug=true
and it appears that it was a "SSL Handshake error":
[DEBUG] Network - Resource request error: 6 ( "SSL handshake failed" )
I add another option to the METEOR_PKG_SPIDERABLE_PHANTOMJS_ARGS environment variable:
METEOR_PKG_SPIDERABLE_PHANTOMJS_ARGS = --ignore-ssl-errors=yes --debug=true
Now everything is working fine on modulus.io.
To sumup:
solve javascript errors
add METEOR_PKG_SPIDERABLE_PHANTOMJS_ARGS = --ignore-ssl-errors=yes
I hope this will help some dudes,

mocha selenium test simple example not working

I am trying to get an understanding of how to use mocha and selenium together. I found a simple tutorial but as soon as it starts I get the following error
Google Search
1) should work
0 passing (2s)
1 failing
1) Google Search should work:
Error: timeout of 2000ms exceeded
at null.<anonymous> (/usr/local/lib/node_modules/mocha/lib/runnable.js:157:19)
at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)
Here is the code that I have
var assert = require('assert'),
test = require('selenium-webdriver/testing'),
webdriver = require('selenium-webdriver');
test.describe('Google Search', function() {
test.it('should work', function() {
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.firefox()).
build();
driver.get('http://www.google.com');
var searchBox = driver.findElement(webdriver.By.name('q'));
searchBox.sendKeys('simple programmer');
searchBox.getAttribute('value').then(function(value) {
assert.equal(value, 'simple programmer');
});
driver.quit();
});
});
So I ran the following command to test selenium-webdriver and it fails only for mocha
npm test selenium-webdriver
Error I get
1) Mocha Integration it properly allows timeouts and cancels control flow :
Error: timeout of 1000ms exceeded
at Test.done (/usr/local/lib/node_modules/mocha/lib/runnable.js:204:67)
at Test.runnable.callback.mochaCallback (/Users/jcostanzo/Work/Development/automation/phantomjs/node_modules/selenium-webdriver/test/testing/index_test.js:61:30)
at Test.cleanupBeforeCallback [as callback] (/Users/jcostanzo/Work/Development/automation/phantomjs/node_modules/selenium-webdriver/testing/index.js:123:52)
at null.<anonymous> (/usr/local/lib/node_modules/mocha/lib/runnable.js:157:10)
at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)
You can increase the timeout by calling this.timeout(5000) either in the describe function or in the it function.
Find all the details and examples here: http://visionmedia.github.io/mocha/#suite-specific-timeouts