cypress fails to set localstorage at travis CI
See original GitHub issueCurrent behavior:
cypress fails to set localStorage key at travis CI
Reproduce:
Im trying to configure CI e2e automation of react app.
In my app i have ProtectedRoute
component which redirects not-loggedin-user to “login” page:
export const ProtectedRoute = ({ component: Component, ...rest }) => (
<Route
{...rest}
render={props =>
localStorage.getItem("user") ? ( // here it checks if localstorage has "user" key
<Component {...props} />
) : (
<Redirect
to={{ pathname: "/login", state: { from: props.location } }}
/>
)
}
/>
);
In my test i’m trying to access some “protected” route and do some checks on the page. As recommended at cypress documentation - i’m not logging-in using UI, but instead, i use to call some command i created to log-in programmatically:
beforeEach(() => {
cy.login(); // the command
})
describe('dashboard', () => {
it('should show dashboard page', () => {
cy.url().should('include', 'dashboard');
})
})
Here is the command, it`s simply creates the “user” key inside localStorage:
Cypress.Commands.add('login', () => {
const user = {"UserName": "Ivan","UserLastName": "Susanin"}
localStorage.setItem('user', JSON.stringify(user))
}
At my local environment i can see the tests passing. But, at travis-CI run i see the tests failing continuously, for the reason of url is “login”
Versions
Here is my travis config file:
language: node_js
node_js:
- 10.13
addons:
apt:
packages:
# Ubuntu 16+ does not install this dependency by default, so we need to install it ourselves
- libgconf-2-4
cache:
# cache both npm modules and Cypress binary
directories:
- ~/.npm
- ~/.cache
script:
- npm run format:check
- npm run lint
- npm test
- node fake-server/server &
- npm run test:all
Please help .
Thanks
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Set local storage in Cypress - Stack Overflow
This function works when running in node. I'm trying to create a cypress command that will set local storage, then visit the application....
Read more >cypress-io/cypress - Gitter
Anyone has any experience using Travis CI with Cypress-IO? ... Did you setup dashboard to collect them? because travis does not have built-in...
Read more >Changelog - Cypress Documentation
Added messaging after failures in CI to direct people to set up recording to the Cypress Cloud if they are not already set...
Read more >@cypress/request-promise - npm
Cypress's fork of the simplified HTTP request client 'request' with Promise support. Powered by Bluebird.. Latest version: 4.2.6, last published: 3 years ...
Read more >Category: products | Better world by better software
How to run the failed tests from DevTools Console using @bahmutov/cy-grep plugin. ... The Simplest CI Setup For Running Cypress Tests.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Unfortunately we have to close this issue as there is not enough information to reproduce the problem. This does not mean that your issue is not happening - it just means that we do not have a path to move forward.
Please comment in this issue with a reproducible example and we will consider reopening the issue.
I have a similar issue with a local storage related test randomly failing in CI.
Here is the test:
And here is the error message when it fails: