ResourceWarning on closed driver object

Issue

I’m starting to use a Page Object design pattern for automated testing in Selenium in Python.

I get to an error which (as I learned) stands that I didn’t close some resources.

C:\Users\48796\PycharmProjects\test_page_mobile\venv\lib\site-packages\selenium\webdriver\remote\remote_connection.py:374: ResourceWarning: unclosed <socket.socket fd=512, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('127.0.0.1', 55580), raddr=('127.0.0.1', 4723)>
return self._request(command_info[0], url, body=data)
ResourceWarning: Enable tracemalloc to get the object allocation traceback

I don’t really understand why this appears four times in a row for this code:

import unittest
from selenium import webdriver
from src.Pages.MainPage import MainPage


class Test001(unittest.TestCase):

    def setUp(self):
        desired_capabilities = {
           "platformName": "Android",
           "platformVersion": "11",
            "deviceName": "emulator-5554",  # cmd -> adb devices
            "browserName": "Chrome"
        }

        self.driver = webdriver.Remote("http://localhost:4723/wd/hub", desired_capabilities)

    def test_print_title(self):
        main_page = MainPage(self.driver)
        print(main_page.get_title())
    
    def tearDown(self):
        self.driver.close()


if __name__ == '__main__':
    unittest.main()

And as you can see the driver is being closed in the "tearDown" method. What do I do wrong? 🙁

Solution

Ok, I found out what was an issue. It was an import. I used

from selenium import webdriver

But for Appium server I should use Appium Webdriver

from appium import webdriver

which is a part of the package "Appium-Python-Client" (instead of "selenium")

Answered By – Alan Filas

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published