U
    b$#                     @   sN   d dl mZmZ d dlmZ d dlmZ G dd dedZG dd deZd	S )
    )ABCMetaabstractmethod)Proxy)InvalidArgumentExceptionc                       s  e Zd ZdZ fddZedd Zdd Zeedd	d
Z	e	j
edddd
Z	eedddZej
eddddZeedddZej
eddddZeedddZej
eddddZeedddZej
eddddZd3eeeddd Zeedd!d"Zej
edd#d$d"Zeedd%d&Zej
ed'd(d&Zeedd)d*Zej
ed'd+d*Zeedd,d-Zej
ed'd.d-Zed/d0 Zeed1d2 Z  ZS )4BaseOptionsz3
    Base class for individual browser options
    c                    s(   t    | j| _| dd d | _d S )NpageLoadStrategynormal)super__init__default_capabilities_capsset_capabilitymobile_optionsself	__class__ E/tmp/pip-unpacked-wheel-3sqd7awy/selenium/webdriver/common/options.pyr
      s    
zBaseOptions.__init__c                 C   s   | j S Nr   r   r   r   r   capabilities"   s    zBaseOptions.capabilitiesc                 C   s   || j |< dS )z Sets a capability Nr   )r   namevaluer   r   r   r   &   s    zBaseOptions.set_capability)returnc                 C   s
   | j d S )zN
        :returns: the version of the browser if set, otherwise None.
        browserVersionr   r   r   r   r   browser_version*   s    zBaseOptions.browser_versionN)versionr   c                 C   s   |  d| dS )z
        Requires the major version of the browser to match provided value:
        https://w3c.github.io/webdriver/#dfn-browser-version

        :param version: The required version of the browser
        r   Nr   )r   r   r   r   r   r   1   s    c                 C   s
   | j d S )z4
        :returns: The name of the platform
        platformNamer   r   r   r   r   platform_name;   s    zBaseOptions.platform_name)platformr   c                 C   s   |  d| dS )z
        Requires the platform to match the provided value: https://w3c.github.io/webdriver/#dfn-platform-name

        :param platform: the required name of the platform
        r   Nr   )r   r!   r   r   r   r    B   s    c                 C   s
   | j d S )zN
        :returns: page load strategy if set, the default is "normal"
        r   r   r   r   r   r   page_load_strategyK   s    zBaseOptions.page_load_strategy)strategyr   c                 C   s"   |dkr|  d| ntddS )z
        Determines the point at which a navigation command is returned:
        https://w3c.github.io/webdriver/#dfn-table-of-page-load-strategies

        :param strategy: the strategy corresponding to a document readiness state
        )r   eagernoner   z>Strategy can only be one of the following: normal, eager, noneNr   
ValueError)r   r#   r   r   r   r"   R   s    c                 C   s
   | j d S )za
        :returns: unhandled prompt behavior if set, the default is "dismiss and notify"
        unhandledPromptBehaviorr   r   r   r   r   unhandled_prompt_behavior_   s    z%BaseOptions.unhandled_prompt_behavior)behaviorr   c                 C   s"   |dkr|  d| ntddS )a
  
        How the driver should respond when an alert is present and the command sent is not handling the alert:
        https://w3c.github.io/webdriver/#dfn-table-of-page-load-strategies

        :param behavior: behavior to use when an alert is encountered
        )Zdismissacceptzdismiss and notifyzaccept and notifyignorer(   ziBehavior can only be one of the following: dismiss, accept, dismiss and notify, accept and notify, ignoreNr&   )r   r*   r   r   r   r)   f   s    c                 C   s
   | j d S )zu
        :returns: Values for implicit timeout, pageLoad timeout and script timeout if set (in milliseconds)
        timeoutsr   r   r   r   r   r-   t   s    zBaseOptions.timeouts)r-   r   c                    s0   t  fdddD r$| d  ntddS )z
        How long the driver should wait for actions to complete before returning an error
        https://w3c.github.io/webdriver/#timeouts

        :param timeouts: values in milliseconds for implicit wait, page load and script timeout
        c                 3   s   | ]}|   kV  qd S r   )keys).0xr-   r   r   	<genexpr>   s     z'BaseOptions.timeouts.<locals>.<genexpr>)ZimplicitZpageLoadscriptr-   zITimeout keys can only be one of the following: implicit, pageLoad, scriptN)allr   r'   )r   r-   r   r1   r   r-   {   s    )android_packageandroid_activitydevice_serialc                 C   s6   |st dd|i| _|r$|| jd< |r2|| jd< dS )z
            Enables mobile browser use for browsers that support it

            :Args:
                android_activity: The name of the android package to start
        z!android_package must be passed inZandroidPackageZandroidActivityZandroidDeviceSerialN)AttributeErrorr   )r   r5   r6   r7   r   r   r   enable_mobile   s     
zBaseOptions.enable_mobilec                 C   s   | j dS )zM
        :returns: whether the session accepts insecure certificates
        acceptInsecureCertsr   getr   r   r   r   accept_insecure_certs   s    z!BaseOptions.accept_insecure_certs)r   r   c                 C   s   || j d< dS )z
        Whether untrusted and self-signed TLS certificates are implicitly trusted:
        https://w3c.github.io/webdriver/#dfn-insecure-tls-certificates

        :param value: whether to accept insecure certificates
        r:   Nr   r   r   r   r   r   r=      s    c                 C   s   | j dS )zP
        :returns: whether session is strict about file interactability
        strictFileInteractabilityr;   r   r   r   r   strict_file_interactability   s    z'BaseOptions.strict_file_interactability)r   c                 C   s   || j d< dS )z
        Whether interactability checks will be applied to file type input elements. The default is false.

        :param value: whether file interactability is strict
        r?   Nr   r>   r   r   r   r@      s    c                 C   s   | j dS )z\
        :returns: whether the remote end supports setting window size and position
        setWindowRectr;   r   r   r   r   set_window_rect   s    zBaseOptions.set_window_rectc                 C   s   || j d< dS )a  
        Whether the remote end supports all of the resizing and positioning commands. The default is false.
        https://w3c.github.io/webdriver/#dfn-strict-file-interactability

        :param value: whether remote end must support setting window resizing and repositioning
        rA   Nr   r>   r   r   r   rB      s    c                 C   s   | j S )z9
        :Returns: Proxy if set, otherwise None.
        )_proxyr   r   r   r   proxy   s    zBaseOptions.proxyc                 C   s   t |tstd|| _d S )Nz$Only Proxy objects can be passed in.)
isinstancer   r   rC   r>   r   r   r   rD      s    
c                 C   s   dS )z-Convert options into capabilities dictionary.Nr   r   r   r   r   to_capabilities   s    zBaseOptions.to_capabilitiesc                 C   s   dS )z6Return minimal capabilities necessary as a dictionary.Nr   r   r   r   r   r      s    z BaseOptions.default_capabilities)NNN)__name__
__module____qualname____doc__r
   propertyr   r   strr   setterr    r"   r)   dictr-   r9   boolr=   r@   rB   r   rD   r   rF   r   __classcell__r   r   r   r   r      s^   
			
r   )	metaclassc                       sL   e Zd Z fddZedd Zdd Zdd Zd	d
 Zedd Z	  Z
S )
ArgOptionsc                    s   t    g | _d| _d S )NF)r	   r
   
_arguments_ignore_local_proxyr   r   r   r   r
      s    
zArgOptions.__init__c                 C   s   | j S )zF
        :Returns: A list of arguments needed for the browser
        )rS   r   r   r   r   	arguments   s    zArgOptions.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)rS   appendr'   )r   argumentr   r   r   add_argument   s    zArgOptions.add_argumentc                 C   s
   d| _ dS )zo
            By calling this you will ignore HTTP_PROXY and HTTPS_PROXY from being picked up and used.
        TN)rT   r   r   r   r   (ignore_local_proxy_environment_variables   s    z3ArgOptions.ignore_local_proxy_environment_variablesc                 C   s   | j S r   r   r   r   r   r   rF     s    zArgOptions.to_capabilitiesc                 C   s   i S r   r   r   r   r   r   r     s    zArgOptions.default_capabilities)rG   rH   rI   r
   rK   rU   rX   rY   rF   r   rP   r   r   r   r   rR      s   
rR   N)	abcr   r   Zselenium.webdriver.common.proxyr   Zselenium.common.exceptionsr   r   rR   r   r   r   r   <module>   s
    L