laravel dusk facebook web driver and cookies - selenium-webdriver

i was trying to login to a site with facebook chrome driver
and then visit another path of the website after login
login is successful but when I try to view another page
it dont recognize my login
here is my code :
$process = (new ChromeProcess)->toProcess();
$process->start();
$options = (new ChromeOptions)->addArguments(['--disable-gpu', '--headless','--enable-file-cookies','--disable-web-security','--allow-file-access-from-files']);
$capabilities = DesiredCapabilities::chrome()->setCapability(ChromeOptions::CAPABILITY, $options);
$driver = retry(5, function () use ($capabilities) {
return RemoteWebDriver::create('http://localhost:9515', $capabilities);
}, 50);
$browser = new Browser($driver);
$browser::$baseUrl = 'https://example.com';
$browser->visit('/login')
->type('username','1375344')
->type('password','23444')
->press('.login_btn');
$browser->waitForText('welcome');
$browser->visit('/statement/deposit/view');
$browser->dump();
does laravel dusk and/or facebook driver has something like cookiejar?

Try
$browser->loginAs(User::find(1));
Additionally you can look at
Dusk Authentication

Related

Class 'Google_Client' not found in cake php

I am working on google login in cake PHP. And I got one error while clicking on Google sign-in button.
"Class 'Google_Client' not found".
Can you help me how to solve this in cake PHP? I am new to CakePHP.
public function googlelogin(){
App::uses('Google_Client', 'Google');
$client = new Google_Client();
dd($client);
$client->setClientId(Configure::read('Google.googleClientID'));
$client->setClientSecret(Configure::read('Google.googleClientSecret'));
$client->setRedirectUri(Configure::read('Google.googleRedirectUrl'));
$client->setScopes([
"https://www.googleapis.com/auth/userinfo.profile",
'https://www.googleapis.com/auth/userinfo.email'
]);
$url = $client->createAuthUrl();
$this->redirect($url);
}
Version . 2.8

ng-admin how to connect remote server

I am green hand in ng-admin, and the question is:
Is it possible to connect to the remote server to get data? such as.
var admin = nga.application('QDNS Admin')
.baseApiUrl('http://remote host/');
Many thanks in advance
In your admin.js file you have to configure your API endpoints like this:
myApp.config(['NgAdminConfigurationProvider', function (nga) {
// create an admin application
var admin = nga.application('Name of your Admin')
.baseApiUrl('http://localhost:8080/api/');
//if you have an entity called users
nga.configure(admin);
}
And in your server.js you must have define a route
In your admin.js file you have to configure your API endpoints like this:
myApp.config(['NgAdminConfigurationProvider', function (nga) {
// create an admin application
var admin = nga.application('Name of your Admin')
.baseApiUrl('http://localhost:8080/api/');
//if you have an entity called users
// the API endpoint for this entity will be 'http://localhost:8080/api/users/
var user = nga.entity('users').identifier(nga.field('_id'));
user.listView()
.fields([
nga.field('username'),
nga.field('email'),
nga.field('password'),
nga.field('lastname'),
nga.field('firstname'),
nga.field('created_at'),
nga.field('updated_at')
]);
admin.addEntity(user);
nga.configure(admin);
}
And in your server.js you must have define a route

How to access any other's google calendar using google php api

I need access any other user's google calendar freebusy using google php api. Can any one help me step by step process to implement that. I have already checked the https://developers.google.com/google-apps/calendar/v3/reference/freebusy/query#response but nothing fruitful I got.
My Approach
session_start();
require_once ('libraries/Google/autoload.php');
$client = new Google_Client();
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setRedirectUri($redirect_uri);
$client->addScope("email");
$client->addScope("profile");
$client->addScope(Google_Service_Calendar::CALENDAR);
$client->addScope(Google_Service_Calendar::CALENDAR_READONLY);
$client->setAccessType('offline');
$service = new Google_Service_Oauth2($client);
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
exit;
}
/************************************************
If we have an access token, we can make
requests, else we generate an authentication URL.
************************************************/
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
} else {
$authUrl = $client->createAuthUrl();
}
$client->setApplicationName("My Calendar"); //DON'T THINK THIS MATTERS
$client->setDeveloperKey($api_key); //GET AT AT DEVELOPERS.GOOGLE.COM
$cal = new Google_Service_Calendar($client);
$calendarId = 'any_other_user_email#gmail.com';
$freebusy_req = new Google_Service_Calendar_FreeBusyRequest();
$freebusy_req->setTimeMin($minTime);
$freebusy_req->setTimeMax($maxTime);
$freebusy_req->setTimeZone($time_zone);
$freebusy_req->setCalendarExpansionMax(10);
$freebusy_req->setGroupExpansionMax(10);
$item = new Google_Service_Calendar_FreeBusyRequestItem();
$item->setId($email);
$freebusy_req->setItems(array($item));
$query = $cal->freebusy->query($freebusy_req);
$response_calendar = $query->getCalendars();
$busy_obj = $response_calendar[$email]->getBusy();
But I am getting blank in terms of free busy.
Just make sure the calendar is public, then try google calendar freebusy method. It will definitely work.

Protractor-net, non angular login page

Using protractor-net, Login page is non-angular, where as the home page is angular. hence cannot launch browser with url using NgWebDriver, probably since its looking for angular. tried angular.ignoreSynchronization="false". But same issue. If I use angDriver.WrappedDriver.FindElement to cross login, the angular objects in home page are not recognized-Asynchronous script error-timeout.
driver = new ChromeDriver("C:\\FTWork\\DriverFiles\\chromedriver_win32\\");
driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(20));
angDriver = new NgWebDriver(driver,"[ng-app='Phoenix']");
string root=angDriver.RootElement;
angDriver.WrappedDriver.Navigate().GoToUrl(url);
angDriver.WrappedDriver.Manage().Window.Maximize();
driver = angDriver.WrappedDriver;
driver.FindElement(By.Id("UserID")).Clear();
driver.FindElement(By.Id("UserID")).SendKeys("");
driver.FindElement(By.Id("Password")).SendKeys("");
driver.FindElement(By.Id("searchsubmit")).Click();
System.Threading.Thread.Sleep(10000);
string dolAmt = angDriver.FindElement(NgBy.Binding("activeValue")).Text;
I am hoping this will do it.
_driver = new ChromeDriver("C:\\FTWork\\DriverFiles\\chromedriver_win32\\");
_driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(10));;
//Do whatever for log in with chrome driver
string url = "url for angular page";
_ngWebDriver = new NgWebDriver(_driver, "[ng-app='Phoenix']");
//You have to naviagate to url in order the _ngWebDriver to know the angular page NOT click and go to angular page
_ngWebDriver.Navigate().GoToUrl(url);
_ngWebDriver.Manage().Window.Maximize();
//The script timeout is almost essential since most of protractor mechanism are dependent of client side script.
//start finding elements with NgBy class
NgWebElement ngElement = _ngWebDriver.FindElement(NgBy.Model("model"));
ngElement.Clear();
EDIT
driver = new ChromeDriver("C:\\FTWork\\DriverFiles\\chromedriver_win32\\");
driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(20));
driver.FindElement(By.Id("UserID")).Clear();
driver.FindElement(By.Id("UserID")).SendKeys("");
driver.FindElement(By.Id("Password")).SendKeys("");
driver.FindElement(By.Id("searchsubmit")).Click();
// Phoenix is the ng-app of the coming angular page
string url = "url for angular page containing [ng-app='Phoenix']"
NgWebDriver angDriver = new NgWebDriver(driver,"[ng-app='Phoenix']");
// don't switch to wrapper driver
angDriver.Navigate().GoToUrl(url);
angDriver.Manage().Window.Maximize();
driver = angDriver.WrappedDriver;
string dolAmt = angDriver.FindElement(NgBy.Binding("activeValue")).Text;

CakePHP Authcomponent session expires after using SSL unforce method

I am using SSL for 5 pages while during registration
https://www.example.com/step1
https://www.example.com/step2
https://www.example.com/step3 - Auth component login
https://www.example.com/step4
https://www.example.com/step5
After step 3, I am creating a Session of the user using Auth Component which automatically logs the user in by Auth component. However, after step 5, it will redirect to http://www.example.com/welcome
I am using SSL component unforced method to change HTTPS to HTTP .
Everything working fine but the problem is that once I reach the welcome page from step 5 (HTTPS) my auth component session expires. I have tried to debug it, but could not find any solution. Please note that without HTTPS all steps and sessions are working fine.
Code in AppController class :
function beforeFilter() {
parent::beforeFilter();
$this->_setupSecurity();}
function _setupSecurity() {
$this->Security->blackHoleCallback = '_badRequest';
if(Configure::read('forceSSL')) {
$this->Security->requireSecure('*'); }
}
/**
* The main SecurityComponent callback.
* Handles both missing SSL problems and general bad requests.
*/
function _badRequest() {
if(Configure::read('forceSSL') && !$this->RequestHandler->isSSL()) {
$this->_forceSSL();
} else {
$this->cakeError('error400');
}
exit;}
/**
* Redirect to the same page, but with the https protocol and exit.
*/
function _forceSSL() {
$this->redirect('https://' . env('SERVER_NAME') . $this->here);
exit;
}
Follow this link: May be you get your solution..
https://stackoverflow.com/a/4473178/983624
if you are using Cakephp 2.0 then go to the following folder
lib/Cake/Model/Datasource/
Open the CakeSession.php file and search for the following line
if (!isset($sessionConfig['ini']['session.cookie_secure']) && env('HTTPS'))
{
$sessionConfig['ini']['session.cookie_secure'] = 1; // Just comment this line and try it will works
}

Resources