Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

421
Visualizações
Cypress: resizing / dragging elements

I am trying to resize a box element by clicking on the bottom right corner and dragging it down a few pixels. Example what I have but does not work:

    it("tests resizing elements", () => {
        cy.findByText(/zoom/i)
            .nextAll(1)
            .invoke("text")
            .then(($text) => {
                let zoom = parseInt($text.split("%")[0]);
                let objects;
                cy.window()
                    .then(($win) => {
                        objects = $win.canvas.getObjects();
                    })
                    .then(() => {
                        cy.getSidebarButton("Edit mode").click();
                        // x and y are relative to the zoom percentage
                        let x =
                            ((objects[objects.length - 1].left +
                                objects[objects.length - 1].width) /
                                100) * zoom;
                        let y =
                            ((objects[objects.length - 1].top +
                                objects[objects.length - 1].height) /
                                100) * zoom;
                        cy.getCanvas()
                            .trigger("mousedown", x, y)
                            .trigger("mousemove", x + 20, y + 25)
                            .trigger("mouseup", x + 20, y + 25);
                    });
            });
    });

What the code currently does is click on the correct spot, drag the object and then release, but it moves the object instead of resizing it.

Any help would be greatly appreciated.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Try triggering resize directly:

cy.getCanvas().trigger('resize',x,y);
about 4 years ago · Juan Pablo Isaza Relatório

0

Finally figured what I needed. The issue was that the element needed to be clicked. So replacing the last bit of my code with

                        cy.getCanvas()
                            .trigger("mousedown", x, y)
                            .trigger("mouseup", x, y)
                            .trigger("mousedown", x, y)
                            .trigger("mousemove", x + 50, y + 55)
                            .trigger("mouseup", x + 50, y + 55);

fixed my issue. (To my surprise, .click() was not enough and it had to be mousedown and mouseup.)

What helped me realize this was needed was spying on the events fired when doing it manually.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda