Cypress detects cross origin error on test that does not leave main origin - cypress

I've been running into a problem with Cypress (currently v8.3.1 but this has been a constant for years) where my test detects a cross origin error on page load, but I am 99% certain that shouldn't apply.
The test logs into a web application and attempts to access a project.
cy.visit(webapp) //login page
cy.login(userCreds) //enter user cred and access main page
cy.get(projectAcccessButton).click() //access project from main
As the project page loads, Cypress throws the cross origin error below. I've been using the "chromeWebSecurity": false workaround, but it does not apply to Firefox. Firefox test coverage is on the "2022 To Do" list, so I am turning to Stack for answers - I hope.
What I want to do: Access the project page without issue.
What has been happening: cross origin error on page load
Permission denied to access property "document" on cross-origin object
I mentioned that the cross origin error likely shouldn't apply because when I modify the test to access the project page via cy.visit(), Cypress does not throw an error.
cy.visit(webapp) //login page
cy.login(userCreds) //enter user cred and access main page
cy.visit(projectPage) //access project via url
This leads me to believe something is happening on the button click that is somehow triggering the cross origin error. Is it possible that the button attribute onclick="window.location.href='/projectManager/123456789'" is somehow being interpreted as leaving the main origin?
If this error is related to the window.location.href, how can I resolve this so Cypress doesn't detect an error when running in Firefox?
Full Error Message:

Related

In Cypress, After an UI operation how to check a particular API call is triggered in Network tab and verify the Status as 200

I have a web application to perform the update operation with the help of a Update button in UI mode.
During that time list of APIs are loaded into the Network tab with XHR type as below. I have to verify one of the API put call is triggered and the status is passed.
url.toString() -- https://abcdef.execute-api.ue-east-2.amazonaws.com/stg2
It contains the RequestedURL value. I manually verified that in Network tab for that particular API put call. Then kept that in cypress.json and reading the url to the current class
Base URL for the UI operation: https://abc-stg2.awsdev.fgh.com/
Note: The both url are modified and dummy one, since it is confidential to share. The understanding is API calls are in AWS and the UI urls are in other environment
Try #1
// After the UI operation
cy.intercept('PUT',url.toString()).as('urupdate')
cy.wait('#urupdate',{requestTimeout:20000})
.its('status')
.should('be.eq',200)
Output:
Try #2
cy.intercept('PUT', url.toString(), (req) => {
if (req.body.status == 200) {
cy.log('pass')
}
})
Output:
The log is not getting printed and till the if statement everything is getting passed
How can we verify the particular API is triggered and the status is 200?
I have gone through the intercept as above and other stuffs in Cypress. But that does not get me the solution. Share your suggestions

Optimizely object is not valid. Failing isFeatureEnabled

I'm trying to use the React and JavaScript SDKs for Optimizely, but getting the following error in the console:
OPTIMIZELY: Optimizely object is not valid. Failing isFeatureEnabled.
More info about my setup below:
Installed via Yarn: yarn add #optimizely/react-sdk
Import statement in the app container:
import {
createInstance
} from '#optimizely/react-sdk'
Logic in render function:
const optimizely = createInstance({
sdkKey: '<SDK_KEY>',
})
const enabled = optimizely.isFeatureEnabled('example_feature', 'user123');
I get this error in the Chrome console:
OPTIMIZELY: Optimizely object is not valid. Failing isFeatureEnabled.
The Optimizely object will log that error when you call isFeatureEnabled before the SDK has successfully loaded your project's datafile. This can happen for a number of reasons outlined below. Looking at the code example provided in the question, it looks like reason #4 is the most likely cause of the error, but here are all of them:
1. Bad SDK key
If you pass in a bad SDK Key to createInstance, the SDK will not successfully load the datafile and you will get this error.
const optimizely = createInstance({
sdkKey: 'invalid-sdk-key'
})
2. Malformed datafile
If you are passing in the datafile directly to createInstance, but pass in an object that isn't the proper datafile format, you will get this error:
const optimizely = createInstance({
datafile: { wrong: 'format' }
})
3. Inaccessible datafile
Make sure you can access the url of your datafile in a web browser: https://cdn.optimizely.com/datafiles/<Your_SDK_Key>.json. If you get an AccessDenied (403) or Not Found (404) error and your account is new, make sure you create something in the Optimizely UI so that Optimizely is triggered to create and upload a proper datafile.
If in the console of your running application you see a 403 or 404 for the request to the datafile, ensure there are no ad-blockers, firewalls, or proxies preventing the SDK from requesting the datafile on Optimizely's CDN from the SDK.
4. Not waiting for Optimizely SDK to be ready
Even if you have the right SDK Key and the SDK can access Optimizely's CDN. If you don't give the SDK enough time for the datafile request to finish, you will be trying to use the SDK before it's ready.
In the JavaScript SDK, this can be solved by using the onReady method:
const optimizely = createInstance({
sdkKey: 'valid-sdk-key',
});
optimizely.onReady().then(() => {
// optimizely is ready to use, with datafile downloaded from the Optimizely CDN
});
If using the <OptimizelyFeature> component of the React SDK, then the <OptimizelyFeature> component will automatically wait until the <OptimizelyProvider> has successfully loaded the datafile before evaluating isFeatureEnabled.
My Firefox console error was
[OPTIMIZELY] - ERROR <timestamp> OPTIMIZELY: Optimizely object is not valid. Failing isFeatureEnabled.
One of my network failures gave me a big clue. The GET request for cdn.optimizely.com showed "Blocked by AdBlocker Ultimate" under the Transferred column.
Solution
I turned off my ad blocker for this site.

Page is not loading when linked is clicked in cypress

Vist to https://www.binance.com/en.
Click on view more markets link.
The website is loading properly but when I am clicking on "View more markets" link. it is giving
the below error:
Blocked a frame with origin "https://www.binance.com" from accessing a cross-origin frame.
Before the page load, you were bound to the origin policy:
https://binance.com
A cross origin error happens when your application navigates to a new superdomain which does not match the origin policy above.
This typically happens in one of three ways:
1. You clicked an that routed you outside of your application
2. You submitted a form and your server redirected you outside of your application
3. You used a javascript redirect to a page outside of your application
Cypress does not allow you to change superdomains within a single test.
You may need to restructure some of your test code to avoid this problem.
Alternatively you can also disable Chrome Web Security which will turn off this restriction by setting { chromeWebSecurity: false } in 'cypress.json'.https://on.cypress.io/cross-origin-violation"
The code is below:
describe('My firs Test',()=> {
it('load page',()=>{
cy.visit("https://www.binance.com/en")
cy.xpath("//a[text()='View more markets']").click();
cy.wait(50000);
})
})
Did you try in your cypress.json file turning off chromeWebSecurity?
{
"projectId": "online-realestate",
"viewportWidth": 1200,
"viewportHeight": 1000,
"video": false,
"chromeWebSecurity": false
}

I can't add items from any dashboard (old or new)

I'm trying tu turn on and test ScadaLTS on my PC (Windows 10). Before read install instuctions, I have donwloaded and installed Tomcat and MySQL, configured context.xml and env.properties. I have restarted Tomcat before changes and navigated to localhost. All seems to work well. Login pagin is showed and I can log in with 'admin/admin'. I click on add view and new view is created. I go to edit button. When I try to add a new component, only two options appear (SLTS Image Componen and SLTS Visit Counter). If I back to old UI, add a view and then try to add a component, list is published as shown is youtube, but when I click on add, nothing happens. No items are added on drawable surface.
I was looking for errors in Tomcat log folder but nothing find. If I open Angular 2 UI with dev-tools, console show firtsly two erros:
Failed to load resource: the server responded with a status of 404 (Not found) ~https://fonts.googleapis.com/icon?family=Material+Icons
Failed to load resource: the server responded with a status of 404 (Not found) ~#angular/material/prebuilt-themes/deeppurple-amber.css
And before them, two more are shown continously:
ERROR TypeError: Cannot read property '_has' of undefined
at p (plotly.min.js:52)
at Object.t [as relayout] (plotly.min.js:52)
at WatchlistComponent.webpackJsonp.../../../../../src/app/appBody/watchlist/watchlist.component.ts.WatchlistComponent.autorangeChart (main.bundle.js:3859)
at main.bundle.js:3635
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (vendor.bundle.js:33289)
at Object.onInvokeTask (vendor.bundle.js:81064)
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (vendor.bundle.js:33288)
at Zone.webpackJsonp.../../../../zone.js/dist/zone.js.Zone.runTask (vendor.bundle.js:33056)
at webpackJsonp.../../../../zone.js/dist/zone.js.ZoneTask.invokeTask (vendor.bundle.js:33363)
at ZoneTask.invoke (vendor.bundle.js:33352)
defaultErrorLogger # vendor.bundle.js:78203
:8080/ScadaBR/api/point_value/getValue/null Failed to load resource: the server responded with a status of 400 (Bad request)
vendor.bundle.js:78203 ERROR Error: Uncaught (in promise): Response with status: 400 PeticiĆ³n incorrecta for URL: http://localhost:8080/ScadaBR/api/point_value/getValue/null
at resolvePromise (vendor.bundle.js:33648)
at resolvePromise (vendor.bundle.js:33619)
at vendor.bundle.js:33696
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (vendor.bundle.js:33289)
at Object.onInvokeTask (vendor.bundle.js:81064)
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (vendor.bundle.js:33288)
at Zone.webpackJsonp.../../../../zone.js/dist/zone.js.Zone.runTask (vendor.bundle.js:33056)
at drainMicroTaskQueue (vendor.bundle.js:33460)
at ZoneTask.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (vendor.bundle.js:33367)
at invokeTask (vendor.bundle.js:34235)
Could you help me please? Thanks in advance
Which version of Java, Tomcat and MySQL are you using?
The problem can be caused by too high version of Tomcat. We recommend to use version 7.0.82.
The simplest way to run Scada-LTS is to use our docker container:
https://github.com/SCADA-LTS/Scada-LTS/wiki/Run-ScadaLTS-on-docker---instruction

Parse related remote calls failing in app

I have developed an Ionic Framework App using Parse which works great on my desktop browsers. No errors or warnings in the browser console.
But when I package the app and test in on my actual Android 4.4.4 device, the Parse related functionalities does not work. When I tried to debug the App by installing the .apk using GapDebug tool, I see the below in the console.
POST https://api.parse.com/1/login net::ERR_CACHE_MISS
POST https://api.parse.com/1/requestPasswordReset net::ERR_CACHE_MISS
Below is the complete console log details for the Parse Login activity.
POST https://api.parse.com/1/login net::ERR_CACHE_MISS parse-1.3.3.min.js:1
b._ajax parse-1.3.3.min.js:1
b._request parse-1.3.3.min.js:1
b.User.b.Object.extend.logIn parse-1.3.3.min.js:3
b.User.b.Object.extend.logIn parse-1.3.3.min.js:3
$scope.validateUser login.controller.js:22
$parseFunctionCall ionic.bundle.js:20124
(anonymous function) ionic.bundle.js:50863
Scope.$eval ionic.bundle.js:22178
Scope.$apply ionic.bundle.js:22276
(anonymous function) ionic.bundle.js:50862
jQuery.event.dispatch jquery.js:4409
elemData.handle jquery.js:4095
triggerMouseEvent ionic.bundle.js:2811
tapClick ionic.bundle.js:2800
tapTouchEnd ionic.bundle.js:2918
POST https://api.parse.com/1/requestPasswordReset net::ERR_CACHE_MISS
For getting all the data for a particular class, I get the below failure object.
Failed to load resource: net::ERR_CACHE_MISS https://api.parse.com/1/Items
XMLHttpRequest failed: {"statusText":"","status":0,"response":"","responseType":"","responseXML":null,"responseText":"","upload":{"ontimeout":null,"onprogress":null,"onloadstart":null,"onloadend":null,"onload":null,"onerror":null,"onabort":null},"withCredentials":false,"readyState":4,"timeout":0,"ontimeout":null,"onprogress":null,"onloadstart":null,"onloadend":null,"onload":null,"onerror":null,"onabort":null}
The issue was with permission. It was failing because the app was not able to connect to internet.
Somehow the Network Access permission entry got deleted in the manifest file. After adding it to manifest, it worked.

Resources