sclevine / agouti

A WebDriver client and acceptance testing library for Go
MIT License
821 stars 103 forks source link

How to simulate Drag and Drop #177

Open pbrown12303 opened 5 years ago

pbrown12303 commented 5 years ago

I am trying to test a diagram editor interface (think UML diagrams) running on a desktop. I have a tree of already-defined elements (implemented with jstree) and nodes from this tree get dragged over a diagram canvas and dropped. The interface works fine manually, but I can't seem to get agouti to trigger the dragstart. I have tried two different approaches, but neither one triggers the dragstart callback on the tree. Any suggestions?

Approach 1: `

            treeNode := page.FindByID(treeNodeID)

            treeNode.MouseToElement()

            page.Click(agouti.HoldClick, agouti.LeftButton)

            container := page.FindByID(newDiagramContainerID)

            container.MouseToElement()

            page.Click(agouti.ReleaseClick, agouti.LeftButton)

`

Approach 2:

`

            treeNode := page.FindByID(treeNodeID)

            treeNode.MouseToElement()

            page.Click(agouti.HoldClick, agouti.LeftButton)

            treeNode.FlickFinger(-100, -300, 50) // places cursor in container area

            page.Click(agouti.ReleaseClick, agouti.LeftButton)

`

sclevine commented 5 years ago

What browsers / webdrivers have you tried this with?

pbrown12303 commented 5 years ago

Thanks for the quick response. I have been using Chrome Version 71.0.3578.98 (Official Build) (64-bit) with go version go1.11.4 windows/amd64 and the latest versions of ginkgo, gomega, and agouti. I am using the agouti.WebDriver. To this point I have not tried any other browser/driver combinations.

By the way, a simple click page.Click(agouti.SingleClick, agouti.LeftButton) works just fine.

Also, the tree node visibly changes state with the page.Click(agouti.HoldClick, agouti.LeftButton)

sclevine commented 5 years ago

Could you check the errors to see if any of the requests to the webdriver are failing?

pbrown12303 commented 5 years ago

Sorry for the long delay in getting back - I've been working on other things.

Today I updated agouti, ginkgo, and gomega to the latest versions and repeated my test - same result. There are no errors being returned by FlickFinger(), though there is a several second delay before the call returns (this in the vscode debugger).

I see no evidence of any other failures - all of the other agouti features seem to be working fine.

I am suspecting there is a conflict in serving sockets, but without knowing the agouti architecture I cannot be sure. My application is a diagram editor that uses the browser as a user interface (that's what I am testing). My application is essentially a web server that uses a websockets connection to provide updates to the browser. Most user interactions in the browser result in requests to the server which may spawn one or more websockets notifications to the browser. At present the web server is using port 8082 and the websockets is using port 8081.

In the startup of my test I spawn the server in its own thread: go editor.StartServer(false) where the false suppresses the automatic starting of the brower. The agouti server, however, is started in the same thread as the test process: agoutiDriver = agouti.ChromeDriver(). Is it possible that there is a conflict between agouti interactions and my application's interactions?

I have seen some evidence hinting in this direction. From time to time in the past I have had to sleep the test thread (i.e. time.Sleep(10 * time.Second) ) after a page.RunScript() call in order to actually get the results. Here I was shooting in the dark trying to get my first tests running. However, based on today's experiments, that no longer seems necessary. Note that a sleep after the FlickFinger() call makes no difference.

Let me know how I can help chase this down.