1717import anhtester .com .utils .ObjectUtils ;
1818import anhtester .com .utils .WebUI ;
1919import org .openqa .selenium .By ;
20- import org .openqa .selenium .JavascriptExecutor ;
2120import org .openqa .selenium .WebDriver ;
2221import org .openqa .selenium .WebElement ;
2322import org .openqa .selenium .chrome .ChromeDriver ;
2726import org .testng .annotations .Test ;
2827
2928import java .awt .*;
30- import java .awt .event .InputEvent ;
3129import java .awt .event .KeyEvent ;
32- import java .io .File ;
3330import java .text .DecimalFormat ;
3431import java .util .ArrayList ;
3532import java .util .Set ;
@@ -268,38 +265,6 @@ public void handleNotificationsBrowser() {
268265 WebUI .sleep (4 );
269266 }
270267
271- @ Test
272- public void handleDragAndDropJQuery () {
273- try {
274- String basePath = new File ("" ).getAbsolutePath ();
275-
276- DriverManager .getDriver ().get ("https://david-desmaisons.github.io/draggable-example/" );
277- Thread .sleep (1000 );
278-
279- final String JQUERY_LOAD_SCRIPT = (basePath + "/src/main/resources/jquery_load_helper.js" );
280- final String DRAG_AND_DROP_SCRIPT = (basePath + "/src/main/resources/drag_and_drop_helper.js" );
281- String jQueryLoader = Helpers .readFile (JQUERY_LOAD_SCRIPT );
282- String dragAndDropScriptLoader = Helpers .readFile (DRAG_AND_DROP_SCRIPT );
283-
284- JavascriptExecutor js = (JavascriptExecutor ) DriverManager .getDriver ();
285- js .executeAsyncScript (jQueryLoader );
286-
287- String source = "li:nth-child(1)" ;
288- String target = "li:nth-child(2)" ;
289-
290- Thread .sleep (1000 );
291-
292- String javaScript = dragAndDropScriptLoader + "window.jQuery('" + source + "').simulateDragDrop({ dropTarget: '" + target + "'});" ;
293-
294- ((JavascriptExecutor ) DriverManager .getDriver ()).executeScript (javaScript );
295-
296- Thread .sleep (3000 );
297- } catch (Exception e ) {
298- e .printStackTrace ();
299- }
300-
301- }
302-
303268 @ Test
304269 public void handleDragAndDropJS () {
305270 DriverManager .getDriver ().get ("https://bestvpn.org/html5demos/drag/" );
@@ -318,49 +283,38 @@ public void handleDragAndDropJS() {
318283 @ Test
319284 public void handleDragAndDrop () {
320285 WebUI .getURL ("http://demo.guru99.com/test/drag_drop.html" );
321- By fromElement1 = By .xpath ("//a[normalize-space()='BANK']" );
322- By toElement1 = By .xpath ("(//div[@id='shoppingCart1']//div)[1]" );
323-
324- By fromElement2 = By .xpath ("(//li[@id='fourth'])[2]" );
325- By toElement2 = By .xpath ("(//div[@id='shoppingCart4']//div)[1]" );
286+ By fromElement = By .xpath ("//a[normalize-space()='BANK']" );
287+ By toElement = By .xpath ("(//div[@id='shoppingCart1']//div)[1]" );
326288
327289 //WebUI.switchToFrameByElement(toElement);
328290 //WebUI.scrollToElement(toElement);
329- WebUI .dragAndDrop (fromElement1 , toElement1 );
291+ WebUI .dragAndDrop (fromElement , toElement );
330292 WebUI .sleep (1 );
331- WebUI .dragAndDropElement (fromElement2 , toElement2 );
332- WebUI .sleep (2 );
333293 }
334294
335295 @ Test
336- public void handleDragAndDropOffset () throws AWTException , InterruptedException {
296+ public void handleDragAndDropHTML5 () {
337297 WebUI .getURL ("https://david-desmaisons.github.io/draggable-example/" );
338- Thread .sleep (1000 );
339-
340- By fromElement1 = By .xpath ("(//li[@class='list-group-item'])[1]" );
341- By toElement1 = By .xpath ("(//li[@class='list-group-item'])[2]" );
298+ WebUI .waitForPageLoaded ();
342299
343- int X1 = driver .findElement (fromElement1 ).getLocation ().getX ();
344- int Y1 = driver .findElement (fromElement1 ).getLocation ().getY ();
345- System .out .println (X1 + " , " + Y1 );
300+ By fromElement = By .xpath ("(//li[@class='list-group-item'])[1]" );
301+ By toElement = By .xpath ("(//li[@class='list-group-item'])[2]" );
346302
347- int X2 = driver .findElement (toElement1 ).getLocation ().getX ();
348- int Y2 = driver .findElement (toElement1 ).getLocation ().getY ();
349- System .out .println (X2 + " , " + Y2 );
303+ WebUI .dragAndDropHTML5 (fromElement , toElement );
304+
305+ WebUI .sleep (2 );
306+ }
350307
351- //Chổ này lấy theo toạ độ cụ thể. Chả biết sao nó lấy toạ độ Element chênh lệch vậy nữa =))
352- Thread .sleep (1000 );
353- Robot robot = new Robot ();
354- robot .mouseMove (250 , 570 );
355- robot .mousePress (InputEvent .BUTTON1_DOWN_MASK );
308+ @ Test
309+ public void handleDragAndDropOffset () {
310+ WebUI .getURL ("https://david-desmaisons.github.io/draggable-example/" );
311+ WebUI .waitForPageLoaded ();
356312
357- Thread .sleep (1000 );
358- robot .mouseMove (250 , 610 );
313+ By fromElement = By .xpath ("(//li[@class='list-group-item'])[1]" );
359314
360- Thread .sleep (1000 );
361- robot .mouseRelease (InputEvent .BUTTON1_DOWN_MASK );
315+ WebUI .dragAndDropToOffset (fromElement , 330 , 600 );
362316
363- Thread .sleep (3000 );
317+ WebUI .sleep (2 );
364318 }
365319
366320 @ Test
0 commit comments