Skip to content

Commit

Permalink
androiddriver-py1.0-final
Browse files Browse the repository at this point in the history
  • Loading branch information
truebit committed Oct 14, 2011
1 parent 135926e commit 345e7f3
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 35 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.swp
.pyc
.*.swp
.*.pyc
21 changes: 10 additions & 11 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,26 @@ As I am a newbie, I do not expect to commit in the Selenium project.
To install this AndroidDriver for Python, you need:
1. download and extract Python client from http://pypi.python.org/pypi/selenium#downloads
2. download AndroidWebDriver4Python from using git clone git://github.com/truebit/AndroidWebDriver4Python.git
3. navigate to ../selenium-2.x.x/py/selenium/webdriver
4. copy the entire folder of android under AndroidWebDriver4Python to above
directory
5. add one line in file __init__.py in directory that was mentioned in step 3:
from android.webdriver import WebDriver as Android
put this line besides other similiar looked lines
6. back to the root directory of Selenium Python Client, to install this
4. copy the entire 'py' folder under AndroidWebDriver4Python to merge the
same one in root directory of AndroidDriver for Python
5. back to the root directory of Selenium Python Client, to install this
modified version using command:
python setup.py install

Here you have installed this AndroidWebDriver4Python add-on.
There are some prerequisites to use AndroidWebDriver4Python.

7. Install Android SDK and set 'tools' and 'platform-tools' in your PATH:
6. Install Android SDK and set 'tools' and 'platform-tools' in your PATH:
http://developer.android.com/sdk/installing.html

8. Install Android server side application on your device:
7. Install Android server side application on your device:
Download android-server-2.x.x.apk from
http://code.google.com/p/selenium/downloads/list

9. enable 'USB Debugging' in your device, which normally could found from:
8. enable 'USB Debugging' in your device, which normally could found from:
Settings>Applications>Development>USB debugging

10. connect USB cable between device and PC, install adb drivers
9. connect USB cable between device and PC, install adb drivers

For more information you could check
http://code.google.com/p/selenium/downloads/list,but you do not need to do all
Expand All @@ -58,7 +54,10 @@ Example
from selenium import webdriver

driver= webdriver.Android()
#another way is to explicitly specify the serial id of the device
#driver=webdriver.Android('emulator-5554')
driver.get("http://www.symbio.com")
driver.quit()

============
Documentation
Expand Down
Binary file removed android/service.pyc
Binary file not shown.
28 changes: 28 additions & 0 deletions py/selenium/webdriver/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/python
#
# Copyright 2008-2010 Webdriver_name committers
# Copyright 2008-2010 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# added Android - Sean Wang
from android.webdriver import WebDriver as Android
from firefox.webdriver import WebDriver as Firefox
from firefox.firefox_profile import FirefoxProfile
from chrome.webdriver import WebDriver as Chrome
from ie.webdriver import WebDriver as Ie
from remote.webdriver import WebDriver as Remote
from common.desired_capabilities import DesiredCapabilities
from common.action_chains import ActionChains

__version__ = '2.8.0'
28 changes: 14 additions & 14 deletions android/__init__.py → py/selenium/webdriver/android/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Copyright 2008-2009 WebDriver committers
# Copyright 2008-2009 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Copyright 2008-2009 WebDriver committers
# Copyright 2008-2009 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
14 changes: 9 additions & 5 deletions android/service.py → py/selenium/webdriver/android/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def initDevice(deviceID=None):
def runAdbCmd(cmd):
"""run an adb command which has no output if successful"""
out=''
out=subprocess.check_output(cmd, stderr=subprocess.STDOUT)
out=subprocess.check_output(cmd, stderr=subprocess.STDOUT,shell=True)
if out:
raise WebDriverException(out)

Expand All @@ -100,12 +100,16 @@ def start(self):
WebDriverException : Raised either when it can't start the service
or when it can't connect to the service"""

print 'start forward'
print 'start tcp port 8080 forwarding'
Service.runAdbCmd('%s forward tcp:8080 tcp:8080'%self.adbCmd)
print 'start press back 4 times'
print 'stop existing android server by sending back key'
# this is not mandatory as we already killed adb server, but could this
# decrease the webview created in andriod server application. maybe
# it's a bug to create one webview per launch of app?
for i in xrange(4):
(r'%s shell input keyevent 4'%self.adbCmd)
print 'start activity'
Service.runAdbCmd(r'%s shell input keyevent 4'%self.adbCmd)

print 'start android server activity'
err=subprocess.Popen(r'%s shell am start -n org.openqa.selenium.android.app/.MainActivity'%self.adbCmd
,stderr=PIPE,stdout=PIPE).communicate()[1]
if err:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

class WebDriver(RemoteWebDriver):

def __init__(self):
self.service = Service()
def __init__(self,deviceID=None):
self.service = Service(deviceID)
self.service.start()
RemoteWebDriver.__init__(self,
command_executor=self.service.service_url,
Expand All @@ -21,5 +21,6 @@ def quit(self):
finally:
self.service.stop()
if __name__ == '__main__':
driver= WebDriver()
driver= WebDriver('emulator-5554')
driver.get("http://www.symbio.com")
driver.quit()

0 comments on commit 345e7f3

Please sign in to comment.