B
     h;                 @   s   d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ e eZd ZdZdZG dd	 d	e	ZG d
d deZdS )    N)DesiredCapabilities)utils)Command)RemoteConnection)FirefoxBinary c               @   s@   e Zd ZdddZdddZdd Zed	d
 Zedd ZdS )ExtensionConnectionN   c             C   s   || _ || _|}t|}| jd kr*t | _|d kr6d}t }|| j _| j   | j   | jj	| j |d d||f }t
j| |dd d S )Nz	127.0.0.1)timeoutzhttp://%s:%d/hubT)
keep_alive)profilebinaryintr   r   	free_portportZupdate_preferencesadd_extensionZlaunch_browserr   __init__)selfhostfirefox_profilefirefox_binaryr
   HOSTPORT_URL r   lC:\Users\sanjo\AppData\Local\Qlobot\Launcher\ext_packages\selenium\webdriver\firefox\extension_connection.pyr   "   s     


zExtensionConnection.__init__c             C   s8   |  tjd|i x |  r2td td qW d S )N	sessionIdzwaiting to quit   )executer   QUITis_connectableLOGGERinfotimesleep)r   r   r   r   r   quit9   s    

zExtensionConnection.quitc             C   s   |  tjdtjiS )z7Connects to the extension and retrieves the session id.desiredCapabilities)r   r   NEW_SESSIONr   FIREFOX)r   r   r   r   connect?   s    zExtensionConnection.connectc             C   s   |  dt  dS )z4Connects to an running browser and quit immediately.z%s/extensions/firefox/quitN)_requestr   )r   r   r   r   connect_and_quitD   s    z$ExtensionConnection.connect_and_quitc             C   s   t | jj dS )z=Trys to connect to the extension but do not retrieve context.N)r   r    r   r   )r   r   r   r   r    I   s    z"ExtensionConnection.is_connectable)Nr	   )N)	__name__
__module____qualname__r   r%   r)   classmethodr+   r    r   r   r   r   r   !   s
   

r   c               @   s   e Zd ZdZdS )ExtensionConnectionErrorziAn internal error occurred int the extension.

    Might be caused by bad input or bugs in webdriver
    N)r,   r-   r.   __doc__r   r   r   r   r0   O   s   r0   )loggingr#   .selenium.webdriver.common.desired_capabilitiesr   Zselenium.webdriver.commonr   Z!selenium.webdriver.remote.commandr   Z+selenium.webdriver.remote.remote_connectionr   Z)selenium.webdriver.firefox.firefox_binaryr   	getLoggerr,   r!   r   r   r   r   	Exceptionr0   r   r   r   r   <module>   s   
.