I am using setCanDrag and setUseNativeDrag (to true) to get the effect of the cursor changing from a crossed-out circle to a plus sign while a canvas is being dragged.
Here is my example code:
This code successfully produces an application where the canvases can be dragged and dropped resulting in their change in position in the VStack.
However, when I use automated Selenium tests to test the drag and drop functionality, Selenium cannot perform the drag and drop.
Here is the Selenium test code that will perform the drag and drop test.
If I remove either or both of the two lines indicated in the first code example, then Selenium can successfully perform the drag and drop and the test passes.
Removing either of the two lines of code also removes the desired cursor appearance while the canvas is being dragged.
Here is my example code:
Code:
[B]public[/B] [B]class[/B] TestLayout [B]extends[/B] VStack { [B]public[/B] TestLayout() { setBorder("3px solid black"); setCanAcceptDrop([B]true[/B]); setHeight(1); setMembersMargin(10); setPadding(10); setWidth(1); [B]for[/B] (String color : [B]new[/B] String[] { "red", "blue", "green" }) { addMember([B]new[/B] MovableLayout(color)); } } [B]private[/B] [B]static[/B] [B]final[/B] [B]class[/B] MovableLayout [B]extends[/B] Canvas { [B]public[/B] MovableLayout(String color) { setID(color); setBackgroundColor(color); setCanDragReposition([B]true[/B]); setCanDrop([B]true[/B]); setDragAppearance(DragAppearance.[B][I]TARGET[/I][/B]); setHeight(100); setWidth(100); /** * The two lines below cause the [U]Selenium[/U] dragAndDrop method to * fail. If either of these lines are removed, the [U]Selenium[/U] * dragAndDrop method will succeed. */ setCanDrag([B]true[/B]); setUseNativeDrag([B]true[/B]); } } }
However, when I use automated Selenium tests to test the drag and drop functionality, Selenium cannot perform the drag and drop.
Here is the Selenium test code that will perform the drag and drop test.
Code:
[B]import[/B] org.openqa.selenium.By; [B]import[/B] org.openqa.selenium.WebElement; [B]import[/B] org.openqa.selenium.interactions.Actions; [B]import[/B] org.openqa.selenium.support.ui.ExpectedConditions; [B]import[/B] org.openqa.selenium.support.ui.WebDriverWait; [B]import[/B] org.testng.Assert; [B]import[/B] org.testng.annotations.Test; [B]import[/B] com.isomorphic.webdriver.ByScLocator; [B]import[/B] com.isomorphic.webdriver.SmartClientFirefoxDriver; [B]public[/B] [B]class[/B] DragAndDropTest { @Test() [B]public[/B] [B]void[/B] testDragAndDrop() { SmartClientFirefoxDriver driver = [B]new[/B] SmartClientFirefoxDriver(); driver.setBaseUrl(""); driver.get("http://localhost:8080/Classifier.html"); ([B]new[/B] WebDriverWait(driver, 10)).until(ExpectedConditions.[I]elementToBeClickable[/I](getLocatorByColor("red"))); System.[B][I]out[/I][/B].println("layout is ready"); Assert.[I]assertEquals[/I](getHorizontalPostion(driver, "red"), 13); Assert.[I]assertEquals[/I](getHorizontalPostion(driver, "blue"), 123); Assert.[I]assertEquals[/I](getHorizontalPostion(driver, "green"), 233); System.[B][I]out[/I][/B].println("initilaize color ordering is correct"); WebElement redWebElement = getColor(driver, "red"); WebElement greenWebElement = getColor(driver, "green"); [B]new[/B] Actions(driver).dragAndDrop(redWebElement, greenWebElement) .build() .perform(); Assert.[I]assertEquals[/I](getHorizontalPostion(driver, "red"), 123); Assert.[I]assertEquals[/I](getHorizontalPostion(driver, "blue"), 13); Assert.[I]assertEquals[/I](getHorizontalPostion(driver, "green"), 233); System.[B][I]out[/I][/B].println("drag and drop color ordering is correct"); } [B]private[/B] [B]int[/B] getHorizontalPostion(SmartClientFirefoxDriver driver, String color) { WebElement element = getColor(driver, color); [B]int[/B] getVerticalPosition = element.getLocation() .getY(); [B]return[/B] getVerticalPosition; } [B]private[/B] WebElement getColor(SmartClientFirefoxDriver driver, String color) { By redLocator = getLocatorByColor(color); [B]return[/B] driver.findElement(redLocator); } [B]private[/B] By getLocatorByColor(String color) { [B]return[/B] ByScLocator.[I]scLocator[/I]("//Canvas[ID=\"" + color + "\"]/"); } }
Removing either of the two lines of code also removes the desired cursor appearance while the canvas is being dragged.
Comment