'Cypress: How to access wp-admin in cypress?

Anybody here is automating Wordpress in wp-admin? I just keeps getting is error

Error: Cookies are blocked or not supported by your browser. You must enable cookies to use WordPress.

i tried this code but i got the same error when logging in. i can't access the dashboard

beforeEach('Setcookies', () => {
    Cypress.Cookies.preserveOnce('wordpress_{hash}','wordpress_logged_in_[hash]')
})


Solution 1:[1]

I'm doing a bit of automation within the dashboard and got things working by using the regex powers of the Cypress.Cookies.defaults() method.

So my test looks something like:

context('Test Dashboard', () => {
  before(() => {
    // This is a custom command that logs in a user for me
    cy.loginAs('user')

    /**
     * This is responsible for keeping the user logged in
     * throughout the test
     */
    Cypress.Cookies.defaults({
      preserve: /wordpress_|wordpress_logged_in_/,
    })
  })

  it('loads the Dashboard', () => {
    cy.visit('/wp-admin');
    cy.get('h1').contains('Dashboard');
  })
})

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 brianjhanson