wgnet / webium

Webium is a Page Object pattern implementation library for Python (http://martinfowler.com/bliki/PageObject.html). It allows you to extend WebElement class to your custom controls like Link, Button and group them as pages.
Apache License 2.0
161 stars 37 forks source link

Driver instance does not restart when new page object is instantiated after calling get_driver().quit() #11

Closed nimicohgr closed 8 years ago

nimicohgr commented 8 years ago

We have a need to restart the browser after certain tests. However, after get_driver().quit() is called, Webium will not automatically create the driver itself in the following test. The simplest example I could come up with that reproduces the behavior can be found below. I'm not certain if this is a webium issue, or just a usage issue on my part. Any suggestions as to achieve the desired behavior would be greatly appreciated.

from selenium.webdriver.common.by import By
from selenium.webdriver.remote.webelement import WebElement
from webium.controls.link import Link
from webium.driver import get_driver
from webium import BasePage, Find, Finds

class GooglePage(BasePage):
    url = 'http://www.google.com'

def test_one():
    home_page = GooglePage()
    home_page.open()
    get_driver().quit()

def test_two():
    home_page = GooglePage()
    home_page.open()
    get_driver().quit()

test_one()
test_two()

Traceback (most recent call last): File "github_example.py", line 21, in test_two() File "github_example.py", line 17, in test_two home_page.open() File "/Users/Code/venv/lib/python3.5/site-packages/webium/base_page.py", line 54, in open self._driver.get(self.url) File "/Users/Code/venv/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 213, in get self.execute(Command.GET, {'url': url}) File "/Users/Code/venv/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 199, in execute response = self.command_executor.execute(driver_command, params) File "/Users/Code/venv/lib/python3.5/site-packages/selenium/webdriver/remote/remote_connection.py", line 395, in execute return self._request(command_info[0], url, body=data) File "/Users/Code/venv/lib/python3.5/site-packages/selenium/webdriver/remote/remote_connection.py", line 425, in _request self._conn.request(method, parsed_url.path, body, headers) File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 1083, in request self._send_request(method, url, body, headers) File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 1128, in _send_request self.endheaders(body) File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 1079, in endheaders self._send_output(message_body) File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 911, in _send_output self.send(msg) File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 854, in send self.connect() File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 826, in connect (self.host,self.port), self.timeout, self.source_address) File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/socket.py", line 711, in create_connection raise err File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/socket.py", line 702, in create_connection sock.connect(sa) ConnectionRefusedError: [Errno 61] Connection refused

nimicohgr commented 8 years ago

Alright, I may have figured it out. I am importing close_driver now and calling it between tests.

This new code works as I expect:

from selenium.webdriver.common.by import By
from selenium.webdriver.remote.webelement import WebElement
from webium.controls.link import Link
from webium.driver import get_driver, close_driver
from webium import BasePage, Find, Finds

class GooglePage(BasePage):
    url = 'http://www.google.com'

def test_one():
    home_page = GooglePage()
    home_page.open()
    close_driver()

def test_two():
    home_page = GooglePage()
    home_page.open()
    get_driver().quit()

test_one()
test_two()