microsoft / WinAppDriver

Windows Application Driver
MIT License
3.66k stars 1.4k forks source link

Experiencing unknown server-side error "Could not proxy command to remote server." #828

Open hicks86 opened 5 years ago

hicks86 commented 5 years ago

Hi guys,

Working on a project that runs an End-to-End test on our application that is a Microsoft Word Addin. Essentially the application fires up Word with a particular document, then using Appium to interact with our application trying to verify certain scenarios are working etc.

Our problem is that we continue to run into the following exception during our run:

System.InvalidOperationException: 'An unknown server-side error occurred while processing the command. Original error: Could not proxy. Proxy error: Could not proxy command to remote server. Original error: Error: connect ECONNREFUSED 127.0.0.1:4724'

Occurs when the E2E test has been running for a bit.

I have a feeling the way I need to deal with this issue is to catch it and try and re-connect?

If you need any more information please let me know

Appium Server Log

[info] [35m[WinAppDriver][39m [STDOUT] POST /wd/hub/session/6674E9C9-76C6-4E82-957C-519037DC48EC/moveto HTTP/1.1 [info] [35m[WinAppDriver][39m [STDOUT] Accept: application/json, / [info] [35m[WinAppDriver][39m [STDOUT] Connection: close [info] [35m[WinAppDriver][39m [STDOUT] Content-Length: 50 [info] [35m[WinAppDriver][39m [STDOUT] Content-Type: application/json; charset=utf-8 [info] [35m[WinAppDriver][39m [STDOUT] Host: 127.0.0.1:4724 [info] [35m[WinAppDriver][39m [STDOUT] User-Agent: appium [info] [35m[WinAppDriver][39m [STDOUT] [info] [35m[WinAppDriver][39m [STDOUT] {"element":"42.199450","xoffset":440,"yoffset":75} [info] [35m[WinAppDriver][39m [STDOUT] HTTP/1.1 200 OK [info] [35m[WinAppDriver][39m [STDOUT] Content-Length: 63 [info] [35m[WinAppDriver][39m [STDOUT] Content-Type: application/json [info] [35m[WinAppDriver][39m [STDOUT] [info] [35m[WinAppDriver][39m [STDOUT] {"sessionId":"6674E9C9-76C6-4E82-957C-519037DC48EC","status":0} [debug] [35m[WD Proxy][39m Got response with status 200: {"sessionId":"6674E9C9-76C6-4E82-957C-519037DC48EC","status":0} [info] [35m[WD Proxy][39m Replacing sessionId 6674E9C9-76C6-4E82-957C-519037DC48EC with 576b44e7-4687-426e-916d-b1f068ff02c0 [info] [35m[HTTP][39m [37m<-- POST /wd/hub/session/576b44e7-4687-426e-916d-b1f068ff02c0/moveto [39m[32m200[39m [90m17 ms - 63[39m [info] [35m[HTTP][39m [90m[39m[info] [35m[HTTP][39m [37m-->[39m [37mPOST[39m [37m/wd/hub/session/576b44e7-4687-426e-916d-b1f068ff02c0/click[39m [info] [35m[HTTP][39m [90m{"button":0}[39m [info] [35m[MJSONWP (576b44e7)][39m Driver proxy active, passing request on via HTTP proxy [debug] [35m[WD Proxy][39m Matched '/wd/hub/session/576b44e7-4687-426e-916d-b1f068ff02c0/click' to command name 'clickCurrent' [debug] [35m[WD Proxy][39m Proxying [POST /wd/hub/session/576b44e7-4687-426e-916d-b1f068ff02c0/click] to [POST http://127.0.0.1:4724/wd/hub/session/6674E9C9-76C6-4E82-957C-519037DC48EC/click] with body: {"button":0} [info] [35m[WinAppDriver][39m [STDOUT] [info] [35m[WinAppDriver][39m [STDOUT] [info] [35m[WinAppDriver][39m [STDOUT] ========================================== [info] [35m[WinAppDriver][39m [STDOUT] POST /wd/hub/session/6674E9C9-76C6-4E82-957C-519037DC48EC/click HTTP/1.1 [info] [35m[WinAppDriver][39m [STDOUT] Accept: application/json, / [info] [35m[WinAppDriver][39m [STDOUT] Connection: close [info] [35m[WinAppDriver][39m [STDOUT] Content-Length: 12 [info] [35m[WinAppDriver][39m [STDOUT] Content-Type: application/json; charset=utf-8 [info] [35m[WinAppDriver][39m [STDOUT] Host: 127.0.0.1:4724 [info] [35m[WinAppDriver][39m [STDOUT] User-Agent: appium [info] [35m[WinAppDriver][39m [STDOUT] [info] [35m[WinAppDriver][39m [STDOUT] {"button":0} [warn] [35m[BaseDriver][39m Shutting down because we waited 60 seconds for a command [debug] [35m[WinAppDriver][39m Deleting WinAppDriver session [debug] [35m[WinAppDriver][39m Deleting WinAppDriver server session [debug] [35m[WD Proxy][39m Matched '/' to command name 'deleteSession' [debug] [35m[WD Proxy][39m Proxying [DELETE /] to [DELETE http://127.0.0.1:4724/wd/hub/session/5E6D0B6F-831C-47AD-9822-6CD25E12C9B9] with no body [warn] [35m[Appium][39m Closing session, cause was 'New Command Timeout of 60 seconds expired. Try customizing the timeout using the 'newCommandTimeout' desired capability' [info] [35m[Appium][39m Removing session 115b55af-b9cd-4d80-8ae0-fd7f6ee17b9e from our master session list

DLightstone commented 5 years ago

I don't know anything about Microsoft Word Addins. I do know a bit about Word automation. Eventually I intend to determine if WinAppDriver can be used to test an application which is an automation of Word.

Your application appears to run locally. If correct and you are attempt to access a single Word Document from two task, then you are experiencing a limitation of Microsoft Word. As I understand things (you will need to get a confirmation from a real live honest to goodness Microsoft employee) Word documents cannot be shared locally. They can only be shared via the cloud.

hicks86 commented 5 years ago

Hi @DLightstone thank you for your reply, the problem isn't with the word document being accessible remotely (although the error message does suggest that) though. Both the E2E test (MsTest) and the word document is local.

Just to clarify I have been using the Appium and WinAppdriver on a number of integration tests which have been working fine. The only difference is this would be a longer process where I am interacting with the addin.

Also just to clarify the addin is just a WinForm application that is bundled as an Addin by a third party provider (Addin Express).

DLightstone commented 5 years ago

@hicks86 I had determined that the application under test and the testing application were both executing locally.

The issue of concern was whether they both needed to access the Word Document. I have been lead to believe that this is not possible, and suspected that an attempt to do so will lead to a command execution failure. (manifested in this case as "Could not proxy command to remote server." )

The basis for the issue of concern is located at the following web address https://answers.microsoft.com/en-us/msoffice/forum/msoffice_word-msoffice_custom-mso_2016/does-microsoft-word-all-local-sharing/66632614-d7c4-43ea-a764-b7ba83fec17e?messageId=d7e5491d-2061-4c32-8707-5c1389052e3d

hicks86 commented 5 years ago

Ok so I think I have managed to get around this issue.

Essentially I am looping through a list of items on the app, and clicking them in turn. I was using a Thread.Sleep() after clicking to wait for the UI to catch up so I can validate the result. This seemed like it was throwing the communication out of sync with the Appium server. The way I am approaching it is to use Selenium Wait.Until() method.

So originally I was doing something like this:

for (int i = 0; i < issueItems.Count; i++)
{
    var item = issueItems[i];
    Session.Mouse.MouseMove(listElement.Coordinates, OffsetX, OffSetY);
    Session.Mouse.Click(null);
    Thread.Sleep(TimeSpan.FromSeconds(1)); //Wait for UI to catchup

    Assert.IsTrue(item.Text.Contains("XXX"));
}

However now doing this:

WebDriverWait wait = new WebDriverWait(Session, TimeSpan.FromSeconds(20));
wait.Until((d) =>
{
    try
    {
        var item = issueItems[i];
        Session.Mouse.MouseMove(listElement.Coordinates, OffsetX, OffSetY);
        Session.Mouse.Click(null);

        Assert.IsTrue(item.Text.Contains("XXX"));

        return true;
    }
    catch (Exception)
    {
        return false;
    }
});

For now this seems to be working a treat. However I would still love to know if the "Could not proxy command...." is related to the use of the heavy handed Thread.Sleep(). Any insights?

hassanuz commented 5 years ago

Interesting @hicks86, thanks for posting the work around.

I'm curious if the original error would have still persisted if you bypassed Appium and connected to WinAppDriver.exe directly?

hicks86 commented 5 years ago

Hi @hassanuz are you able to point me in the direction of a "How to" connect directly to the WinAppdriver.exe? I will try it out.

hicks86 commented 5 years ago

Hi @hassanuz are you able to point me in the direction of a "How to" connect directly to the WinAppdriver.exe? I will try it out.

Ignore this, just a case of RTFM in the ReadMe section of this repo. Was on Mobile before now back on laptop