3
#+]                 @   s   d dl Z d dlZd dlZyd dljZW n ek
rB   d dlZY nX d dlm	Z
 d dlmZ d dlmZ dZG dd de
Z	dS )    N)	WebDriver)WebDriverException)WebDriverWait   c               @   s*   e Zd ZdZdddi fddZdd ZdS )	r   ac  
    Controls the BlackBerry Browser and allows you to drive it.

    :Args:
     - device_password - password for the BlackBerry device or emulator you are
       trying to drive
     - bb_tools_dir path to the blackberry-deploy executable. If the default
       is used it assumes it is in the $PATH
     - hostip - the ip for the device you are trying to drive. Falls back to
       169.254.0.1 which is the default ip used
     - port - the port being used for WebDriver on device. defaults to 1338
     - desired_capabilities: Dictionary object with non-browser specific
       capabilities only, such as "proxy" or "loggingPref".

    Note: To get blackberry-deploy you will need to install the BlackBerry
          WebWorks SDK - the default install will put it in the $PATH for you.
          Download at https://developer.blackberry.com/html5/downloads/
    Nz169.254.0.1i:  c                sb  dj ||}d}tj dkr$|d7 }|d k	rrtjj|rbtjj||}tjj|sptdj |qvtdj |n|}y|dt	|dd	d
ddt	|g	}	t
tjd}
tj|	|
d}W d Q R X |j }|dkr|dt	|dd	d
ddt	|g	 td tj fdddd tj| ||d ntdW n8 tk
r\ } ztdt|dd dW Y d d }~X nX d S )Nzhttp://{}:{}zblackberry-deployWindowsz.batz&Invalid blackberry-deploy location: {}z:Invalid blackberry tools location, must be a directory: {}z
-launchAppz-package-namezsys.browserz-package-idZgYABgJYFHAzbeFMPCCpYWBtHAm0z	-passwordw)stdoutr   z-isAppRunningc                s   t j jdS )Nzresult::true)
subprocesscheck_outputfind)x)is_running_args M/tmp/pip-install-ke3synd2/selenium/selenium/webdriver/blackberry/webdriver.py<lambda>a   s   
z$WebDriver.__init__.<locals>.<lambda>z(waiting for BlackBerry10 browser to load)message)Zcommand_executordesired_capabilitiesz*blackberry-deploy failed to launch browserz0Something went wrong launching blackberry-deploy
stacktrace)r   )formatplatformsystemospathisdirjoinisfiler   stropendevnullr	   Popenwaitr   LOAD_TIMEOUTZuntilRemoteWebDriver__init__	Exceptiongetattr)selfZdevice_passwordZbb_tools_dirZhostipportr   Zremote_addrfilenameZbb_deploy_locationZlaunch_argsfpp
returncodeer   )r   r   r#   5   sJ    



zWebDriver.__init__c             C   s*   yt j|  W n tjk
r$   Y nX dS )z7
        Closes the browser and shuts down the
        N)r"   quithttp_clientBadStatusLine)r&   r   r   r   r-   m   s    zWebDriver.quit)__name__
__module____qualname____doc__r#   r-   r   r   r   r   r   "   s   7r   )r   r   r	   http.clientclientr.   ImportErrorhttplibZ#selenium.webdriver.remote.webdriverr   r"   Zselenium.common.exceptionsr   Zselenium.webdriver.support.uir   r!   r   r   r   r   <module>   s   