如何在react-dnd-treeview库上使用Selenium测试拖放 [英] How to test drag and drop with Selenium on the react-dnd-treeview library

查看:105
本文介绍了如何在react-dnd-treeview库上使用Selenium测试拖放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在React应用程序上测试简单的拖放行为.

I'm trying to test a simple drag and drop behavior on a React app.

我正在使用 react-dnd-treeview 库和他们的示例网站来测试我的测试用例.

I am using the react-dnd-treeview library and their example website to test my test case.

当我在调试中运行测试时,我没有收到任何错误,并且Selenium能够获取正确的元素,但是什么也没有发生,即使尝试了之后,我也无法创建或可视化任何类型的动作这么多不同的答案在这个类似的问题中,但徒劳.

When I run the tests in debug, I don't get any errors and Selenium is able to get the right elements, but nothing is happening, I'm not able to create or visualize any sort of actions, even after trying so many of the different answers in this similar question, but in vain.

这是我正在使用的代码:

Here is the code I am working with:

package tests;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;

import java.io.File;

public class DAndDJava {

    public static void main(String[] args) {

        File file = new File("C:/misc/chromedriver.exe");
        System.setProperty("webdriver.chrome.driver" , file.getAbsolutePath());

        WebDriver driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.get("http://teleport.github.io/react-dnd-treeview/example/dist/index.html");

        WebElement dragPoint = driver.findElement(By.xpath ("//*[@id=\"root\"]/div/div/div[3]/div[2]/div[2]/div/div/div[3]/div[2]/div/div[1]/div[3]/div[1]/div"));
        WebElement dropPoint = driver.findElement(By.xpath ("//*[@id=\"root\"]/div/div/div[3]/div[2]/div[2]/div/div/div[3]/div[2]/div/div[1]/div[3]/div[1]"));

        Actions builder = new Actions(driver);

        Action dragAndDrop = builder.clickAndHold(dragPoint)
                                    .moveToElement(dropPoint)
                                    .release(dropPoint)
                                    .build();

        dragAndDrop.perform();

        driver.quit();
    }

}

推荐答案

可以尝试使用以下代码:

Could you try with below code:

Action dragAndDrop = builder.clickAndHold(dragPoint)
                            .moveToElement(dropPoint)
                            .moveByOffset(0,10)   
                            .release()
                            .build()
                            .perform() ;

这篇关于如何在react-dnd-treeview库上使用Selenium测试拖放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆