0
votes

Using cypress("@vue/cli-plugin-e2e-cypress": "~4.2.0") in @vue/cli 4.0.5 app I make CRUD opearitions and adding new category :

cy.get('#parent_id').select('1')


cy.get('section.submit_form_category')
    .get('button.submit_button_category')
    .click()  // by submitting new category was added on server

cy.url()
    .should('include', '/admin/categories/edit/')

cy.contains('Edit category')

cy.get('section.submit_form_category')
    .get('a.cancel_button_category')
    .click()


cy.url()
    .should('include', '/admin/categories')
cy.contains('Categories')  // opened listing of categories 

Next I need to delete this row and for this I need to get ID of a new category created above. If there is a way to make it ?

Thanks!

1

1 Answers

0
votes

I found a decision with wait method and parsing response url which must be like /admin/categories/edit/52 :

cy.get('section.submit_form_category')
    .get('button.submit_button_category')
    .click() // by clicking on submit button form is validated and new categoty inserted

cy.wait(1000)

cy.url()
    .should('include', '/admin/categories/edit/') // newly inserted row must be redirected to the editor in edit mode with ID in url
    .then((response) => {
        var valuesArray = response.split('/admin/categories/edit/'); // get ID of newly inserted category
        if (valuesArray.length == 2) {
            let new_category_id = valuesArray[1]
            // alert('new_category_id::' + new_category_id)
        }
    })
cy.contains('Edit category')

That works for me, though maybe there is a better solution?