microsoft / WinAppDriver

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

WinAppDriver does not close nor quit the session. #1014

Open pcbt opened 4 years ago

pcbt commented 4 years ago

Hi, I am using appium python client and unittest in my app_test.py file. Here is the teardown code:

    @classmethod
    def tearDownClass(self):
        self.app_session.close()
        self.app_session.quit()
        self.session.quit()

session is desktop session (my app using splash screen so I am using desktop session to find it). app_session is obviously my app session. After test ran app is still open. Here is WinAppDriver console:

==========================================
DELETE /session/0B29F7E3-29C9-4637-8597-A9A45AD070FC/window HTTP/1.1
Accept: application/json
Accept-Encoding: identity
Connection: keep-alive
Content-Type: application/json;charset=UTF-8
Host: 127.0.0.1:4723
User-Agent: appium/python 0.48 (selenium/3.141.0 (python windows))

HTTP/1.1 200 OK
Content-Length: 63
Content-Type: application/json

{"sessionId":"0B29F7E3-29C9-4637-8597-A9A45AD070FC","status":0}

==========================================
DELETE /session/0B29F7E3-29C9-4637-8597-A9A45AD070FC HTTP/1.1
Accept: application/json
Accept-Encoding: identity
Connection: keep-alive
Content-Type: application/json;charset=UTF-8
Host: 127.0.0.1:4723
User-Agent: appium/python 0.48 (selenium/3.141.0 (python windows))

HTTP/1.1 200 OK
Content-Length: 12
Content-Type: application/json

{"status":0}

==========================================
DELETE /session/A337864D-16ED-45F6-85FD-5FF6D1C6844B HTTP/1.1
Accept: application/json
Accept-Encoding: identity
Connection: keep-alive
Content-Type: application/json;charset=UTF-8
Host: 127.0.0.1:4723
User-Agent: appium/python 0.48 (selenium/3.141.0 (python windows))

HTTP/1.1 200 OK
Content-Length: 12
Content-Type: application/json

{"status":0}

When I try to run tests again application quits immediately. Here is WinAppDriver console (continue from above):

==========================================
POST /session HTTP/1.1
Accept: application/json
Accept-Encoding: identity
Connection: keep-alive
Content-Length: 213
Content-Type: application/json;charset=UTF-8
Host: 127.0.0.1:4723
User-Agent: appium/python 0.48 (selenium/3.141.0 (python windows))

{"capabilities": {"firstMatch": [{"platformName": "Windows", "appium:app": "Root", "appium:deviceName": "WindowsPc"}]}, "desiredCapabilities": {"platformName": "Windows", "app": "Root", "deviceName": "WindowsPc"}}
HTTP/1.1 200 OK
Content-Length: 111
Content-Type: application/json

{"sessionId":"B2D5B106-F928-4CE3-B403-8184D269403B","status":0,"value":{"app":"Root","platformName":"Windows"}}

==========================================
POST /session/B2D5B106-F928-4CE3-B403-8184D269403B/elements HTTP/1.1
Accept: application/json
Accept-Encoding: identity
Connection: keep-alive
Content-Length: 93
Content-Type: application/json;charset=UTF-8
Host: 127.0.0.1:4723
User-Agent: appium/python 0.48 (selenium/3.141.0 (python windows))

{"using": "tag name", "value": "Window", "sessionId": "B2D5B106-F928-4CE3-B403-8184D269403B"}

### SearchMultipleElements exception: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

HTTP/1.1 200 OK
Content-Length: 74
Content-Type: application/json

{"sessionId":"B2D5B106-F928-4CE3-B403-8184D269403B","status":0,"value":[]}

I have three unittest methods in my test.py file and when I run them individually in VS Code; after first one ran the app quits, after second and third one ran the app does not quit. I checked WinAppDriver console for each unittest method but there is nothing different in the last commands which are DELETE commands given above. By the way this teardown code works in different test file with two unittest methods and application quits succesfully. What could be the reason?

fenchu commented 4 years ago

Try upgrading to appium-python-client v.49, because it works all fine, haven't tested v.48 since there was a v.49 already out:

    @classmethod
    def tearDownClass(self):
        if not args.keep and hasattr(self, 'driver'):
            self.driver.quit()
            self.driver = None
HTTP/1.1 200 OK
Content-Length: 76
Content-Type: application/json

{"sessionId":"E6C2DBED-90C4-4CAA-9DDE-3BC77A81C8BE","status":0,"value":true}

==========================================
DELETE /session/E6C2DBED-90C4-4CAA-9DDE-3BC77A81C8BE HTTP/1.1
Accept: application/json
Accept-Encoding: identity
Connection: keep-alive
Content-Type: application/json;charset=UTF-8
Host: 127.0.0.1:4723
User-Agent: appium/python 0.49 (selenium/3.141.0 (python windows))

HTTP/1.1 200 OK
Content-Length: 12
Content-Type: application/json

{"status":0}
yotsubakoiwai commented 4 years ago

i am using C# and NUnit, in my TearDown i just called driver.close(); then driver.quit(); and it's worked :)

pcbt commented 4 years ago

Hi @fenchu ,

Why did you use this part:

    @classmethod
    def tearDownClass(self):
        if not args.keep and hasattr(self, 'driver'):
            self.driver.quit()
            self.driver = None

It gives me this error:

    if not args.keep and hasattr(self, 'app_session'):
NameError: name 'args' is not defined

By the way in my conda environment appium 0.49 is installed but WinAppDriver claims it is 0.48:

appium_version

pcbt commented 4 years ago

Hi @yotsubakoiwai ,

Python version also works, sometimes :)