CasperJS Login to Facebook - phantomjs

After trying this answer
How to login into a website with CasperJS? I didn't work apparently fill function is the one failing
Now facebook doesn't have emai, and pass as direct children of login_form does this affect the code ? I figured it stops at this.test.assert...
my code
var casper = require('casper').create({
pageSettings: {
loadImages: false, // The WebPage instance used by Casper will
loadPlugins: false, // use these settings
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4'
}
});
var url = 'https://www.facebook.com/';
casper.start(url, function() {
console.log("page loaded");
this.test.assertExists('form#login_form', 'form is found');
this.fill('form#login_form', {
email: 'email',
pass: 'pass'
}, true);
});
casper.then(function() {
this.evaluateOrDie(function() {
return /message sent/.test(document.body.innerText);
}, 'sending message failed');
});
casper.run(function() {
this.echo('message sent').exit();
});
In case no answers I got what I need working with PhantomJS only

Version problem, not clear what was the problem.

Change the call to phantomjs in the batchbin/casperjs.bat file from
call phantomjs "%CASPER_BIN%bootstrap.js" --casper-path="%CASPER_PATH%" --cli %ARGV%
to
call phantomjs --ignore-ssl-errors=yes "%CASPER_BIN%bootstrap.js" --casper-path="%CASPER_PATH%" --cli %ARGV%
This simply forces the ignore-ssl-errors on every call to phantomjs, which for my use case was fine. This is not a fix, just a hack.
https://github.com/n1k0/casperjs/issues/49

Related

Share screen in safari 13 with agora sdk

I am using agora-rtc-sdk 3.3.0. When i click on "share screen" and gave permission (problem is not with getDisplayMedia) safari reload page. The line which cause it, is client.publish(stream), if comment this line stream created successfully (according to console), same as client but i cant publish my "screen sharing" stream. This bug appears only in safari 13, other browsers works fine. Adding this part of code.
const beginShare = async() => {
agoraShareStream = AgoraRTC.createStream({
streamID: SHARE_ID,
audio: false,
video: false,
screen: true
});
await agoraShareStream.init(() => {
console.log('init local stream success')
});
setShareStream(agoraShareStream);
enqueueSnackbar("Started screen sharing", { variant: "info" });
}
const createShareClient = async() => {
const agoraShareClient = AgoraRTC.createClient({
mode: "rtc",
codec: "vp8"
});
await agoraShareClient.init(appId);
await agoraShareClient.join(getAgoraToken({ uid: SHARE_ID, channel }), channel, SHARE_ID);
agoraShareClient.publish(agoraShareStream);
setShareClient(agoraShareClient);
}
Unfortunately, Agora doesn't support screen sharing on Safari as noted in the documentation here: https://docs.agora.io/en/Video/screensharing_web?platform=Web#introduction
The Agora RTC Web SDK supports screen sharing in the following desktop browsers:
Chrome 58 or later
Firefox 56 or later
Edge 80 or later on Windows 10+

Chromium won't load any websites and keeps crashing

All of the sudden my scripts aren't working anymore.
const puppeteer = require("puppeteer");
async function run() {
const browser = await puppeteer.launch({
headless: false
});
const page = await browser.newPage();
await page.goto("https://www.google.com");
// browser.close();
}
run();
When I run node index.js, Chromium launches, however, it is all white, then my mouse turns into the little rainbow spinning circle (Mac) and it crashes and I get the following error:
(node:37226) UnhandledPromiseRejectionWarning: Error: Navigation failed because browser has disconnected!
Thanks for any help!
I had the same problem on mac and solved it by adding '--no-sandbox' to the chrome args.
You can expose it as an env variable like so:
CHROME_ARGS=--no-sandbox
or add it to your browser.launch configuration:
const browser = await puppeteer.launch({
headless: false,
args: ['--no-sandbox']
});

Interaction between restartBrowserBetweenTests with onPrepare()

I want each of my tests to run on clean browser (Firefox) so i use restartBrowserBetweenTests:true option. Because i use non-Angular demo app, in onPrepare() function i use browser.waitForAngularEnabled(false). It's works fine, when i run a single spec, but when i run 2 specs, i have error.
Angular could not be found on the page. If this is not an Angular application, you may need to turn off waiting for Angular.
How can i solve this? And in addition, how onPrepare works in this case - every time when browser starts or one time before all specs?
Here is my conf.js
const screenshotReporter = require('./screenshotCustomReporter')
exports.config = {
capabilities: {
browserName: 'firefox'
},
restartBrowserBetweenTests: true,
framework: 'jasmine',
directConnect: true,
baseUrl: URL,
specs: ['path/**/*Spec.js'],
// Options to be passed to Jasmine.
jasmineNodeOpts: {
defaultTimeoutInterval: 30000,
includeStackTrace: true
},
onPrepare: () => {
require("#babel/register");
jasmine.getEnv().addReporter(screenshotReporter)
browser.waitForAngularEnabled(false)
}
}
You can recreate this issue using the following simple project:
conf.js
exports.config = {
framework: 'jasmine',
specs: ['./app.1.js', './app.2.js'],
seleniumAddress: 'http://localhost:4444/wd/hub',
restartBrowserBetweenTests:true,
onPrepare:function(){
browser.waitForAngularEnabled(false);
},
}
app.1.js
describe('second test', () => {
it('should check is displayed successfully', () => {
browser.driver.get("https://stackoverflow.com");
browser.driver.sleep(5000);
expect(element(by.linkText('Ask Question')).isDisplayed()).toBe(true);
});
});
app.2.js
describe('first test', () => {
it('should check is displayed successfully', () => {
browser.driver.get("https://stackoverflow.com");
browser.driver.sleep(5000);
expect(element(by.linkText('Ask Question')).isDisplayed()).toBe(true);
});
});
OnPrepare is defined for all settings need to be executed for suite. It means it
is always one time operation irrespective of number of spec files.
One concept you need to understand is that whenever the new instance of
firefox browser is launched then WebdriverJs initialize the instance of webdriver.
and global object browser in protractor also gets initialized.
In your case First spec file start firefox browser, OnPrepare function is executed afterwards and
default setting of protractor is overriden by WaitForAngularEnabled.But when you run second spec file,
again firefox browser is launched with fresh instance of webdriver and protractor browser which expect
angular application and in that case test case gets failed.
The solution for this problem is to use before function in spec file
describe('first test', () => {
before(() => {
browser.waitForAngularEnabled(false);
});
it('should check is displayed successfully', () => {
browser.driver.get("https://stackoverflow.com");
browser.driver.sleep(5000);
expect(element(by.linkText('Ask Question')).isDisplayed()).toBe(true);
});
});
Note : If you are using restartBrowserBetweenTests: true then you will have to use beforeEach() function for waitForAngularEnabled because every time fresh instance of webdriver will be created.

CasperJS Not Rendering Google Recaptcha

I'm trying to bypass a form protected by recaptcha using CasperJS. I'm using a third party service the provide the function to bypass recaptcha, however the captcha is never rendered.
var casper = require('casper').create({
pageSettings: {
userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11"
},
verbose: true,
logLevel: "debug"
});
casper.start("https://website.com/protected/form");
casper.then(function() {
casper.wait(5000, function() {
casper.capture('/home/phantomjs/downloaders/screenshot-1.png');
});
});
casper.run();
Upon viewing the screenshot I see the recaptcha form is never rendered. I've tried adjusting the wait time to a longer period, no matter how long I wait it's never rendered.

getting "Uncaught TypeError: Cannot call method 'replace' of undefined" when doing FB.init using Facebooker2

I am using Facebooker2 to create a Facebook IFrame application, which is running as a tab inside a Facebook page.
My goal is to be able to use the social plugins, such as a like button and comments, etc. I tried to define them as follows
<div class="fb-like" data-href="http://www.myurl.com" data-send="false" data-layout="button_count" data-width="450" data-show-faces="false"></div>
and trying to initialize the FB JS SDK by calling
<%= fb_connect_async_js %>
which outputs
<div id="fb-root"><script async="" src="http://connect.facebook.net/en_US/all.js"></script></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'APP_ID',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
oauth : true,
xfbml : true // parse XFBML
});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
This has worked before, and stopped working after Facebook pushed their last platform update about a month ago. Now the Like button is not being rendered at all. I also tried the XFBML approach, no luck.
note: I am able to publish feeds using FB.publish, and I am also able to create a like button using the IFrame method.
I looked at the documentation and didn't see anywhere where it was mentioned that Social plugins cannot be used inside IFrame apps.
any ideas anyone?
I've encountered the same issue, and the only workaround i could find is to set a timer to execute FB.XFBML.parse();
If anyone has a better solution, I'd be thanksfull to hear it !
window.fbAsyncInit = function() {
setTimeout(function(){
FB.XFBML.parse();
FB.Event.subscribe('auth.login', function(response) {
fbLogin();
});
FB.Event.subscribe('auth.logout', function(response) {
fbLogout();
});
/* Additional initialization code here */
},
1000);
var params = {
appId : facebookAppId,
channelUrl : siteurl+'facebookChannelFile.php',
status : true,
cookie : true,
oauth : true,
xfbml : true
};
FB.init(params);
};