├── .gitattributes
├── .gitignore
├── LICENSE
├── README.md
├── autopydriverserver
├── __init__.py
├── element_image_map.cfg
├── favicon.ico
└── server.py
├── linux_mac_requirements.txt
├── sample-code
├── calculator_demo.py
├── images
│ ├── calc_1_btn.png
│ ├── calc_2_btn.png
│ ├── calc_3_result - Copy.png
│ ├── calc_3_result.png
│ ├── calc_equals_btn.png
│ ├── calc_plus_btn.png
│ ├── calc_val_field.png
│ ├── dnd_result.png
│ ├── dnd_result2.png
│ ├── drag_src.png
│ ├── drag_src_html5.png
│ ├── drop_target.png
│ └── drop_target_html5.png
├── web_drag_and_drop_demo.py
└── webdriver_integration_demo.py
└── windows_requirements.txt
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 | *.sln merge=union
7 | *.csproj merge=union
8 | *.vbproj merge=union
9 | *.fsproj merge=union
10 | *.dbproj merge=union
11 |
12 | # Standard to msysgit
13 | *.doc diff=astextplain
14 | *.DOC diff=astextplain
15 | *.docx diff=astextplain
16 | *.DOCX diff=astextplain
17 | *.dot diff=astextplain
18 | *.DOT diff=astextplain
19 | *.pdf diff=astextplain
20 | *.PDF diff=astextplain
21 | *.rtf diff=astextplain
22 | *.RTF diff=astextplain
23 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #################
2 | ## Eclipse
3 | #################
4 |
5 | *.pydevproject
6 | .project
7 | .metadata
8 | bin/
9 | tmp/
10 | *.tmp
11 | *.bak
12 | *.swp
13 | *~.nib
14 | local.properties
15 | .classpath
16 | .settings/
17 | .loadpath
18 |
19 | # External tool builders
20 | .externalToolBuilders/
21 |
22 | # Locally stored "Eclipse launch configurations"
23 | *.launch
24 |
25 | # CDT-specific
26 | .cproject
27 |
28 | # PDT-specific
29 | .buildpath
30 |
31 |
32 | #################
33 | ## Visual Studio
34 | #################
35 |
36 | ## Ignore Visual Studio temporary files, build results, and
37 | ## files generated by popular Visual Studio add-ons.
38 |
39 | # User-specific files
40 | *.suo
41 | *.user
42 | *.sln.docstates
43 |
44 | # Build results
45 |
46 | [Dd]ebug/
47 | [Rr]elease/
48 | x64/
49 | build/
50 | [Bb]in/
51 | [Oo]bj/
52 |
53 | # MSTest test Results
54 | [Tt]est[Rr]esult*/
55 | [Bb]uild[Ll]og.*
56 |
57 | *_i.c
58 | *_p.c
59 | *.ilk
60 | *.meta
61 | *.obj
62 | *.pch
63 | *.pdb
64 | *.pgc
65 | *.pgd
66 | *.rsp
67 | *.sbr
68 | *.tlb
69 | *.tli
70 | *.tlh
71 | *.tmp
72 | *.tmp_proj
73 | *.log
74 | *.vspscc
75 | *.vssscc
76 | .builds
77 | *.pidb
78 | *.log
79 | *.scc
80 |
81 | # Visual C++ cache files
82 | ipch/
83 | *.aps
84 | *.ncb
85 | *.opensdf
86 | *.sdf
87 | *.cachefile
88 |
89 | # Visual Studio profiler
90 | *.psess
91 | *.vsp
92 | *.vspx
93 |
94 | # Guidance Automation Toolkit
95 | *.gpState
96 |
97 | # ReSharper is a .NET coding add-in
98 | _ReSharper*/
99 | *.[Rr]e[Ss]harper
100 |
101 | # TeamCity is a build add-in
102 | _TeamCity*
103 |
104 | # DotCover is a Code Coverage Tool
105 | *.dotCover
106 |
107 | # NCrunch
108 | *.ncrunch*
109 | .*crunch*.local.xml
110 |
111 | # Installshield output folder
112 | [Ee]xpress/
113 |
114 | # DocProject is a documentation generator add-in
115 | DocProject/buildhelp/
116 | DocProject/Help/*.HxT
117 | DocProject/Help/*.HxC
118 | DocProject/Help/*.hhc
119 | DocProject/Help/*.hhk
120 | DocProject/Help/*.hhp
121 | DocProject/Help/Html2
122 | DocProject/Help/html
123 |
124 | # Click-Once directory
125 | publish/
126 |
127 | # Publish Web Output
128 | *.Publish.xml
129 | *.pubxml
130 |
131 | # NuGet Packages Directory
132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line
133 | #packages/
134 |
135 | # Windows Azure Build Output
136 | csx
137 | *.build.csdef
138 |
139 | # Windows Store app package directory
140 | AppPackages/
141 |
142 | # Others
143 | sql/
144 | *.Cache
145 | ClientBin/
146 | [Ss]tyle[Cc]op.*
147 | ~$*
148 | *~
149 | *.dbmdl
150 | *.[Pp]ublish.xml
151 | *.pfx
152 | *.publishsettings
153 |
154 | # RIA/Silverlight projects
155 | Generated_Code/
156 |
157 | # Backup & report files from converting an old project file to a newer
158 | # Visual Studio version. Backup files are not needed, because we have git ;-)
159 | _UpgradeReport_Files/
160 | Backup*/
161 | UpgradeLog*.XML
162 | UpgradeLog*.htm
163 |
164 | # SQL Server files
165 | App_Data/*.mdf
166 | App_Data/*.ldf
167 |
168 | #############
169 | ## Windows detritus
170 | #############
171 |
172 | # Windows image file caches
173 | Thumbs.db
174 | ehthumbs.db
175 |
176 | # Folder config file
177 | Desktop.ini
178 |
179 | # Recycle Bin used on file shares
180 | $RECYCLE.BIN/
181 |
182 | # Mac crap
183 | .DS_Store
184 |
185 |
186 | #############
187 | ## Python
188 | #############
189 |
190 | *.py[co]
191 |
192 | # Packages
193 | *.egg
194 | *.egg-info
195 | dist/
196 | build/
197 | eggs/
198 | parts/
199 | var/
200 | sdist/
201 | develop-eggs/
202 | .installed.cfg
203 |
204 | # Installer logs
205 | pip-log.txt
206 |
207 | # Unit test / coverage reports
208 | .coverage
209 | .tox
210 |
211 | #Translations
212 | *.mo
213 |
214 | #Mr Developer
215 | .mr.developer.cfg
216 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [2012] [Appium Contributors]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | AutoPyDriverServer
2 | =========
3 |
4 | AutoPyDriverServer is a (test) automation tool via image recognition that provides a Selenium WebDriver API via the webdriver JSON wire protocol to drive to the [AutoPy](https://github.com/msanders/autopy) tool/library running as a server. It is adapted from the [old Appium server Python implementation](https://github.com/hugs/appium-old).
5 |
6 | AutoPyDriverServer uses the [Bottle micro web-framework](http://www.bottlepy.org), and has the goal of working with all off the shelf Selenium client libraries.
7 |
8 | There are two benefits to testing with AutoPyDriverServer:
9 |
10 | 1: With AutoPyDriverServer, you are able to write your test in your choice of programming language, using the Selenium WebDriver API and language-specific client libraries. If you only used AutoPy, you would be required to write tests in Python, or interface to some Python code to call AutoPy.
11 |
12 | 2: AutoPyDriverServer uses the AutoPy library for Python, which provides cross-plaform support for some image recognition capability and mouse, keyboard manipulation. If you already use AutoPy, this will be a nice benefit.
13 |
14 | Quick Start
15 | -----------
16 |
17 | To get started, clone the repo:
18 |
19 | `git clone git://github.com/daluu/AutoPyDriverServer`
20 |
21 | Next, change into the 'autopydriverserver' directory, and install dependencies:
22 | `pip install -r linux_mac_requirements.txt`
23 | or
24 | `pip install -r windows_requirements.txt`
25 |
26 | For Windows, you may wish to manually install AutoPy module (dependency), which is not in the requirements file for Windows (above), as suggested by AutoPy author. Get the binary installer at https://pypi.python.org/pypi/autopy/
27 |
28 | To launch a webdriver-compatible server, run:
29 | `python server.py`
30 |
31 | For additional parameter info, append the `--help` parameter
32 |
33 | Example WebDriver API/client test usage against this server tool can be found in `sample-code` folder. To run the test, startup the server (with customized parameters as needed, recommend set address to 127.0.0.1) and review the example files' code before executing those scripts. Examples use Python WebDriver binding, but any language binding will do.
34 |
35 | NOTES/Caveats
36 | -------------
37 |
38 | AutoPyDriverServer is simply a WebDriver server interface to AutoPy. Issues you experience may usually be the result of an issue with AutoPy rather than AutoPyDriverServer itself. If you are experienced with Python, it would be wise to test your issue/scenario using native Python AutoPy API to confirm whether the issue is with AutoPy or AutoPyDriverServer. The source code of AutoPyDriverServer will point you to the appropriate AutoPy API or see the [AutoPy Python API specifics for debugging](https://github.com/daluu/AutoPyDriverServer/wiki/AutoPy-Python-API-specifics-for-debugging).
39 |
40 | The server isn't flawless and may at times appear to crash on you (on Windows, resulting ina popup about program hanging and whether you want to close it or do something else), upon receivng some WebDriver command request. But for the most part or most of the time, it works.
41 |
42 | WebDriver API/command support and mapping to AutoPy API
43 | -------------------------------------------------------
44 |
45 | See [WebDriver API command support and mapping to AutoPy API](https://github.com/daluu/AutoPyDriverServer/wiki/WebDriver-API-command-support-and-mapping-to-AutoPy-API)
46 |
47 | Contributing
48 | ------------
49 |
50 | Fork the project, make a change, and send a pull request!
51 |
52 | Or as a user, try it out, provide your feedback, submit bugs/enhancement requests.
53 |
--------------------------------------------------------------------------------
/autopydriverserver/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2012 Appium Committers
2 | #
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 |
--------------------------------------------------------------------------------
/autopydriverserver/element_image_map.cfg:
--------------------------------------------------------------------------------
1 | [Element Mapping]
2 | drag_src=/pathTo/drag_src.png
3 | drop_target=C:\\pathTo\\drop_target.png
4 | result=/pathTo/dnd_result.png
--------------------------------------------------------------------------------
/autopydriverserver/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daluu/AutoPyDriverServer/c26bc7a5562da3dd25c905e970318dd0c4bb6a86/autopydriverserver/favicon.ico
--------------------------------------------------------------------------------
/autopydriverserver/server.py:
--------------------------------------------------------------------------------
1 | # Source code is modified from and based off of
2 | # old/original Appium Python implementation at
3 | #
4 | # https://github.com/hugs/appium-old
5 | #
6 | # Licensed to the Apache Software Foundation (ASF) under one
7 | # or more contributor license agreements. See the NOTICE file
8 | # distributed with this work for additional information
9 | # regarding copyright ownership. The ASF licenses this file
10 | # to you under the Apache License, Version 2.0 (the
11 | # "License"); you may not use this file except in compliance
12 | # with the License. You may obtain a copy of the License at
13 | #
14 | # http://www.apache.org/licenses/LICENSE-2.0
15 | #
16 | # Unless required by applicable law or agreed to in writing,
17 | # software distributed under the License is distributed on an
18 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19 | # KIND, either express or implied. See the License for the
20 | # specific language governing permissions and limitations
21 | # under the License.
22 |
23 | from bottle import Bottle, request, response, redirect
24 | from bottle import run, static_file
25 | import ConfigParser
26 | import json
27 | import socket
28 | import sys
29 | import platform
30 | import os
31 | import subprocess
32 | import base64
33 | import urllib
34 | import autopy
35 | from time import time
36 | from time import sleep
37 |
38 | app = Bottle()
39 |
40 | @app.get('/favicon.ico')
41 | def get_favicon():
42 | return static_file('favicon.ico', root='.')
43 |
44 | def get_platform():
45 | if sys.platform == "win32":
46 | if platform.release() == "Vista":
47 | wd_platform = "VISTA"
48 | elif platform.release() == "XP": #?
49 | wd_platform = "XP"
50 | else:
51 | wd_platform = "WINDOWS"
52 | elif sys.platform == "darwin":
53 | wd_platform = "MAC"
54 | else: #sys.platform.startswith('linux'):
55 | wd_platform = "LINUX"
56 | return wd_platform
57 |
58 | @app.route('/wd/hub/status', method='GET')
59 | def status():
60 | wd_platform = get_platform()
61 | status = {'sessionId': app.SESSION_ID if app.started else None,
62 | 'status': 0,
63 | 'value': {'build': {'version': 'AutoPyDriverServer 0.1'},
64 | 'os': {'arch':platform.machine(),'name':wd_platform,'version':platform.release()}}}
65 | return status
66 |
67 | @app.route('/wd/hub/session', method='POST')
68 | def create_session():
69 | #process desired capabilities
70 | request_data = request.body.read()
71 | dc = json.loads(request_data).get('desiredCapabilities')
72 | if dc is not None:
73 | newTolerance = dc.get('imageRecognitionToleranceValue')
74 | if newTolerance is not None:
75 | app.tolerance = newTolerance
76 | newImageFolder = dc.get('defaultImageFolder')
77 | if newImageFolder is not None:
78 | app.image_path = newImageFolder
79 | newConfigFile = dc.get('defaultElementImageMapConfigFile')
80 | if newConfigFile is not None:
81 | app.element_locator_map_file = newConfigFile
82 |
83 | #setup session
84 | app.started = True
85 | redirect('/wd/hub/session/%s' % app.SESSION_ID)
86 |
87 | @app.route('/wd/hub/session/', method='GET')
88 | def get_session(session_id=''):
89 | wd_platform = get_platform()
90 | app_response = {'sessionId': session_id,
91 | 'status': 0,
92 | 'value': {"version":"0.1",
93 | "browserName":"AutoPy",
94 | "platform":wd_platform,
95 | "takesScreenshot":True,
96 | "imageRecognitionToleranceValue":app.tolerance,
97 | "defaultImageFolder":app.image_path,
98 | "defaultElementImageMapConfigFile":app.element_locator_map_file}}
99 | return app_response
100 |
101 | @app.route('/wd/hub/session/', method='DELETE')
102 | def delete_session(session_id=''):
103 | app.started = False
104 | app_response = {'sessionId': session_id,
105 | 'status': 0,
106 | 'value': {}}
107 | return app_response
108 |
109 | @app.route('/wd/hub/session//execute', method='POST')
110 | def execute_script(session_id=''):
111 | result = ''
112 | request_data = request.body.read()
113 | try:
114 | script = json.loads(request_data).get('script')
115 | #args = json.loads(request_data).get('args')
116 | #script_with_args = [script]
117 | #script_with_args.extend(args)
118 | #result = subprocess.check_output(script, stderr=subprocess.STDOUT)
119 | #result = subprocess.check_output(script_with_args, stderr=subprocess.STDOUT)
120 | proc_handle = os.popen(script)
121 | result = proc_handle.read()
122 | proc_handle.close()
123 | except:
124 | response.status = 400
125 | return {'sessionId': session_id, 'status': 13, 'value': str(sys.exc_info()[0])}
126 |
127 | app_response = {'sessionId': session_id,
128 | 'status': 0,
129 | 'value': result}
130 | return app_response
131 |
132 | @app.route('/wd/hub/session//element//click', method='POST')
133 | def element_click(session_id='', element_id=''):
134 | try:
135 | _go_to_element(element_id)
136 | autopy.mouse.click()
137 | except:
138 | response.status = 400
139 | return {'sessionId': session_id, 'status': 13, 'value': str(sys.exc_info()[0])}
140 |
141 | app_response = {'sessionId': session_id,
142 | 'status': 0,
143 | 'value': {}}
144 | return app_response
145 |
146 | @app.route('/wd/hub/session//click', method='POST')
147 | def mouse_click(session_id=''):
148 | request_data = request.body.read()
149 | if request_data == None or request_data == '' or request_data == "{}":
150 | button = 0
151 | else:
152 | button = json.loads(request_data).get('button')
153 | try:
154 | if button == 1:
155 | autopy.mouse.click(autopy.mouse.CENTER_BUTTON)
156 | elif button == 2:
157 | autopy.mouse.click(autopy.mouse.RIGHT_BUTTON)
158 | else: #button 1
159 | autopy.mouse.click()
160 | except:
161 | response.status = 400
162 | return {'sessionId': session_id, 'status': 13, 'value': str(sys.exc_info()[0])}
163 |
164 | app_response = {'sessionId': session_id,
165 | 'status': 0,
166 | 'value': {}}
167 | return app_response
168 |
169 | @app.route('/wd/hub/session//buttonup', method='POST')
170 | def mouse_up(session_id=''):
171 | request_data = request.body.read()
172 | if request_data == None or request_data == '' or request_data == "{}":
173 | button = 0
174 | else:
175 | button = json.loads(request_data).get('button')
176 | try:
177 | if button == 1:
178 | autopy.mouse.toggle(False,autopy.mouse.CENTER_BUTTON)
179 | elif button == 2:
180 | autopy.mouse.toggle(False,autopy.mouse.RIGHT_BUTTON)
181 | else: #button 1
182 | autopy.mouse.toggle(False)
183 | except:
184 | response.status = 400
185 | return {'sessionId': session_id, 'status': 13, 'value': str(sys.exc_info()[0])}
186 |
187 | app_response = {'sessionId': session_id,
188 | 'status': 0,
189 | 'value': {}}
190 | return app_response
191 |
192 | @app.route('/wd/hub/session//buttondown', method='POST')
193 | def mouse_down(session_id=''):
194 | request_data = request.body.read()
195 | if request_data == None or request_data == '' or request_data == "{}":
196 | button = 0
197 | else:
198 | button = json.loads(request_data).get('button')
199 | try:
200 | if button == 1:
201 | autopy.mouse.toggle(True,autopy.mouse.CENTER_BUTTON)
202 | elif button == 2:
203 | autopy.mouse.toggle(True,autopy.mouse.RIGHT_BUTTON)
204 | else: #button 1
205 | autopy.mouse.toggle(True)
206 | except:
207 | response.status = 400
208 | return {'sessionId': session_id, 'status': 13, 'value': str(sys.exc_info()[0])}
209 |
210 | app_response = {'sessionId': session_id,
211 | 'status': 0,
212 | 'value': {}}
213 | return app_response
214 |
215 | @app.route('/wd/hub/session//moveto', method='POST')
216 | def move_to(session_id=''):
217 | request_data = request.body.read()
218 | if request_data == None or request_data == '' or request_data == "{}":
219 | element_id = None
220 | xoffset = None
221 | yoffset = None
222 | else:
223 | element_id = json.loads(request_data).get('element')
224 | xoffset = json.loads(request_data).get('xoffset')
225 | yoffset = json.loads(request_data).get('yoffset')
226 | try:
227 | if element_id == None and (xoffset != None or yoffset != None):
228 | src = autopy.mouse.get_pos()
229 | autopy.mouse.smooth_move(src[0]+xoffset,src[1]+yoffset)
230 | else:
231 | if xoffset != None or yoffset != None:
232 | path = decode_value_from_wire(element_id)
233 | elem = autopy.bitmap.Bitmap.open(path)
234 | pos = autopy.bitmap.capture_screen().find_bitmap(elem,app.tolerance)
235 | autopy.mouse.smooth_move(pos[0]+xoffset,pos[1]+yoffset)
236 | else: # just go to center of element
237 | _go_to_element(element_id)
238 |
239 | except:
240 | response.status = 400
241 | return {'sessionId': session_id, 'status': 13, 'value': str(sys.exc_info()[0])}
242 |
243 | app_response = {'sessionId': session_id,
244 | 'status': 0,
245 | 'value': {}}
246 | return app_response
247 |
248 | @app.route('/wd/hub/session//element//value', method='POST')
249 | def set_value(session_id='', element_id=''):
250 | request_data = request.body.read()
251 | try:
252 | value_to_set = json.loads(request_data).get('value')
253 | value_to_set = ''.join(value_to_set)
254 |
255 | _go_to_element(element_id)
256 | autopy.mouse.click()
257 | autopy.key.type_string(value_to_set)
258 | except:
259 | response.status = 400
260 | return {'sessionId': session_id, 'status': 13, 'value': str(sys.exc_info()[0])}
261 |
262 | app_response = {'sessionId': session_id,
263 | 'status': 0,
264 | 'value': {}}
265 | return app_response
266 |
267 | @app.route('/wd/hub/session//element//elements', method='POST')
268 | def element_find_elements(session_id='', element_id=''):
269 | return _find_element(session_id, element_id, many=True)
270 |
271 | @app.route('/wd/hub/session//elements', method='POST')
272 | def find_elements(session_id=''):
273 | return _find_element(session_id, "root", many=True)
274 |
275 | @app.route('/wd/hub/session//element//element', method='POST')
276 | def element_find_element(session_id='', element_id=''):
277 | return _find_element(session_id, element_id)
278 |
279 | @app.route('/wd/hub/session//element', method='POST')
280 | def find_element(session_id=''):
281 | return _find_element(session_id, "root")
282 |
283 | def _go_to_element(element_id):
284 | path = decode_value_from_wire(element_id)
285 | elem = autopy.bitmap.Bitmap.open(path)
286 | pos = autopy.bitmap.capture_screen().find_bitmap(elem,app.tolerance)
287 |
288 | if autopy.mouse.get_pos() != pos:
289 | autopy.mouse.smooth_move(pos[0]+(elem.width/2),pos[1]+(elem.height/2))
290 |
291 | def _find_element(session_id, context, many=False):
292 | try:
293 | json_request_data = json.loads(request.body.read())
294 | locator_strategy = json_request_data.get('using')
295 | value = json_request_data.get('value')
296 |
297 | if locator_strategy == "id":
298 | path = app.config.get("Element Mapping",value)
299 | elif locator_strategy == "name":
300 | path = os.path.join(app.image_path,value)
301 | elif locator_strategy == "xpath":
302 | path = value
303 | else:
304 | response.status = 501
305 | return {'sessionId': session_id, 'status': 32, 'value': 'Unsupported location strategy, use id, name, or XPath only. See docs for details.'}
306 | elem = autopy.bitmap.Bitmap.open(path)
307 |
308 | if not many:
309 | if context == "root":
310 | pos = autopy.bitmap.capture_screen().find_bitmap(elem,app.tolerance)
311 | else:
312 | canvas = autopy.bitmap.Bitmap.open(decode_value_from_wire(context))
313 | pos = canvas.find_bitmap(elem,app.tolerance)
314 |
315 | if pos is None:
316 | return {'sessionId': session_id, 'status': 7, 'value': 'Element not found'}
317 |
318 | found_elements = {'ELEMENT':encode_value_4_wire(path)}
319 | else:
320 | if context == "root":
321 | if autopy.bitmap.capture_screen().count_of_bitmap(elem,app.tolerance) == 0:
322 | found_elements = []
323 | else:
324 | temp_elements = []
325 | result = autopy.bitmap.capture_screen().find_every_bitmap(elem,app.tolerance)
326 | for pos in result:
327 | temp_elements.append({'ELEMENT':encode_value_4_wire(path)})
328 | found_elements = temp_elements
329 | else:
330 | canvas = autopy.bitmap.Bitmap.open(decode_value_from_wire(context))
331 | if canvas.count_of_bitmap(elem,app.tolerance) == 0:
332 | found_elements = []
333 | else:
334 | temp_elements = []
335 | result = canvas.find_every_bitmap(elem,app.tolerance)
336 | for pos in result:
337 | temp_elements.append({'ELEMENT':encode_value_4_wire(path)})
338 | found_elements = temp_elements
339 |
340 | return {'sessionId': session_id, 'status': 0, 'value': found_elements}
341 | except:
342 | response.status = 400
343 | return {'sessionId': session_id, 'status': 13, 'value': str(sys.exc_info()[0])}
344 |
345 | @app.route('/wd/hub/session//screenshot', method='GET')
346 | def get_screenshot(session_id=''):
347 | try:
348 | path = os.path.join(os.path.dirname(os.tempnam()),'autopydriver_screenshot.png')
349 | autopy.bitmap.capture_screen().save(path)
350 | with open(path, 'rb') as screenshot:
351 | encoded_file = base64.b64encode(screenshot.read())
352 | return {'sessionId': session_id, 'status': 0, 'value': encoded_file}
353 | except:
354 | response.status = 400
355 | return {'sessionId': session_id, 'status': 13, 'value': str(sys.exc_info()[0])}
356 |
357 | @app.route('/wd/hub/session//keys', method='POST')
358 | def keys(session_id=''):
359 | try:
360 | request_data = request.body.read()
361 | wired_keys = json.loads(request_data).get('value')
362 | keys = ''.join(wired_keys)
363 | autopy.key.type_string(keys)
364 | return {'sessionId': session_id, 'status': 0}
365 | except:
366 | response.status = 400
367 | return {'sessionId': session_id, 'status': 13, 'value': str(sys.exc_info()[0])}
368 |
369 | @app.route('/wd/hub/session//element//location', method='GET')
370 | def element_location(session_id='', element_id=''):
371 | try:
372 | path = decode_value_from_wire(element_id)
373 | elem = autopy.bitmap.Bitmap.open(path)
374 | pos = autopy.bitmap.capture_screen().find_bitmap(elem,app.tolerance)
375 | location = {'x': pos[0], 'y': pos[1]}
376 | return {'sessionId': session_id, 'status': 0, 'value': location}
377 | except:
378 | response.status = 400
379 | return {'sessionId': session_id, 'status': 13, 'value': str(sys.exc_info()[0])}
380 |
381 | @app.route('/wd/hub/session//element//size', method='GET')
382 | def element_size(session_id='', element_id=''):
383 | try:
384 | path = decode_value_from_wire(element_id)
385 | elem = autopy.bitmap.Bitmap.open(path)
386 | size = {'width': elem.width, 'height': elem.height}
387 | return {'sessionId': session_id, 'status': 0, 'value': size}
388 | except:
389 | response.status = 400
390 | return {'sessionId': session_id, 'status': 13, 'value': str(sys.exc_info()[0])}
391 |
392 | @app.route('/wd/hub/session//element//displayed', method='GET')
393 | def element_displayed(session_id='', element_id=''):
394 | try:
395 | path = decode_value_from_wire(element_id)
396 | elem = autopy.bitmap.Bitmap.open(path)
397 | pos = autopy.bitmap.capture_screen().find_bitmap(elem,app.tolerance)
398 | displayed = True if pos is not None else False
399 | return {'sessionId': session_id, 'status': 0, 'value': displayed}
400 | except:
401 | response.status = 400
402 | return {'sessionId': session_id, 'status': 13, 'value': str(sys.exc_info()[0])}
403 |
404 | @app.route('/wd/hub/session//file', method='POST')
405 | def upload_file(session_id=''):
406 | try:
407 | request_data = request.body.read()
408 | b64data = json.loads(request_data).get('file')
409 | byteContent = base64.b64decode(b64data)
410 | path = os.tempnam()
411 | with open(path, 'wb') as f:
412 | f.write(byteContent)
413 | extracted_files = unzip(path,os.path.dirname(path))
414 | except:
415 | response.status = 400
416 | return {'sessionId': session_id, 'status': 13, 'value': str(sys.exc_info()[0])}
417 |
418 | # For (remote) file uploads - well currently AutoPyDriverServer will always be "remote"
419 | # we can't formally/technically support multiple file uploads yet, due to Selenium issue 2239
420 | # as the WebDriver/JSONWireProtocol spec doesn't define how to handle request/response
421 | # of multiple files uploaded. Therefore, we assume user upload single file for now
422 | result = "".join(extracted_files)
423 | app_response = {'sessionId': session_id,
424 | 'status': 0,
425 | 'value': result}
426 | return app_response
427 |
428 | def unzip(source_filename, dest_dir):
429 | import zipfile,os.path
430 | files_in_zip = []
431 | with zipfile.ZipFile(source_filename) as zf:
432 | for member in zf.infolist():
433 | words = member.filename.split('/')
434 | path = dest_dir
435 | for word in words[:-1]:
436 | drive, word = os.path.splitdrive(word)
437 | head, word = os.path.split(word)
438 | if word in (os.curdir, os.pardir, ''): continue
439 | path = os.path.join(path, word)
440 | zf.extract(member, path)
441 | unzipped_file = os.path.join(dest_dir,member.filename)
442 | print "Unzipped a file: %s" % unzipped_file
443 | files_in_zip.append(unzipped_file)
444 | return files_in_zip
445 |
446 | @app.error(404)
447 | def unsupported_command(error):
448 | response.content_type = 'text/plain'
449 | return 'Unrecognized command, or AutoPyDriverServer does not support/implement this: %s %s' % (request.method, request.path)
450 |
451 | def encode_value_4_wire(value):
452 | return urllib.pathname2url(base64.b64encode(value))
453 |
454 | def decode_value_from_wire(value):
455 | return base64.b64decode(urllib.url2pathname(value))
456 |
457 | if __name__ == '__main__':
458 | import argparse
459 |
460 | parser = argparse.ArgumentParser(description='AutoPyDriverServer - a webdriver-compatible server for use with desktop GUI automation via AutoPy library/tool.')
461 | #parser.add_argument('-v', dest='verbose', action="store_true", default=False, help='verbose mode')
462 | parser.add_argument('-a', '--address', type=str, default=None, help='ip address to listen on')
463 | parser.add_argument('-p', '--port', type=int, default=4723, help='port to listen on')
464 | parser.add_argument('-t', '--tolerance', type=float, default=0.0, help='define tolerance value for finding elements via images/bitmaps, see docs for details')
465 | parser.add_argument('-f', '--images_folder', type=str, default=None, help='define image folder containing element locator images for find by name, defaults to image subfolder within the app/server directory')
466 | parser.add_argument('-c', '--element_image_mapping_file', type=str, default=None, help='define the element image mapping config file for find by ID, see default sample config file in the app/server directory')
467 |
468 | args = parser.parse_args()
469 |
470 | if args.address is None:
471 | try:
472 | args.address = socket.gethostbyname(socket.gethostname())
473 | except:
474 | args.address = '127.0.0.1'
475 |
476 | if args.element_image_mapping_file is not None:
477 | app.element_locator_map_file = args.element_image_mapping_file
478 | else:
479 | app.element_locator_map_file = os.path.join(os.path.curdir,'element_image_map.cfg')
480 | if args.images_folder is not None:
481 | app.image_path = args.images_folder
482 | else:
483 | app.image_path = os.path.join(os.path.curdir,'images')
484 | app.tolerance = args.tolerance
485 |
486 | app.config = ConfigParser.RawConfigParser()
487 | app.config.read(app.element_locator_map_file)
488 |
489 | app.SESSION_ID = "%s:%d" % (args.address, args.port)
490 | app.started = False
491 | run(app, host=args.address, port=args.port)
492 |
--------------------------------------------------------------------------------
/linux_mac_requirements.txt:
--------------------------------------------------------------------------------
1 | bottle>=0.10.11
2 | autopy>=0.51
--------------------------------------------------------------------------------
/sample-code/calculator_demo.py:
--------------------------------------------------------------------------------
1 | from selenium import webdriver
2 | from os import path
3 |
4 | # NOTE 1: this demo uses images under images subfolder to find by name.
5 | # Be sure to configure AutoPyDriverServer to use that folder for images by name
6 |
7 | # NOTE 2: this demo targets the Calculator in Windows 7. But if calculator visually
8 | # differs in other versions of Windows, and for Mac, Linux, the demo will still work
9 | # if you replace the images with the equivalents for the other platforms
10 |
11 | driver = webdriver.Remote( command_executor='http://127.0.0.1:4723/wd/hub', desired_capabilities={'browserName':'AutoPy','imageRecognitionToleranceValue':0.0})
12 | print "Desired Capabilities returned by server:\n"
13 | print driver.desired_capabilities
14 | print ""
15 |
16 | # Example opening the "Calculator" app for Windows:
17 | #driver.execute_script("start calc")
18 | # except that it hangs the script until you close calculator
19 | # maybe different on Linux/Mac if you launch as background process but not sure. Try at your own risk.
20 |
21 | # so, we assume calculator open with focus and can start testing at this point
22 | # AutoPy has no APIs for handling windows
23 |
24 | driver.find_element_by_name('calc_1_btn.png').click()
25 | driver.find_element_by_name('calc_plus_btn.png').click()
26 | driver.find_element_by_name('calc_2_btn.png').click()
27 | equals_btn = driver.find_element_by_name('calc_equals_btn.png')
28 | equals_btn.click()
29 | size = equals_btn.size
30 | loc = equals_btn.location
31 |
32 | print "Equals button is %d x %d pixels in size" % (size['width'],size['height'])
33 | print "Equals button is located approximately at (%d,%d) on (main) desktop screen" % (loc['x'],loc['y'])
34 |
35 | print "# elements found when try find_elements for an element that can't seem to find: %d" % len(driver.find_elements_by_name('calc_3_result.png'))
36 |
37 | # AutoPy may fail below due to problems trying to find the results text field
38 | # may need to tweak AutoPy tolerance values
39 | #if driver.find_element_by_name('calc_3_result.png').is_displayed():
40 | # print 'Calculated correctly that 1 + 2 = 3\n'
41 | #else:
42 | # screenshot = path.join(path.curdir,'failed_calculation.png')
43 | # driver.get_screenshot_as_file(screenshot)
44 | # print 'Calculation of 1 + 2 is incorrect. See screenshot for actual result: %s.\n' % screenshot
45 |
46 | screenshot = path.join(path.curdir,'screenshot_demo.png')
47 | driver.get_screenshot_as_file(screenshot)
48 | print 'See screenshot demo: %s.\n' % screenshot
49 |
50 | driver.quit()
--------------------------------------------------------------------------------
/sample-code/images/calc_1_btn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daluu/AutoPyDriverServer/c26bc7a5562da3dd25c905e970318dd0c4bb6a86/sample-code/images/calc_1_btn.png
--------------------------------------------------------------------------------
/sample-code/images/calc_2_btn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daluu/AutoPyDriverServer/c26bc7a5562da3dd25c905e970318dd0c4bb6a86/sample-code/images/calc_2_btn.png
--------------------------------------------------------------------------------
/sample-code/images/calc_3_result - Copy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daluu/AutoPyDriverServer/c26bc7a5562da3dd25c905e970318dd0c4bb6a86/sample-code/images/calc_3_result - Copy.png
--------------------------------------------------------------------------------
/sample-code/images/calc_3_result.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daluu/AutoPyDriverServer/c26bc7a5562da3dd25c905e970318dd0c4bb6a86/sample-code/images/calc_3_result.png
--------------------------------------------------------------------------------
/sample-code/images/calc_equals_btn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daluu/AutoPyDriverServer/c26bc7a5562da3dd25c905e970318dd0c4bb6a86/sample-code/images/calc_equals_btn.png
--------------------------------------------------------------------------------
/sample-code/images/calc_plus_btn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daluu/AutoPyDriverServer/c26bc7a5562da3dd25c905e970318dd0c4bb6a86/sample-code/images/calc_plus_btn.png
--------------------------------------------------------------------------------
/sample-code/images/calc_val_field.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daluu/AutoPyDriverServer/c26bc7a5562da3dd25c905e970318dd0c4bb6a86/sample-code/images/calc_val_field.png
--------------------------------------------------------------------------------
/sample-code/images/dnd_result.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daluu/AutoPyDriverServer/c26bc7a5562da3dd25c905e970318dd0c4bb6a86/sample-code/images/dnd_result.png
--------------------------------------------------------------------------------
/sample-code/images/dnd_result2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daluu/AutoPyDriverServer/c26bc7a5562da3dd25c905e970318dd0c4bb6a86/sample-code/images/dnd_result2.png
--------------------------------------------------------------------------------
/sample-code/images/drag_src.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daluu/AutoPyDriverServer/c26bc7a5562da3dd25c905e970318dd0c4bb6a86/sample-code/images/drag_src.png
--------------------------------------------------------------------------------
/sample-code/images/drag_src_html5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daluu/AutoPyDriverServer/c26bc7a5562da3dd25c905e970318dd0c4bb6a86/sample-code/images/drag_src_html5.png
--------------------------------------------------------------------------------
/sample-code/images/drop_target.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daluu/AutoPyDriverServer/c26bc7a5562da3dd25c905e970318dd0c4bb6a86/sample-code/images/drop_target.png
--------------------------------------------------------------------------------
/sample-code/images/drop_target_html5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daluu/AutoPyDriverServer/c26bc7a5562da3dd25c905e970318dd0c4bb6a86/sample-code/images/drop_target_html5.png
--------------------------------------------------------------------------------
/sample-code/web_drag_and_drop_demo.py:
--------------------------------------------------------------------------------
1 | from selenium import webdriver
2 | from selenium.webdriver import ActionChains
3 | from os import path
4 |
5 | #NOTE: this demo uses images under images subfolder to find by name.
6 | # Be sure to configure AutoPyDriverServer to use that folder for images by name
7 |
8 | driver = webdriver.Remote( command_executor='http://127.0.0.1:4723/wd/hub', desired_capabilities={'browserName':'AutoPy','imageRecognitionToleranceValue':0.0})
9 | print "Desired Capabilities returned by server:\n"
10 | print driver.desired_capabilities
11 | print ""
12 |
13 | # Example opening the test drag & drop webpage for Windows:
14 | #driver.execute_script("start http://html5demos.com/drag")
15 | # or
16 | #driver.execute_script("start http://jqueryui.com/resources/demos/droppable/default.html")
17 | # except that it hangs the script until you close calculator
18 | # maybe different on Linux/Mac if you launch as background process but not sure. Try at your own risk.
19 |
20 | # so, we assume the test webpage is open, in default state, & w/ focus so can start testing at this point
21 | # AutoPy has no APIs for handling windows
22 |
23 | # example for http://html5demos.com/drag
24 | src = driver.find_element_by_name('drag_src_html5.png')
25 | target = driver.find_element_by_name('drop_target_html5.png')
26 | actions = ActionChains(driver)
27 | actions.drag_and_drop(src,target).perform()
28 |
29 | # or http://jqueryui.com/resources/demos/droppable/default.html
30 | #src = driver.find_element_by_name('drag_src.png')
31 | #target = driver.find_element_by_name('drop_target.png')
32 | #actions = ActionChains(driver)
33 | #actions.drag_and_drop(src,target).perform()
34 |
35 | # result check for http://html5demos.com/drag
36 | if len(driver.find_elements_by_name('drag_src_html5.png')) == 0: # as drag src disappeared into drop target
37 | # or http://jqueryui.com/resources/demos/droppable/default.html
38 | #if driver.find_element_by_name('dnd_result.png').is_displayed():
39 | print 'Drag & drop succeeded.\n'
40 | else:
41 | screenshot = path.join(path.curdir,'failed_drag_and_drop.png')
42 | driver.get_screenshot_as_file(screenshot)
43 | print 'Drag & drop failed. See screenshot for actual result: %s.\n' % screenshot
44 |
45 | # AutoPy may fail below due to problems trying to find the drag & drop result,
46 | # may need to tweak AutoPy tolerance values. Also actual drag & drop operation
47 | # may not be perfect in placement location each time, so actual result may not
48 | # match the saved result image
49 |
50 | driver.quit()
--------------------------------------------------------------------------------
/sample-code/webdriver_integration_demo.py:
--------------------------------------------------------------------------------
1 | from selenium import webdriver
2 | from selenium.webdriver import ActionChains
3 | from os import path
4 | import time
5 |
6 | #NOTE: this demo uses images under images subfolder to find by name.
7 | # Be sure to configure AutoPyDriverServer to use that folder for images by name
8 |
9 | # start up both Firefox & AutoPyDriver for demo
10 | browser = webdriver.Firefox()
11 | autopy_driver = webdriver.Remote( command_executor='http://127.0.0.1:4723/wd/hub', desired_capabilities={'browserName':'AutoPy','imageRecognitionToleranceValue':0.0})
12 | print "Desired Capabilities returned by server:\n"
13 | print autopy_driver.desired_capabilities
14 | print ""
15 |
16 | # launch browser to Drag & drop page for demo test
17 | browser.get("http://html5demos.com/drag")
18 |
19 | if len(browser.find_elements_by_tag_name("li")) != 5:
20 | print "Drag & drop test page not in correct state for demo test"
21 |
22 | time.sleep(5)
23 |
24 | src = autopy_driver.find_element_by_name('drag_src_html5.png')
25 | target = autopy_driver.find_element_by_name('drop_target_html5.png')
26 | actions = ActionChains(autopy_driver)
27 | actions.drag_and_drop(src,target).perform()
28 |
29 | # check results, drag & drop reduced items by 1 from 5 to 4
30 | result = len(browser.find_elements_by_tag_name('li'))
31 | if result != 4:
32 | print 'Drag & drop failed. There are %d items when there should be 4.\n' % result
33 | else:
34 | print 'Drag & drop success.\n'
35 |
36 | browser.quit()
37 | autopy_driver.quit()
38 |
39 | # Now imagine from this integration demo, you could use AutoPy with browser via
40 | # WebDriver to do stuff like file download, HTTP authentication and other stuff
41 | # like drag item from desktop into browser, that you could not do w/ WebDriver
42 | # alone, or w/ executing shell commands and other external stuff. Now can do all
43 | # with WebDriver APIs against 2+ WebDriver instances.
--------------------------------------------------------------------------------
/windows_requirements.txt:
--------------------------------------------------------------------------------
1 | bottle>=0.10.11
--------------------------------------------------------------------------------