https://cypress.io logo
When loading a page I constantly get Timeout
# i-need-help
p
So for example th is is the code that I have used.
> describe("test", () => { > it("tests test", () => { > > > cy.viewport(1920, 1080); > cy.visit("https://www.saucedemo.com/"); > > > cy.get("[data-test='username']").click(); > cy.get("[data-test='username']").type("standard_user"); > cy.get("[data-test='password']").click(); > cy.get("[data-test='password']").type("secret_sauce"); > cy.get("[data-test='login-button']").click(); > }); > });
Which would in theory load the saucedemo website and then enter the username etc.
Timed out after waiting 60000ms for your remote page to load. Your page did not fire its load event within 60000ms. You can try increasing the pageLoadTimeout value in cypress.config.js to wait longer. Browsers will not fire the load event until all stylesheets and scripts are done downloading. When this load event occurs, Cypress will continue running commands.
Weird thing, when I record a run, it shows it succesfully on the cypress.io website.
m
Hi @powerful-toothbrush-36495 Why do you have `%22`in the URL?
If you open your source code in VSCode it will show you have an error. Look at the colors. `cy.visit("https://www.saucedemo.com/");`is what you want.
p
oh right saw it now 😮
Another use case I am running tests one after another - Log into the page. - And another test to check if you can access a certain page, however what it happens is the 2nd test takes me back to the login screen, how would i setup cy.session()?>
One of the ways I've tried is to introduce a custom Cypress command in 'commands.js' > Cypress.Commands.add('login', (username, password) => > { > cy.session([username,password], () => > { > }) > cy.get("#email").click(); > cy.get("#email").type("automation-test"); > cy.get("#password").click(); > cy.get("#password").type("Password@"); > cy.get("span:nth-of-type(2)").click(); > cy.get("button").click(); > }); And then in my tests, I've done the following: > beforeEach( () => > { > cy.login('username', 'password') > }) > > describe("create-shift", () => { > it("tests create-shift", () => { > cy.viewport(1920, 1080); > cy.visit("https://myurl/"); > > cy.get("div.ant-col-md-6 > div > div:nth-of-type(1) svg").click(); > cy.get("li.ant-menu-submenu-active span.ant-menu-title-content").click(); > cy.get("li.ant-menu-item-active a").click(); > cy.get("div:nth-of-type(13) [data-testid='\\32 023-04-28']").click(); > cy.get("div:nth-of-type(2) > div.ant-col-18").click(); > cy.get("div:nth-of-type(13) div.__83mpQDLL > div").click(); > cy.get("div:nth-of-type(6) [data-testid='Expand-modal-button'] path").click(); > cy.get("div.ant-modal-footer > div > span span").click(); > }); > }); But when I run it via Timed out retrying after 4000ms: Expected to find element: #email, but never found it. Because this error occurred during a before each hook we are skipping all of the remaining tests. So not really sure what I'm doing wrong.
e
Are you using the test runner to debug? Running that exact test, it's easy to see the element
#email
can't be found because the test isn't on the login page at all. You need to add a
cy.visit
into your login command before you can type into any elements. I would also look slow down a bit and read up on each line to make sure you understand what is happening as there are several issues, at an initial glance - The
cy.session
command isn't wrapping the actual login commands - The selectors are wrong, compared to what I found on the saucedemo site. For instance
#email
is actually
#username
. - You don't need to
.click
on an input field. You can just
.type
, etc I'd recommend taking a high-level course first or using a test repo which already has some working code to help you walkthrough what is happening at each step. https://docs.cypress.io/examples/media/courses-media https://github.com/cypress-io/cypress-realworld-app

https://cdn.discordapp.com/attachments/1101829596418154546/1102606877226979469/image.pngâ–¾

4 Views