Social Login with protractor - angularjs

I'm trying to login in my app with google and protractor. I can't find the error. It seems that a element is not present but the element is working fine in the test. Please help me with this.
Here is the test's code
browser.getAllWindowHandles().then(function (handles) {
var popupHandle = handles[1];
browser.switchTo().window(popupHandle);
var email = browser.driver.findElement(by.name('Email'));
var signIn = browser.driver.findElement(by.name('signIn'));
email.sendKeys(browser.params.login.user || process.env.GOOGLE_USER);
signIn.click();
browser.driver.sleep(2000);
var password = browser.driver.findElement(by.name('Passwd'));
password.sendKeys(browser.params.login.password || process.env.GOOGLE_PASS);
var login = browser.driver.findElement(by.css('.rc-button'));
login.click();
browser.driver.sleep(10000);
browser.driver.switchTo().window(handles[0]);
});
and here is the error
16:30:05.655 INFO - Done: [find element: By.cssSelector: *[name="signIn"]]
16:30:05.659 INFO - Executing: [click: 3 [[ChromeDriver: chrome on LINUX (e0625e8b3f72a0f40228f4f4e90c2c9d)] -> css selector: *[name="signIn"]]])
16:30:05.945 WARN - Exception thrown
org.openqa.selenium.ElementNotVisibleException: element not visible
I don't know if there is a workaround to do this but I can't find a solution in order to login with protractor. Please help

May be your sign-in button is enabled only after your email is validated. You should do something like below
var EC = protractor.ExpectedConditions;
browser.wait(EC.visibilityOf(signIn,5000).then(function() { signIn.click()}):       
     

Thank you... I've tried that but it doesn't work... What really worked for me was put the login code into the onPrepare function in the config file.
Like this.
onPrepare: function() {
var site = browser.params.site;
browser.get(site);
element(by.css('.btn-crearseguro-nav')).click();
element(by.id('gm')).click();
//Sign in with to popup
browser.getAllWindowHandles().then(function (handles) {
var popupHandle = handles[1];
browser.switchTo().window(popupHandle);
var email = browser.driver.findElement(by.name('Email'));
var signIn = browser.driver.findElement(by.name('signIn'));
email.sendKeys(browser.params.login.user || process.env.GOOGLE_USER);
signIn.click();
browser.driver.sleep(10000);
var password = browser.driver.findElement(by.name('Passwd'));
password.sendKeys(browser.params.login.password || process.env.GOOGLE_PASS);
var login = browser.driver.findElement(by.id('signIn'));
login.click();
browser.driver.sleep(5000);
browser.driver.switchTo().window(handles[0]);
});
},
And it work's fine... But thanks for yout comment... Sure I will use it in another test (y)

Related

Protractor : Error: Error while waiting for Protractor to sync with the page: "window.angular is undefined. If i create new object of PageObject

I am trying to create a object of page object into spec and i am getting the error.
dashboard.pageObject.js
/*global exports,console*/
module.exports = function(){
this.dashboarurl = 'http://localhost:2525/ars-webapp/';
this.createNewReport_Clickhear = element(By.xpath("//a[contains(.,'Click Here')]"));
this.reportInputModel = element(by.model('reportDefCntrl.reportDef.reportname'));
this.reportDescriptionModel = element(by.model('reportDefCntrl.reportDef.reportdesc'));
this.templateListSelect = element(By.xpath("//select[#id='template-list-select']")).click();
this.selectAlarmDashboarTemplate= element(By.xpath("//option[contains(#value,'number:2')]"));
this.durationOfAlarmTemplate = element(By.xpath("//span[#class='ui-select-placeholder text-muted ng-binding']"));
this.duration_Daily = element(By.xpath("//span[contains(.,'Daily')]"));
this.addObject = element(By.xpath("//button[#data-ng-click='reportDefCntrl.addLogObjects()']"));
this.searchInput = element(By.xpath("//input[#type='search']"));
this.searchButton = element(By.xpath("//button[contains(.,'Search')]"));
this.selectAllButton = element(By.xpath("//button[contains(.,'SelectAll')]"));
this.addObjectButton = element(By.xpath("//button[#data-ng-click='addLogObjectsCntrl.submitObjects()']"));
this.saveButton = element(By.xpath("//button[contains(.,'Save')]"));
}
Specfile is
/global require,console/
var Dashboard = require('../pageObjects/dashboard.pageObject.js');
var dashboard = new Dashboard();
describe('angularjs homepage todo list', function() {
it('should add a todo', function() {
browser.get(dashboard.dashboarurl);
}
if i skip the line
var dashboard = new Dashboard();
and provide
browser.get('http://localhost:2525/ars-webapp/');
instead of
browser.get(dashboard.dashboarurl);
it's working .
but i can't use feature of page object.
if i use
var dashboard = new Dashboard();
so i am getting error
E/launcher - Error while waiting for Protractor to sync with the page:
"window.angular is undefined. This could be either because this is a
non-angular page or because your test involves client-side navigation,
which can interfere with Protractor's bootstrapping. See
http://git.io/v4gXM for details"
Oh Man .. found it !!.. Everything was fine in your code. You know what .. The problem was .. you had a click() in this line this.templateListSelect = element(By.xpath("")).click() in your file - dashboard.pageObject.js
Since you have a require() first .. The dashboard file is executed first and click() is trigerred even before browser.get() and thats the reason you were seeing that error

Integrating cordova plugin paypal with ionic

I'm trying to use the paypal-cordova-plugin to integrate paiement on my mobile app. But the instructions I am following are asking for sandbox id and production id but I have no idea where to find them in paypal. Can someone help me on this ?
This is the place where they are asked
angular.module('app')
.constant("shopSettings", (function () {
return {
payPalSandboxId: "Aar8HZzvc5NztVWodTBpOiOod9wWrBDrJUjyvRr4WsxcCD28xYig7oecfYsqxQUDu5QHptPpSALirxZD",
payPalProductionId : "production id here",
payPalEnv: "PayPalEnvironmentSandbo", // for testing production for production
payPalShopName : "SenPass",
payPalMerchantPrivacyPolicyURL : "url to policy",
payPalMerchantUserAgreementURL : "url to user agreement"
}
})());
This is the link I'm following : http://ionicandroidlearning.blogspot.fr/2015/11/ionic-paypal-integration.html
First you need to create an account on paypal developers.
Then inside the dashboard create a new application (REST API apps).
When you create the new app, Paypal will generate a sandbox account and a client id for you.
Add the code (example):
var configuration=function () {
var configOptions = {
merchantName: "Some name you have specified",
merchantPrivacyPolicyURL: "http://yourserver/privacypolicy",
merchantUserAgreementURL: "http://yourserver/agreement",
languageOrLocale: "en_US"
};
// for more options see paypal-mobile-js-helper.js
var _config = new PayPalConfiguration( configOptions );
return _config;
}
var onPrepareRender = function(){
$log.info(" ======= onPrepareRender ==========");
}
var onPayPalMobileInit = function(){
var payPalConfig = configuration();
PayPalMobile.prepareToRender("PayPalEnvironmentSandbox", payPalConfig, onPrepareRender);
deferred.resolve( payPalConfig );
}
var clientIDs = {
"PayPalEnvironmentProduction": '', //leave it blank
"PayPalEnvironmentSandbox": 'your sandbox id'
};
PayPalMobile.init(clientIDs, onPayPalMobileInit);
to retrive PayPal Sandobx keys try to go here:
https://developer.paypal.com/developer/accounts/
click on your generated account for testing (in the table) and then on Profile ...it open a modal with some tabs .. choose the API Credential tab
Hope it can help you

Ionic Push to specific user from Ionic.io

I am trying to implemented ionic push from ionic.io.
Sending push to all users are working, but sending push to a specific user is not working.
The codes for ionic push are following as below:
function IonicPushInit(){
var push = new Ionic.Push();
var callback = function(token) {
push.saveToken(token);
}
push.register(callback);
}
function IonicIoLogin(){
var user = Ionic.User.current();
if (user.isAuthenticated()) {
IonicPushInit();
} else {
var details = {
'email': 'asdsadsads#mail.com',
'password': 'secretpassword'
};
var options = { 'remember': true };
Ionic.Auth.login('basic', options, details).then(function(sucRes){
IonicPushInit();
}, function(err){
Ionic.Auth.signup(details).then(function(s){
IonicPushInit();
}, function(e){
alert(e);
});
});
}
}
IonicIoLogin();
After execute above codes, when I send a push to all users from ionic.io, it works. But if I send a push to a specific user with following condition, it doesn't work.
So I've checked the user "asd...#mail.com" in User Tab, but in ther the push tab is empty. Is this the reason? Why it is empty?
What's wrong with above the codes?
Your code seems good, so it has to be something with project configuration.
Did you follow ionic documentation to use "Full setup"? Assign tokens to real users does not work on "Limited setup" => http://docs.ionic.io/docs/push-full-setup
After follow steps of "Full setup" I had your problem.
Then I realized that register doesn't work in browser or emulator. You have to try it on real device.
To have more information about your register function, just use:
var push = new Ionic.Push({"debug": true});

Firebase: How can i use onDisconnect during logout?

How can i detect when a user logs out of firebase (either facebook, google or password) and trigger the onDisconnect method in the firebase presence system. .unauth() is not working. I would like to show a users online and offline status when they login and out, minimize the app (idle) - not just when the power off their device and remove the app from active applications on the device.
I'm using firebase simple login for angularjs/ angularfire
Im using code based off of this tutorial on the firebase site.
https://www.firebase.com/blog/2013-06-17-howto-build-a-presence-system.html
Please i need help with this!
Presence code:
var connectedRef = new Firebase(fb_connections);
var presenceRef = new Firebase(fb_url + 'presence/');
var presenceUserRef = new Firebase(fb_url + 'presence/'+ userID + '/status');
var currentUserPresenceRef = new Firebase(fb_url + 'users/'+ userID + '/status');
connectedRef.on("value", function(isOnline) {
if (isOnline.val()) {
// If we lose our internet connection, we want ourselves removed from the list.
presenceUserRef.onDisconnect().remove();
currentUserPresenceRef.onDisconnect().set("<span class='balanced'>☆</span>");
// Set our initial online status.
presenceUserRef.set("<span class='balanced'>★</span>");
currentUserPresenceRef.set("<span class='balanced'>★</span>");
}
});
Logout function:
var ref = new Firebase(fb_url);
var usersRef = ref.child('users');
service.logout = function(loginData) {
ref.unauth();
//Firebase.goOffline(); //not working
loggedIn = false;
seedUser = {};
clearLoginFromStorage();
saveLoginToStorage();
auth.logout();
};
The onDisconnect() code that you provide, will run automatically on the Firebase servers when the connection to the client is lost. To force the client to disconnect, you can call Firebase.goOffline().
Note that calling unauth() will simply sign the user out from the Firebase connection. It does not disconnect, since there might be data that the user still has access to.
Update
This works for me:
var fb_url = 'https://yours.firebaseio.com/';
var ref = new Firebase(fb_url);
function connect() {
Firebase.goOnline();
ref.authAnonymously(function(error, authData) {
if (!error) {
ref.child(authData.uid).set(true);
ref.child(authData.uid).onDisconnect().remove();
}
});
setTimeout(disconnect, 5000);
}
function disconnect() {
ref.unauth();
Firebase.goOffline();
setTimeout(connect, 5000);
}
connect();

emails from gmail but response is gmail.readonly

I am trying to get the emails from gmail using https://www.googleapis.com/auth/gmail.readonly/?access_token='fdrt654vfdgfe6545But in response I am getting gmail.readonlyBut the System.HttpResponse[Status=OK, StatusCode=200] is fine. Can any guide me is there anything I am missing out.
This I how I requested got auth but in the response I received access token
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/client:plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/client:plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
var AuthStates = {google: null};
function signinCallback(authResult) {
if (authResult['status']['signed_in']) {
// Update the app to reflect a signed in user
// Hide the sign-in button now that the user is authorized, for example:
document.getElementById('signinButton').setAttribute('style', 'display: none');
//alert(authResult['code']);
console.log('code state: ' + authResult['code']);
//console.log('authResult : ' + authResult[]);
AuthStates.google = authResult;
console.log('authResult 1 : ' + authResult['status']['method']);
console.log('auth Result : ' + authResult['id_token']);
//{!access_token} = authResult['access_token'];
//{!code} = authResult['code'];
connection(authResult['access_token'], authResult['code']);
} else {
// Update the app to reflect a signed out user
// Possible error values:
// "user_signed_out" - User is signed-out
// "access_denied" - User denied access to your app
// "immediate_failed" - Could not automatically log in the user
console.log('Sign-in state: ' + authResult['error']);
}
}
</script>
<apex:outputPanel >
<span id="signinButton">
<span
class="g-signin"
data-callback="signinCallback"
data-clientid="clientid"
data-cookiepolicy="single_host_origin"
data-scope="https://www.googleapis.com/auth/gmail.readonly"
data-response_type="code"
data-redirect_uri="http://test-on.ap1.visual.force.com/apex/Gmail_inbox">
</span>
</span>
<apex:form >
So as i got my access token from my request I can go directly for getting all information related to the logedin user. As I am getting all the information regarding the user I am trying to get all the emails related to him. Is I am doing right or I am wrong any place. I am very new with api and web service trying to learn. please do help me put out.
You're actually making an HTTP GET call to that URL ( https://www.googleapis.com/auth/gmail.readonly/?access_token= ...)? Isn't that just the auth scope identifier?
Once you have a valid Oauth2 token you can set in the Auth header then you can make HTTP requests to the API. For example, to list messages see:
https://developers.google.com/gmail/api/v1/reference/users/messages/list
That has the URL to access (GET https://www.googleapis.com/gmail/v1/users/me/messages ) then once you have the message IDs you can get the messages individually following: https://developers.google.com/gmail/api/v1/reference/users/messages/get (e.g. GET https://www.googleapis.com/gmail/v1/users/me/messages/ ).
Usually there are good client libraries for the Google APIs. Not sure if that works for you, but see, for example:
https://developers.google.com/gmail/api/downloads

Resources