Socket hang up error with Cypress (tried 5.4 and 6.0.1) - https

I'm trying to use cypress to test an app running on my local linux box. If I manually browse to the test URL (https://localhost:8443) it works fine. If I create a test in Cypress that simply contains nothing more than
describe('my app tests', function () {
it('does very little', function () {
cy.visit('https://localhost:8443')
})
})
Then it fails after a few seconds with:
cy.visit() failed trying to load:
https://localhost:8443/
We attempted to make an http request to this URL but the request failed without a response.
We received this error at the network level:
> Error: socket hang up
Common situations why this would fail:
- you don't have internet access
- you forgot to run / boot your web server
- your web server isn't accessible
- you have weird network configuration settings on your computer
Looking in DevTools there are no apparent requests to the test server - just 3 requests (1 document with a 304 status, and 2 xhr requests each with a 200 status) all of which apparently loading the cypress test and support files. Nothing else - no logged request to the test URL.
Can anyone offer any suggestions why I'm seeing this 'dead' test?

Related

cy.origin() and multiple origins in the same domain

I am trying to add login flow to my cypress tests.
I want to get it running on my machine, in the following environment:
both app and OAuth server are running in docker containers
both containers have their ports mapped to localhost:
app is available at baseUrl: 'https://localhost:8888'
OAuth Server is available at 'http://localhost:9081'
As you can see, there are 2 origins on the localhost.
If I try the simple code:
cy.visit('/mysecuredpage'); // this redirects to http://localhost:9081
cy.contains('Please log in');
cy.get('input#username').type('user1');
cy.get('input#password').type('password1');
cy.get('button#password-submit').click();
I get an error about conflicting origins:
The command was expected to run against origin `http://localhost:9081` but the application is at origin `https://localhost:8888`.
I was trying to follow SSO login custom command
cy.visit('/mysecuredpage'); // this redirects to http://localhost:9081
cy.origin('http://localhost:9081', () => {
cy.contains('Please log in');
cy.get('input#username').type('user1');
cy.get('input#password').type('password1');
cy.get('button#password-submit').click();
});
Unfortunately, this fails with an error about wrong domain:
CypressError: `cy.origin()` requires the first argument to be a different domain than top. You passed `http://localhost:9081` to the origin command, while top is at `http://localhost:9081`.
Either the intended page was not visited prior to running the cy.origin block or the cy.origin block may not be needed at all.
Am I running against some known limitation or doing sth wrong?
I am not even sure if multiple origins in the same domain is the root cause of the problem, or is it caused by some usage pattern of my app (all pages are private and redirect immediately to Oauth - there is no login button on the app side)
Cypress: 11.0.1
Browser: Chrome 107 (headless)
Node Version: v18.6.0

Cypress not able to load a different domain used in the second test

Cypress not able to load a different domain used in the second test . I have 2 tests. In one test the user goes to https://www.google.com and login and in the second test case it goes to https://www.yahoo.com and tries to the same.I have gone through cypress documentation that's why my 2 different domains are part of 2 separate tests.But fails to load the second url in the second test.Dashboard get stuck and 2nd url not loading.How to solve this issue?
Cypress can load a different domains in different tests, but Yahoo throws some internal errors which causes Cypress to fail loading that page.
If you substitute http://www.example.com/, both domains will load.
You can suppress the Yahoo errors with Uncaught Exceptions event
At the top of the spec,
Cypress.on('uncaught:exception', (err, runnable) => {
return false
})

Network requests not showing up in cypress command log

We are trying to write a cypress test that checks one of the xhr requests made from the page. However the requests that we are making are not showing up in the command log. They do however show up in the bash console after running cypress open.
Command log:
Bash console:
We have tried running our simple test against other domains such as cypress.io, and google.com. Requests show up just fine.
We have verified that the requests made are not fetch requests.
We have disabled chomeWebSecurity (not sure if relevant).
Here is the example we are using:
describe('example', () => {
it('visits a page', () => {
cy.server();
cy.route('POST', '**');
cy.visit('https://www.academia.edu/12297791/Open_Access_Meets_Discoverability_Citations_to_Articles_Posted_to_Academia.edu');
});
});
Here is our cypress.json file:
{
"chromeWebSecurity": false
}
We are running cypress version 3.4.1
I would expect the command log to have these post requests show up, like this documentation describes: https://docs.cypress.io/guides/guides/network-requests.html#Requests
Any help is greatly appreciated, as we're unsure how else to debug this.
1.) I would suggest to use a more up-to-date version of Cypress with the cy.intercept().
2.) A typical problem can be the timing - add a cy.wait(X) before it, or add a timeout to replace the default timeout.
3.) Make sure the path of the route/intercept, especially when it differs from the cy.visit() 's url.
4.) Additional hint, use aliases.

How to map a SignalR Hub in ASP.NET MVC Core to a dynamic route? (e.g. /controller/action/{id}?

my question is simple and everything important is in my title.
I've tried to map it this way:
app.UseSignalR(routes =>
{
routes.MapHub<ChatHub>("/Controller/Action/{id}");
});
But I get a 404 in my developer console in Chrome, when requesting such a route:
Failed to load resource: the server responded with a status of 404 ()
signalr.js:1883 Error: Failed to complete negotiation with the server: Error (ConsoleLogger.log # signalr.js:1883)
Error: Failed to start the connection: Error (ConsoleLogger.log # Signalr.js:1883)
Therefore I guess I am mapping it the wrong way?

Failed to load resource: the server responded with a status of 400 () while trying to login into Instagram through Selenium and Python

I've been in the process of making an instagram bot for a few days now and I'm having trouble logging into instagram with a headless selenium browser.
The script I made works perfectly fine when run on my laptop but when I try to run this on my digital ocean server, the browser will fill the login forms, then submit the form but nothing happens. I was able to print any console errors with this code:
for entry in self.browser.get_log('browser'):
print(str(entry))
and this error comes up
{u'source': u'network', u'message': u'https://www.instagram.com/accounts/login/ajax/ - Failed to load resource: the server responded with a status of 400 ()', u'timestamp': 1546536937734, u'level': u'SEVERE'}
I am using the chromedriver for selenium and python2.7
I'm not completely sure why this is happening. Thanks for any help!
This error message...
{u'source': u'network', u'message': u'https://www.instagram.com/accounts/login/ajax/ - Failed to load resource: the server responded with a status of 400 ()', u'timestamp': 1546536937734, u'level': u'SEVERE'}
...implies that the WebDriver was unable to initiate/spawn a new WebBrowsing Session as it failed to load the required resources through AJAX calls.
As per the HTML DOM of the Instagram - Log in page it is pretty clear the DOM Tree contains AJAX and JavaScript enabled elements.
So while you invoke get() method before interacting with the elements on the particular you need to induce WebDriverWait for the desired elements to be clickable which will ensure that:
The associated JavaScript and AJAX Calls have completed
The desired elements are enabled and visible to recognize click events propogated through Selenium.
You can find a relevant discussion in Google adsense responding the server responded with a status of 400 ()
Here you can find a relevant discussion on Filling in login forms in Instagram using selenium and webdriver (chrome) python OSX

Resources