How to enable browser notifications using Cypress - cypress

I am using Cypress for e2e testing and the site I am testing requires to have the notification permission granted.
For manual testing, I go to chrome preferences->Privacy and Security->Site Settings->Notifications and set the site url to 'Allow'
But how do I do this on Cypress ?

To do this on Cypress you need the index.html and then you can do this first test to confirm that the browser support notifications:
/// <reference types="Cypress" />
describe('Browser notifications', () => {
it('are supported by the test browser', () => {
cy.visit('index.html')
cy.window().should('have.property', 'Notification').should('be.a', 'function')
})
})
If you enable notifications from Cypress itself, you will see a popup if you click "Notify me!" button.
The rest of the tests stubs Notification constructor to avoid popups

You can use the cypress-browser-permissions
plugin.

Related

Cypress cy.origin() & Google sign in not working

I'm trying to login to our site which uses Auth0 and Google Sign in but I'm having issues with cy.origin it's behaving different in each browser, none of which is letting me log in. This is my test:
import { loginPage } from '../../page-objects/login-page'
describe('Login Tests', () => {
beforeEach(() => {
loginPage.visit()
})
it('GoogleLogin', () => {
// Click google sign in button - On My Base URL
cy.get("a[data-testid='googleSignInButton']").click()
// I'm now on an Auth0 Page where I click the Google Sign In Button
cy.get("a[class='auth0-lock-social-button auth0-lock-social-big-button']").click()
// Now I am on the accounts.google.com domain
cy.origin('https://accounts.google.com', () => {
// enter email on accounts.google.com
cy.get("input[type='email']").type('myemail#gmail.com')
// click next button seen on accounts.google.com page
cy.get(
"button[class='VfPpkd-LgbsSe VfPpkd-LgbsSe-OWXEXe-k8QpJ VfPpkd-LgbsSe-OWXEXe-dgl2Hf nCP5yc AjY5Oe DuMIQc LQeN7 qIypjc TrZEUc lw1w4b']",
).click()
})
})
})
The issues I'm seeing are:
In Chrome once I get to accounts.google.com the test times out with "Timed out after waiting 60000ms for your remote page to load on origin(s)"
In Firefox the test times out with the same error as on Chrome but on the Auth0 page instead of accounts.goole.com
In Electron when I click the Google Sign in button on Auth0 I'm taken to accounts.google.com but a message is displayed "403. That’s an error. We're sorry, but you do not have access to this page. That’s all we know."
In Edge I can get to accounts.google.com and enter "myemail#gmail.com" and click the next button but then I see a message "This browser or app may not be secure.
Try using a different browser. If you’re already using a supported browser, you can try again to sign in." with a Try again button.
Four browsers are all reacting differently and not one is letting me actually login, can anyone see what I've done wrong?

Before/After spec not working as expected

In my Cypress configuration I have a before and after spec:
on('before:spec', () => {
console.log('before spec');
});
on('after:spec', () => {
console.log('after spec');
});
When I do cypress:run I see the before and after logged with each spec. But when I run cypress:open I see a the before spec when I open the Cypress client, not when I open the spec. The after spec is also not logged when the test is finished, but rather when the Cypress client is closed.
From the documentation:
The after:spec event fires after a spec file is run. When running
cypress via cypress open, the event will fire when the browser closes.
and
When running via cypress open, the after:spec event only fires if the experimentalInteractiveRunEvents flag is enabled.

Does cypress support sales force

I tried to logon to SF application using cypress script
it is logging on but the moment it logs on cypress runner in left pane disappearing and test is not running further
it("should sales force page is open", () => {
cy.visit("https://***-digital--fpqa.my.salesforce.com/")
cy.get('#username').type('murali.naidu#******')
cy.get('#password').type('*****')
cy.get('#Login').click()
cy.wait(1000)
cy.url().should('include','sSSA')
})**strong text**

Accessing background page for firefox add-on in puppeteer

Is it possible to get background_page target for Firefox Add-on in puppeteer?
For testing chrome extensions, I can easily access the background_page when extension is loaded by doing the following:
// Bring up chrome browser with extension loaded
const browser = await puppeteer.launch({
headless: false,
defaultViewport: null,
ignoreHTTPSErrors: true,
timeout: 0,
args: [
`--disable-extensions-except=${CRX_PATH}`,
`--load-extension=${CRX_PATH}`,
'--ignore-certificate-errors',
'--no-sandbox',
'--disable-setuid-sandbox',
'--window-size=1920,1080',
],
});
// Fetch browser targets
const targets = await browser.targets();
// Filter out background_page for extension from the targets
const backgroundPageTarget = targets.find((target) => {
return target.type() === 'background_page';
});
I was able to load my firefox add-on by following these guides:
https://github.com/puppeteer/puppeteer/issues/4162
https://github.com/puppeteer/puppeteer/blob/f26bb7f4c44d9b7db5cc73c4af32db6fa5bcd3a2/experimental/puppeteer-firefox/README.md#add-ons
However, I've been unable to access the background_page of the add-on. I need that to intercept and validate requests and responses made by the add-on.
I managed to make it work with Selenium by following these steps:
Open up the same Firefox browser application that you're making Puppeteer connect to.
Load the extension the same way that you make Puppeteer load it (there's different ways, I did it by loading an unsigned version with Firefox dev edition).
Activate the popup window for the extension, then right click and select View page source.
In the URL, you should see this pattern view-source:moz-extension://<extension-id>/<extension-page-name>.html
Using this extension ID, you can make your script go to the background page by having the browser navigate to moz-extension://<extension-id>/<background-page-name>.html

Xamarin.Forms UI Automation Testing WaitForElement WebView always times out

My Xamarin.Forms app uses Azure AD B2C for authentication. It works great. I'm trying to build UI automation tests now and I ran into my first blocker. I have been trying to wait for the WebView to come on the screen so I can enter the email and password of a test user into my ui test automation script however the WaitForElement method always times out!
[Test]
public void RegistrationStarts()
{
app.Screenshot("Welcome screen.");
app.WaitForElement(c => c.WebView());
app.Tap(c => c.WebView().Css("input#logonIdentifier"));
app.EnterText("sample#example.com");
}
I'm not sure why. I'm only testing in Android. I notice that the Azure AD B2C login web view appears to be inside my app. I can tell this because when I open the Android task switcher I can see Chrome and my app.
Is there a reason you used input before the id? If logonIdentifier is your ID of whatever you want to type, it should just be
app.Tap(c => c.WebView().Css("#logonIdentifier"));
Also, if logonIdentifier is the TextBox in which you want to type, enter text should be
_app.EnterText(c => c.WebView().Css("#logonIdentifier"), "sample#example.com");
you can try wait for element with timeout - time in milisecond, second, and min.
app.WaitForElement(x => x.Marked("AutomationID"), timeout:TimeSpan.FromSeconds(90));
or
https://learn.microsoft.com/en-us/dotnet/api/xamarin.uitest.iapp.waitforelement?view=xamarin-uitest-sdk
It seems you are using systembrowser instead of WebView.
Change your method of acquiring token with WebView.
AuthenticationResult authResult = await _pca.AcquireTokenInteractive(B2CConstants.Scopes)
.WithUseEmbeddedWebView(true)
.ExecuteAsync();
https://github.com/microsoft/appcenter/issues/287#issuecomment-484151924

Resources