How can I login with Cypress in a site that uses Google Auth? - google-oauth

I need to login with Cypress to a site that has Google Authenticator as a 2FV. I can enter mail & pass, but after this I need to complete the Authentication passcode shown in the app (Which changes constantly)
Is there any way to do this?
describe('empty spec', () => {
it('passes', () => {
cy.visit('website')
cy.get('[data-selenium-id="email"]').click()
cy.get('[name="email"]').type("mail")
cy.get('[name="password"]').type("Pass")
cy.get('[data-selenium-id="signInForm.signInButton"]').click()
})
})
After that, the passcode is needed to continue:
(https://i.stack.imgur.com/q9rKD.png)
I am expecting to skip this 2FV in anyway so that I can continue with my test using Cypress

Related

Cypress uncaught:exception handler not working with Magic.link flow

I'm using Cypress to test a login flow that uses Magic.link auth on a mobile Web device, which is encountering the ResizeObserver loop limit exceeded error, as it tries to navigate the Google Auth forms. I've looked at numerous posts, and played around with my test, but it seems the handler is not working.
The recommended Google Authentication from the Cypress docs is insufficient, because with Magic, the flow is initiated by a call to magic.oauth.loginWithRedirect, hence I was hoping to drive the process via the UI directly.
You'll see I added a test to ensure the password input is visible. Now the exception is being thrown at that part of the test. If I remove that check the error occurs on the next step where I try to type the password.
describe('my auth flow', () => {
it('can auth with google', () => {
// click login button from my site
cy.get('button')
.contains('sign-in')
.click();
cy.origin('https://accounts.google.com', () => {
// enter email address
cy.get('input[type=email]')
.type('myuser#mydomain.com');
cy.get('button')
.find('span')
.contains('Next')
.click();
// wait for password page to show
cy.get('#password')
.should('exist')
.and('be.visible'); // error here...
// enter password
// error here if above visibility check removed
cy.get('#password input[type=password]')
.type('mypassword');
cy.get('button')
.find('span')
.contains('Next')
.click();
});
});
});
In support/commands.js, I've added the global error handler, which should handle all uncaught exceptions according to the documentation.
Cypress.on(
'uncaught:exception',
(err) => false
);
Magic does have a test mode, however I really don't want to bypass the login flow. Ideally I could exercise the login flow without hacks for testing.
The cy.origin() command is an isolated sandbox with different document and window to the primary domain.
Try adding the exception handler inside the origin command (presuming the error is happening while on the google domain).
cy.origin('https://accounts.google.com', () => {
Cypress.on('uncaught:exception', (err) => false)

Cypress alert (pop-up) login at visit url

I have strange problem.
I want to automate one web site using Cypress. At the begining I need to enter credentials like username and password into the alert (pop-up) window. I tryed a lot of ways to handle this.
Here is my code that I used for handling alert (pop-up) windows, that contains input text element:
cy.window().then(($win) => {
cy.stub($win, 'prompt').returns(text)
cy.get(#randomId).click()
})
I wasn't sure if this is the correct way to handle this, thats why I tryed one package named: cypress-ntlm-auth. I tried to use this package, because it seems that the package handles "Windows Authentication login" when visiting a site for the first time. Here is the code that I tried:
cy.ntlm(['chiquito-qa.omnifitrgsites.co.uk'], "tainae", "nekazvam", "chiquito-qa");
cy.visit('chiquito-qa.omnifitrgsites.co.uk');
Btw the credentials are not real.
you could use this one
describe('auth with proper credentials', () => {
it('bypass login', () => {
cy.visit('your url', {
auth: {
username: 'enter username',
password: 'enter password,
},
})
})
})
I think the website use a basic authentication method to login simply use this pattern
cy.visit("http://username:password#chiquito-qa.omnifitrgsites.co.uk")
Or to simplify your process for other request use a base url on the cypress.json file
"baseUrl": "http://username:password#chiquito-qa.omnifitrgsites.co.uk"
You can do something like this. This will bypass the auth pop-up and will directly authenticate.
cy.visit('https://username:password#example.com')

How do I login to salesforce by using cypress?

I'm currently using cypress to do some testing. However, I have to do some tests with salesforce and it seems that I'm getting the following issue 'Whoops, there is no test to run.'
context('Salesforce', () => {
beforeEach(() => {
cy.request("https://test.salesforce.com/?un=username%40domain_name&pw=user_password&startURL=%2F001")
})
it('.click() - click on a DOM element', () => {
// load opportunity page
cy.visit('https://test.salesfroce.com/lightning/page/home')
// optional. let's the page load during the test runner
cy.wait(7000)
//cy.get('#username').type('username')
//cy.get('#password').type('password')
//cy.contains('Log In to Sandbox')
})
})
Does anyone know how to bypass the login page with cypress?
The problem that I had is that I was using a long password where extra characters didn't take into account. For this reason, I decided to change my password for something short, and now is working correctly.
This is the actual URL that you have to request and visit to make sure you can log in to your Salesforce account.
Take into consideration that cy.request is the link above & the cy.visit will be your dashboard URL.
"https://test.salesforce.com/?un=username%40domain_name&pw=user_password&startURL=%2F001

Auth.signIn() using Device - AWS Amplify with React-Native

I would like my react-native app to sign in automatically with the Device Remember option from cognito, but I didn't find an option in the Auth.signIn() method to pass the device instead the username and logon. Is there a better way of doing that?
It has method called currentAuthenticatedUser
Auth.currentAuthenticatedUser().then(() => {
// User is logged in
}).catch(() => {
// User is not logged in
})

Proper way to logout with react-native-fbsdk

I am using react-native-fbsdk to login through facebook on my react-native app.
I call LoginManager.logOut() to logout: it does not actually properly logout since the next time I try to login, it does not ask me for login/password again so I can only login on one account. I can not find a way to login to another facebook account.
This guy (react-native-fbsdk: How properly log out from facebook?) had the same problem and seem to have found no solution.
One trick on iOS is to go to safari then logout from the mobile facebook website. This does not work on android though :(
EDIT:
Here is my facebook login code:
function login() {
return LoginManager.logInWithReadPermissions(FACEBOOK_PERMISSIONS)
.then(result => {
if (result.isCancelled) {
throw new Error("Login canceled");
}
return AccessToken.getCurrentAccessToken();
})
.then(({ accessToken }) => accessToken);
}
Video of logout/login: https://d3vv6lp55qjaqc.cloudfront.net/items/132L2U1p383E1y0l2l2v/Screen%20Recording%202018-10-31%20at%2002.52%20PM.mov
So I found this solution, that is not a hack but the proper way to perform a logout on facebook. You need to create a GraphRequest to ask a deletion of permissions.
Below the code, I hope that will help you. I test it on Android and IOS, and that work like a charm.
FBLogout = (accessToken) => {
let logout =
new GraphRequest(
"me/permissions/",
{
accessToken: accessToken,
httpMethod: 'DELETE'
},
(error, result) => {
if (error) {
console.log('Error fetching data: ' + error.toString());
} else {
LoginManager.logOut();
}
});
new GraphRequestManager().addRequest(logout).start();
};
The problem is not with react-native-fbsdk but with Facebook or the browser through which the user logs in to connect to your app, the reason being every-time your app accesses the Facebook login through the browser or the Facebook app where the user-account is already logged-in, which is why it doesn't show you username or password fields.
To solve this issue, the user must logout from the browser or Facebook through which he/she logged in (for app permission initially) to your app, so when the user comes back to your app and selects the Facebook-login option, assuming user logged-out of your app as well, then he/she can see it redirecting to the Facebook or browser login page with username and password fields.