B
     h                 @   s@   d dl Z d dlZd dlZd dlZd dlmZ G dd deZdS )    N)DesiredCapabilitiesc               @   s   e Zd ZdZdd Zedd Zejdd Zedd Zd	d
 Z	edd Z
e
jdd Z
edd Zdd Zedd Zdd Zdd Zedd Zdd Zedd Zejdd Zd%d d!Zd"d# Zd$S )&Optionszgoog:chromeOptionsc             C   s4   d| _ g | _g | _g | _i | _d | _tj | _	d S )N )
_binary_location
_arguments_extension_files_extensions_experimental_options_debugger_addressr   CHROMEcopy_caps)self r   ^C:\Users\sanjo\AppData\Local\Qlobot\Launcher\ext_packages\selenium\webdriver\chrome\options.py__init__   s    zOptions.__init__c             C   s   | j S )zN
        Returns the location of the binary otherwise an empty string
        )r   )r   r   r   r   binary_location&   s    zOptions.binary_locationc             C   s
   || _ dS )z
        Allows you to set where the chromium binary lives

        :Args:
         - value: path to the Chromium binary
        N)r   )r   valuer   r   r   r   -   s    c             C   s   | j S )N)r   )r   r   r   r   capabilities7   s    zOptions.capabilitiesc             C   s   || j |< dS )zSets a capability.N)r   )r   namer   r   r   r   set_capability;   s    zOptions.set_capabilityc             C   s   | j S )zE
        Returns the address of the remote devtools instance
        )r
   )r   r   r   r   debugger_address?   s    zOptions.debugger_addressc             C   s
   || _ dS )a  
        Allows you to set the address of the remote devtools instance
        that the ChromeDriver instance will try to connect to during an
        active wait.

        :Args:
         - value: address of remote devtools instance if any (hostname[:port])
        N)r
   )r   r   r   r   r   r   F   s    
c             C   s   | j S )zD
        Returns a list of arguments needed for the browser
        )r   )r   r   r   r   	argumentsR   s    zOptions.argumentsc             C   s   |r| j | ntddS )z\
        Adds an argument to the list

        :Args:
         - Sets the arguments
        zargument can not be nullN)r   append
ValueError)r   argumentr   r   r   add_argumentY   s    zOptions.add_argumentc             C   sJ   g }x:| j D ]0}t|d}|t| d |  qW || j S )zW
        Returns a list of encoded extensions that will be loaded into chrome

        rbzUTF-8)	r   openr   base64	b64encodereaddecodecloser   )r   Zencoded_extensionsextZfile_r   r   r   
extensionse   s    
zOptions.extensionsc             C   sH   |r<t jt j|}t j|r2| j| qDtdntddS )z
        Adds the path to the extension to a list that will be used to extract it
        to the ChromeDriver

        :Args:
         - extension: path to the \*.crx file
        z#Path to the extension doesn't existzargument can not be nullN)	ospathabspath
expanduserexistsr   r   IOErrorr   )r   	extensionZextension_to_addr   r   r   add_extensionv   s    
zOptions.add_extensionc             C   s   |r| j | ntddS )z
        Adds Base64 encoded string with extension data to a list that will be used to extract it
        to the ChromeDriver

        :Args:
         - extension: Base64 encoded string with extension data
        zargument can not be nullN)r   r   r   )r   r,   r   r   r   add_encoded_extension   s    zOptions.add_encoded_extensionc             C   s   | j S )zJ
        Returns a dictionary of experimental options for chrome.
        )r	   )r   r   r   r   experimental_options   s    zOptions.experimental_optionsc             C   s   || j |< dS )z
        Adds an experimental option which is passed to chrome.

        Args:
          name: The experimental option name.
          value: The option value.
        N)r	   )r   r   r   r   r   r   add_experimental_option   s    zOptions.add_experimental_optionc             C   s
   d| j kS )zE
        Returns whether or not the headless argument is set
        z
--headless)r   )r   r   r   r   headless   s    zOptions.headlessc             C   sN   dh}t   dkr |d |dkr6| j| ntt| j| | _dS )z
        Sets the headless argument

        Args:
          value: boolean value indicating to set the headless option
        z
--headlessZwindowsz--disable-gpuTN)platformsystemloweraddr   extendlistset)r   r   argsr   r   r   r1      s    
Tc             C   s   t jdtdd || _dS )z% Deprecated, options.headless = True z8use setter for headless property instead of set_headless   )
stacklevelN)warningswarnDeprecationWarningr1   )r   r1   r   r   r   set_headless   s    
zOptions.set_headlessc             C   sR   | j }| j }| j|d< | jr*| j|d< | j|d< | jrD| j|d< ||| j< |S )z
            Creates a capabilities with all the options that have been set and

            returns a dictionary with everything
        r%   binaryr9   ZdebuggerAddress)r   r/   r   r%   r   r   r   KEY)r   capschrome_optionsr   r   r   to_capabilities   s    





zOptions.to_capabilitiesN)T)__name__
__module____qualname__rA   r   propertyr   setterr   r   r   r   r   r%   r-   r.   r/   r0   r1   r?   rD   r   r   r   r   r      s&   	


r   )r   r&   r2   r<   .selenium.webdriver.common.desired_capabilitiesr   objectr   r   r   r   r   <module>   s
   