calabash-android 0.5.16.pre1 → 0.6.0.pre4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/calabash-android-build.rb +2 -1
- data/irbrc +17 -0
- data/lib/calabash-android/dot_dir.rb +17 -0
- data/lib/calabash-android/environment.rb +120 -0
- data/{test-server → lib/calabash-android/lib}/AndroidManifest.xml +0 -0
- data/lib/calabash-android/lib/TestServer.apk +0 -0
- data/lib/calabash-android/logging.rb +120 -0
- data/lib/calabash-android/operations.rb +12 -0
- data/lib/calabash-android/store/preferences.rb +211 -0
- data/lib/calabash-android/text_helpers.rb +41 -14
- data/lib/calabash-android/usage_tracker.rb +192 -0
- data/lib/calabash-android/version.rb +1 -1
- data/lib/calabash-android/wait_helpers.rb +1 -1
- data/lib/calabash-android.rb +6 -1
- metadata +168 -61
- data/.calabash_settings +0 -1
- data/.yardopts +0 -3
- data/CHANGES.txt +0 -354
- data/ENVIRONMENT_VARIABLES.md +0 -106
- data/Gemfile +0 -4
- data/README_YARDOC.md +0 -163
- data/Rakefile +0 -49
- data/calabash-android.gemspec +0 -30
- data/lib/calabash-android/canned_steps.md +0 -229
- data/test-server/build.xml +0 -152
- data/test-server/calabash-js/src/calabash.js +0 -172
@@ -1,229 +0,0 @@
|
|
1
|
-
Canned steps
|
2
|
-
============
|
3
|
-
Calabash Android comes with the following set of predefined steps.
|
4
|
-
You can add your own steps or change the ones you see here.
|
5
|
-
|
6
|
-
Assertion steps
|
7
|
-
---------------
|
8
|
-
|
9
|
-
To assert that specified text can be found use any of the following steps.
|
10
|
-
|
11
|
-
Then /^I see the text "([^\"]*)"$/
|
12
|
-
Then /^I see "([^\"]*)"$/
|
13
|
-
Then /^I should see "([^\"]*)"$/
|
14
|
-
Then /^I should see text containing "([^\"]*)"$/
|
15
|
-
|
16
|
-
To assert that specified text cannot be found use any of the following steps.
|
17
|
-
|
18
|
-
Then /^I should not see "([^\"]*)"$/
|
19
|
-
Then /^I don't see the text "([^\"]*)"$/
|
20
|
-
Then /^I don't see "([^\"]*)"$/
|
21
|
-
|
22
|
-
|
23
|
-
Input steps
|
24
|
-
-----------
|
25
|
-
|
26
|
-
Then /^I toggle checkbox number (\d+)$/ do |index|
|
27
|
-
Toggles the checkout with the specified index.
|
28
|
-
|
29
|
-
Then /^I long press "([^\"]*)"$/ do |text|
|
30
|
-
Long presses the view containing the specified text.
|
31
|
-
|
32
|
-
Then /^I long press "([^\"]*)" and select item number (\d+)$/ do |text, index|
|
33
|
-
**This predefined step is deprecated**
|
34
|
-
|
35
|
-
Long presses the view containing the specified text and selects the menu item with the specified index in the context menu that appears.
|
36
|
-
|
37
|
-
Then /^I long press "([^\"]*)" and select "([^\"]*)"$/ do |text, identifier|
|
38
|
-
**This predefined step is deprecated**
|
39
|
-
|
40
|
-
Long presses the view containing the specified text and selects the menu item marked by the specified identifier in the context menu that appears.
|
41
|
-
|
42
|
-
|
43
|
-
Given /^I set the date to "(\d\d-\d\d-\d\d\d\d)" on DatePicker with index "([^\"]*)"$/ do |date, index|
|
44
|
-
Finds the datepicker with the specified index and changes the date.
|
45
|
-
|
46
|
-
|
47
|
-
Given /^I set the time to "(\d\d:\d\d)" on TimePicker with index "([^\"]*)"$/
|
48
|
-
Given /^I set the "([^\"]*)" time to "(\d\d:\d\d)"$/
|
49
|
-
Finds the timepicker with the specified index and changes the time.
|
50
|
-
|
51
|
-
Given /^I set the "([^\"]*)" date to "(\d\d-\d\d-\d\d\d\d)"$/ do |content_description, date|
|
52
|
-
Finds the datepicker by content description and changes the date.
|
53
|
-
|
54
|
-
Then /^I enter "([^\"]*)" into input field number (\d+)$/ do |text, index|
|
55
|
-
Enters the specified text into the input field with the specified index.
|
56
|
-
|
57
|
-
Then /^I enter text "([^\"]*)" into field with id "([^\"]*)"$/ do |text, id|
|
58
|
-
Enters the specified text into the input field with the specified id.
|
59
|
-
|
60
|
-
Then /^I enter "([^\"]*)" as "([^\"]*)"$/ do |text, content_description|
|
61
|
-
Then /^I enter "([^\"]*)" into "([^\"]*)"$/ do |text, content_description|
|
62
|
-
Enters the specified text into the input field that has the specified content description.
|
63
|
-
|
64
|
-
Then /^I clear input field number (\d+)$/ do |index|
|
65
|
-
Clears the text of the input field with the specified index.
|
66
|
-
|
67
|
-
Then /^I clear "([^\"]*)"$/ do |identifier|
|
68
|
-
Clears the text of input fields marked by the identifier.
|
69
|
-
|
70
|
-
Then /^I clear input field with id "([^\"]*)"$/ do |id|
|
71
|
-
Clears the text of the input field with the specified id.
|
72
|
-
|
73
|
-
Then /^I select "([^\"]*)" from "([^\"]*)"$/ do |item_identifier, spinner_identifier|
|
74
|
-
Finds the spinner marked by the specified 'spinner_identifier' or has a childview marked by the specified 'spinner_identifier'. It then selects the menu item marked by the specified 'item_identifier'.
|
75
|
-
|
76
|
-
Buttons
|
77
|
-
-------
|
78
|
-
|
79
|
-
Then /^I go back$/
|
80
|
-
Simulates that the user pressed the back button.
|
81
|
-
|
82
|
-
Then /^I press the menu key$/
|
83
|
-
Simulates that the user pressed the menu button.
|
84
|
-
|
85
|
-
Then /^I press the enter button$/
|
86
|
-
Simulates that the user pressed the enter button on the keyboard.
|
87
|
-
|
88
|
-
Gestures
|
89
|
-
--------
|
90
|
-
Then /^I swipe left$/
|
91
|
-
Swipes left.
|
92
|
-
|
93
|
-
Then /^I swipe right$/
|
94
|
-
Swipes right.
|
95
|
-
|
96
|
-
Then /^I scroll down$/
|
97
|
-
Scrolls down.
|
98
|
-
|
99
|
-
Then /^I scroll up$/
|
100
|
-
Scrolls up.
|
101
|
-
|
102
|
-
Then /^I select "([^\"]*)" from the menu$/ do |identifier|
|
103
|
-
Opens the menu by simulating pressing the menu button and then selects a menu item marked by the specified identifier.
|
104
|
-
|
105
|
-
|
106
|
-
Then /^I drag from (\d+):(\d+) to (\d+):(\d+) moving with (\d+) steps$/ do |from_x, from_y, to_x, to_y, steps|
|
107
|
-
Drags from one point on the screen to another.
|
108
|
-
|
109
|
-
**Note: x:y co-ordinates are expressed as percentages of the screen width:height**
|
110
|
-
|
111
|
-
Touching
|
112
|
-
--------
|
113
|
-
|
114
|
-
Given /^I press the "([^\"]*)" button$/ do |text|
|
115
|
-
Taps the button containing the specified text.
|
116
|
-
|
117
|
-
Then /^I press button number (\d+)$/ do |index|
|
118
|
-
Taps the button with the specified index.
|
119
|
-
|
120
|
-
Then /^I press image button number (\d+)$/ do |index|
|
121
|
-
Taps the image button with the specified index.
|
122
|
-
|
123
|
-
Then /^I press view with id "([^\"]*)"$/ do |id|
|
124
|
-
Taps the view with the give id.
|
125
|
-
|
126
|
-
Then /^I press "([^\"]*)"$/ do |identifier|
|
127
|
-
Taps the view marked by the specified identifier.
|
128
|
-
|
129
|
-
Then /^I touch the "([^\"]*)" text$/ do |text|
|
130
|
-
Taps the specified text.
|
131
|
-
|
132
|
-
Then /^I press list item number (\d+)$/ do |index|
|
133
|
-
**This predefined step is deprecated**
|
134
|
-
|
135
|
-
Taps the list item with the specified index in the first visible list.
|
136
|
-
|
137
|
-
Then /^I long press list item number (\d+)$/ do |index|
|
138
|
-
**This predefined step is deprecated**
|
139
|
-
|
140
|
-
Long presses the list item with the specified index in the first visible list.
|
141
|
-
|
142
|
-
Then /^I click on screen (\d+)% from the left and (\d+)% from the top$/ do |x, y|
|
143
|
-
Taps the screen at the specified location.
|
144
|
-
|
145
|
-
Waiting
|
146
|
-
-------
|
147
|
-
|
148
|
-
Then /^I wait for progress$/ do
|
149
|
-
Will wait until there are no more progress bars.
|
150
|
-
|
151
|
-
Then /^I wait for "([^\"]*)" to appear$/ do |text|
|
152
|
-
Then /^I wait to see "([^\"]*)"$/ do |text|
|
153
|
-
Waits for the specified text to appear.
|
154
|
-
|
155
|
-
Then /^I wait up to (\d+) seconds for "([^\"]*)" to appear$/ do |timeout, text|
|
156
|
-
Then /^I wait up to (\d+) seconds to see "([^\"]*)"$/ do |timeout, †ext|
|
157
|
-
Waits for the specified text to appear, with a custom timeout
|
158
|
-
|
159
|
-
Then /^I wait for the "([^\"]*)" button to appear$/ do |identifier|
|
160
|
-
Waits for a button marked by the specified identifier to appear.
|
161
|
-
|
162
|
-
Then /^I wait for the "([^\"]*)" screen to appear$/ do |activity_name|
|
163
|
-
Waits for a particular screen (Android Activity) to appear.
|
164
|
-
|
165
|
-
Then /^I wait for the view with id "([^\"]*)" to appear$/ do |id|
|
166
|
-
Waits for a view with the specified if to appear.
|
167
|
-
|
168
|
-
Then /^I wait up to (\d+) seconds for the "([^\"]*)" screen to appear$/ do |timeout, activity_name|
|
169
|
-
Then /^I wait upto (\d+) seconds for the "([^\"]*)" screen to appear$/ do |timeout, activity_name|
|
170
|
-
Waits for a particular screen (Android Activity) to appear with a timeout.
|
171
|
-
|
172
|
-
Then /^I wait for 1 second$/
|
173
|
-
Then /^I wait for a second$/
|
174
|
-
Waits for one second.
|
175
|
-
|
176
|
-
Then /^I wait$/
|
177
|
-
Waits for two seconds.
|
178
|
-
|
179
|
-
Then /^I wait for (\d+) seconds$/ do |seconds|
|
180
|
-
Waits for a specified number of seconds.
|
181
|
-
|
182
|
-
Screenshots
|
183
|
-
-----------
|
184
|
-
To take a screenshot of the phone while running the test use any of these steps.
|
185
|
-
|
186
|
-
Then /^take picture$/
|
187
|
-
Then /^I take a picture$/
|
188
|
-
Then /^I take a screenshot$/
|
189
|
-
|
190
|
-
|
191
|
-
Location steps
|
192
|
-
--------------
|
193
|
-
If you allow your phone to use mocked locations (configured on your device under development settings) and your app has the `ACCESS_MOCK_LOCATION` permission you can change the perceived location of the device by using any of these steps.
|
194
|
-
|
195
|
-
|
196
|
-
You can change the location any address or named location. This is done using the [geocoder gem](http://www.rubygeocoder.com/).
|
197
|
-
|
198
|
-
|
199
|
-
Then /^I am in "([^\"]*)"$/ do |location|
|
200
|
-
Then /^I am at "([^\"]*)"$/ do |location|
|
201
|
-
Then /^I go to "([^\"]*)"$/ do |location|
|
202
|
-
|
203
|
-
To use a set of concrete GPS cordinates
|
204
|
-
|
205
|
-
Then /^I am at ([-+]?[0-9]*\.?[0-9]+), ([-+]?[0-9]*\.?[0-9]+)$/ do |latitude, longitude|
|
206
|
-
Then /^I go to ([-+]?[0-9]*\.?[0-9]+), ([-+]?[0-9]*\.?[0-9]+)$/ do |latitude, longitude|
|
207
|
-
|
208
|
-
Internationalization
|
209
|
-
--------------------
|
210
|
-
|
211
|
-
Then /^I press text of translated l10nkey "?([^\"]*)"?$/
|
212
|
-
Simulates that the user pressed the text of the l10nkey.
|
213
|
-
|
214
|
-
Then /^I press button of translated l10nkey "?([^\"]*)"?$/
|
215
|
-
Simulates that the user pressed the button with the label text of the l10nkey.
|
216
|
-
|
217
|
-
Then /^I press menu item of translated l10nkey "?([^\"]*)"?$/
|
218
|
-
Simulates that the user pressed the menu item with the label text of the l10nkey.
|
219
|
-
|
220
|
-
Then /^I press toggle button of translated l10nkey "?([^\"]*)?"$/
|
221
|
-
Simulates that the user pressed the toggle button with the label text of the l10nkey.
|
222
|
-
|
223
|
-
Then /^I wait for the translated "?([^\"]*)"? l10nkey to appear$/
|
224
|
-
Waits until the text of the translated l10nkey is displayed.
|
225
|
-
|
226
|
-
Note: you can assert or press interface elements using [Android's String resources](http://developer.android.com/reference/android/R.string.html) by passing a package in a custom step:
|
227
|
-
|
228
|
-
perform_action('press_l10n_element', 'ok', nil, 'android')
|
229
|
-
|
data/test-server/build.xml
DELETED
@@ -1,152 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="utf-8"?>
|
2
|
-
<project name="" default="package" basedir=".">
|
3
|
-
<description>
|
4
|
-
Bits and pieces plucked out of $ANDROID_HOME/tools/ant/build.xml
|
5
|
-
</description>
|
6
|
-
|
7
|
-
<property name="adb.device.arg" value="" />
|
8
|
-
<property environment="env"/>
|
9
|
-
<property name="staging.dir" location="staging"/>
|
10
|
-
<property name="bin.dir" location="bin"/>
|
11
|
-
<property name="test.app.aapt" location="${bin.dir}/Test_aapt.apk"/>
|
12
|
-
<property name="dex.file" location="${bin.dir}/classes.dex"/>
|
13
|
-
<property name="test.app.unsigned" location="${bin.dir}/Test_unsigned.apk"/>
|
14
|
-
<property name="calabashjs.dir" location="calabash-js/src"/>
|
15
|
-
|
16
|
-
<!-- Windows support -->
|
17
|
-
<condition property="bat" value=".bat" else=""><os family="windows" /></condition>
|
18
|
-
|
19
|
-
<property name="dx" location="${tools.dir}/dx${bat}" />
|
20
|
-
<property name="aapt" location="${tools.dir}/aapt" />
|
21
|
-
|
22
|
-
<property name="android.lib" location="${env.ANDROID_HOME}/platforms/android-${android.api.level}/android.jar"/>
|
23
|
-
<path id="android.antlibs">
|
24
|
-
<pathelement path="${env.ANDROID_HOME}/tools/lib/ant-tasks.jar" />
|
25
|
-
<pathelement path="${env.ANDROID_HOME}/tools/lib/anttasks.jar" />
|
26
|
-
<pathelement path="${env.ANDROID_HOME}/tools/lib/sdklib.jar" />
|
27
|
-
<pathelement path="${env.ANDROID_HOME}/tools/lib/androidprefs.jar" />
|
28
|
-
</path>
|
29
|
-
|
30
|
-
<path id="jar.libs.ref">
|
31
|
-
<fileset dir="${staging.dir}/libs/" includes="*.jar" />
|
32
|
-
</path>
|
33
|
-
|
34
|
-
<path id="cucumber.path">
|
35
|
-
<fileset dir="cucumber/" includes="*.jar" />
|
36
|
-
</path>
|
37
|
-
|
38
|
-
<path id="android.target.classpath">
|
39
|
-
<fileset dir="${env.ANDROID_HOME}/platforms/android-${android.api.level}/" includes="*.jar"/>
|
40
|
-
</path>
|
41
|
-
|
42
|
-
<target name="-check.preconditions">
|
43
|
-
<available file="${calabashjs.dir}" type="dir" property="doesCalabashJsExist" />
|
44
|
-
<fail unless="doesCalabashJsExist">
|
45
|
-
${calabashjs.dir} does not exist.
|
46
|
-
</fail>
|
47
|
-
<antversion property="version.running" />
|
48
|
-
<fail message="FATAL ERROR: The running Ant version, ${version.running}, is too old.">
|
49
|
-
<condition>
|
50
|
-
<not>
|
51
|
-
<antversion atleast="1.8" />
|
52
|
-
</not>
|
53
|
-
</condition>
|
54
|
-
</fail>
|
55
|
-
</target>
|
56
|
-
|
57
|
-
<target name="-stage">
|
58
|
-
<mkdir dir="${staging.dir}"/>
|
59
|
-
<mkdir dir="${bin.dir}"/>
|
60
|
-
<antcall target="-prepare.testserver"/>
|
61
|
-
</target>
|
62
|
-
|
63
|
-
<target name="-prepare.testserver" description="Makes sure the testserver matches the tested application by looking at its manifest file">
|
64
|
-
<copy todir="${staging.dir}">
|
65
|
-
<fileset dir="instrumentation-backend" />
|
66
|
-
</copy>
|
67
|
-
<copy todir="${staging.dir}/libs">
|
68
|
-
<fileset erroronmissingdir="false" dir="${env.ANDROID_HOME}/add-ons/addon-google_apis-google_inc_-${android.api.level}/libs"/>
|
69
|
-
<fileset erroronmissingdir="false" dir="${env.ANDROID_HOME}/add-ons/addon-google_apis-google-${android.api.level}/libs"/>
|
70
|
-
</copy>
|
71
|
-
<copy todir="${staging.dir}/assets">
|
72
|
-
<fileset dir="${calabashjs.dir}"/>
|
73
|
-
</copy>
|
74
|
-
<replace file="${staging.dir}/src/sh/calaba/instrumentationbackend/actions/version/Version.java" token="####VERSION####" value="${version}" failOnNoReplacements="true" />
|
75
|
-
|
76
|
-
<property name="src.dir.absolute" location="${staging.dir}/src" />
|
77
|
-
<pathconvert property="testserver.actions" pathsep="${line.separator}" dirsep=".">
|
78
|
-
<fileset dir="${src.dir.absolute}" includes="sh/calaba/instrumentationbackend/actions/**/*.java" />
|
79
|
-
<globmapper from="${src.dir.absolute}/*.java" to="*" handledirsep="true" />
|
80
|
-
</pathconvert>
|
81
|
-
<echo file="${staging.dir}/assets/actions" message="${testserver.actions}${line.separator}" />
|
82
|
-
</target>
|
83
|
-
|
84
|
-
|
85
|
-
<target name="-compile">
|
86
|
-
<antcall target="-stage" />
|
87
|
-
<javac
|
88
|
-
srcdir="${staging.dir}/src"
|
89
|
-
destdir="${bin.dir}"
|
90
|
-
verbose="${verbose}"
|
91
|
-
source="1.6"
|
92
|
-
target="1.6"
|
93
|
-
debug="true"
|
94
|
-
includeantruntime="false"
|
95
|
-
bootclasspathref="android.target.classpath"
|
96
|
-
classpath="${extensible.classpath}"
|
97
|
-
classpathref="jar.libs.ref" />
|
98
|
-
</target>
|
99
|
-
|
100
|
-
|
101
|
-
<target name="package" depends="-check.preconditions">
|
102
|
-
<antcall target="-compile" />
|
103
|
-
<antcall target="-aapt" />
|
104
|
-
<antcall target="-dex" />
|
105
|
-
<antcall target="-apk" />
|
106
|
-
</target>
|
107
|
-
|
108
|
-
|
109
|
-
<target name="clean" description="clean up">
|
110
|
-
<delete dir="${staging.dir}"/>
|
111
|
-
<delete dir="${bin.dir}"/>
|
112
|
-
</target>
|
113
|
-
|
114
|
-
<target name="-aapt">
|
115
|
-
<exec executable="${aapt}" failonerror="yes">
|
116
|
-
<arg value="package" />
|
117
|
-
<arg value="-f" />
|
118
|
-
<arg value="-F" />
|
119
|
-
<arg file="${test.app.aapt}" />
|
120
|
-
<arg value="-I" />
|
121
|
-
<arg path="${android.lib}" />
|
122
|
-
<arg value="-A" />
|
123
|
-
<arg path="${staging.dir}/assets" />
|
124
|
-
<arg value="-m" />
|
125
|
-
<arg value="-J" />
|
126
|
-
<arg path="gen" />
|
127
|
-
</exec>
|
128
|
-
</target>
|
129
|
-
|
130
|
-
<target name="-dex">
|
131
|
-
<copy todir="${bin.dir}/libs">
|
132
|
-
<fileset dir="instrumentation-backend/libs"/>
|
133
|
-
</copy>
|
134
|
-
<exec executable="${dx}" failonerror="yes">
|
135
|
-
<arg value="--dex" />
|
136
|
-
<arg value="--output" />
|
137
|
-
<arg file="${dex.file}" />
|
138
|
-
<arg path="${bin.dir}" />
|
139
|
-
</exec>
|
140
|
-
</target>
|
141
|
-
|
142
|
-
<target name="-apk">
|
143
|
-
<exec executable="java" failonerror="yes">
|
144
|
-
<arg value="-jar" />
|
145
|
-
<arg value="${staging.dir}/CalabashApkBuilder.jar" />
|
146
|
-
<arg file="${test.app.unsigned}" />
|
147
|
-
<arg file="${test.app.aapt}" />
|
148
|
-
<arg file="${dex.file}" />
|
149
|
-
</exec>
|
150
|
-
</target>
|
151
|
-
|
152
|
-
</project>
|
@@ -1,172 +0,0 @@
|
|
1
|
-
(function () {
|
2
|
-
/** David Mark's isHostMethod function,
|
3
|
-
* http://peter.michaux.ca/articles/feature-detection-state-of-the-art-browser-scripting
|
4
|
-
* Modified to use strict equality
|
5
|
-
*/
|
6
|
-
function isHostMethod (object, property)
|
7
|
-
{
|
8
|
-
var t = typeof object[property];
|
9
|
-
return t==='function' ||
|
10
|
-
(!!(t==='object' && object[property])) ||
|
11
|
-
t==='unknown';
|
12
|
-
}
|
13
|
-
/*http://www.w3.org/TR/DOM-Level-2-Core/core.html*/
|
14
|
-
var NODE_TYPES = {
|
15
|
-
/*ELEMENT_NODE : */ 1 : 'ELEMENT_NODE',
|
16
|
-
/*ATTRIBUTE_NODE : */ 2: 'ATTRIBUTE_NODE',
|
17
|
-
/*TEXT_NODE : */ 3 : 'TEXT_NODE',
|
18
|
-
/*DOCUMENT_NODE : */ 9 : 'DOCUMENT_NODE'
|
19
|
-
};
|
20
|
-
|
21
|
-
function computeRectForNode(object)
|
22
|
-
{
|
23
|
-
var res = {}, boundingBox;
|
24
|
-
if (isHostMethod(object,'getBoundingClientRect'))
|
25
|
-
{
|
26
|
-
boundingBox = object.getBoundingClientRect();
|
27
|
-
var rect = {};
|
28
|
-
rect.width = boundingBox.width;
|
29
|
-
rect.height = boundingBox.height;
|
30
|
-
rect.left = boundingBox.left;
|
31
|
-
rect.top = boundingBox.top;
|
32
|
-
res.rect = rect;
|
33
|
-
res.rect.center_x = rect.left + Math.floor(rect.width/2);
|
34
|
-
res.rect.center_y = rect.top + Math.floor(rect.height/2);
|
35
|
-
}
|
36
|
-
res.nodeType = NODE_TYPES[object.nodeType] || res.nodeType + ' (Unexpected)';
|
37
|
-
res.nodeName = object.nodeName;
|
38
|
-
res.id = object.id || '';
|
39
|
-
res['class'] = object.className || '';
|
40
|
-
if (object.href)
|
41
|
-
{
|
42
|
-
res.href = object.href;
|
43
|
-
}
|
44
|
-
if (object.hasOwnProperty('value'))
|
45
|
-
{
|
46
|
-
res.value = object.value || '';
|
47
|
-
}
|
48
|
-
res.html = object.outerHTML || '';
|
49
|
-
res.textContent = object.textContent;
|
50
|
-
return res;
|
51
|
-
}
|
52
|
-
function toJSON(object)
|
53
|
-
{
|
54
|
-
var res, i, N, spanEl, parentEl;
|
55
|
-
if (typeof object==='undefined')
|
56
|
-
{
|
57
|
-
throw {message:'Calling toJSON with undefined'};
|
58
|
-
}
|
59
|
-
else if (object instanceof Text)
|
60
|
-
{
|
61
|
-
parentEl = object.parentElement;
|
62
|
-
if (parentEl)
|
63
|
-
{
|
64
|
-
spanEl = document.createElement("calabash");
|
65
|
-
spanEl.style.display = "inline";
|
66
|
-
spanEl.innerHTML = object.textContent;
|
67
|
-
parentEl.replaceChild(spanEl, object);
|
68
|
-
res = computeRectForNode(spanEl);
|
69
|
-
res.nodeType = NODE_TYPES[object.nodeType];
|
70
|
-
delete res.nodeName;
|
71
|
-
delete res.id;
|
72
|
-
delete res['class'];
|
73
|
-
|
74
|
-
parentEl.replaceChild(object,spanEl);
|
75
|
-
}
|
76
|
-
else
|
77
|
-
{
|
78
|
-
res = object;
|
79
|
-
}
|
80
|
-
|
81
|
-
|
82
|
-
}
|
83
|
-
else if (object instanceof Node)
|
84
|
-
{
|
85
|
-
res = computeRectForNode(object);
|
86
|
-
}
|
87
|
-
else if (object instanceof NodeList ||
|
88
|
-
(typeof object=='object' && object &&
|
89
|
-
typeof object.length === 'number' &&
|
90
|
-
object.length > 0
|
91
|
-
&& typeof object[0] !== 'undefined'))
|
92
|
-
{
|
93
|
-
res = [];
|
94
|
-
for (i=0,N=object.length;i<N;i++)
|
95
|
-
{
|
96
|
-
res[i] = toJSON(object[i]);
|
97
|
-
}
|
98
|
-
}
|
99
|
-
else
|
100
|
-
{
|
101
|
-
res = object;
|
102
|
-
}
|
103
|
-
return res;
|
104
|
-
}
|
105
|
-
|
106
|
-
function applyMethods(object, arguments) {
|
107
|
-
var length = arguments.length;
|
108
|
-
|
109
|
-
for(var i = 0; i < length; i++) {
|
110
|
-
var argument = arguments[i];
|
111
|
-
|
112
|
-
if (typeof argument === 'string') {
|
113
|
-
argument = {method_name: argument, arguments: []}
|
114
|
-
}
|
115
|
-
|
116
|
-
var methodName = argument.method_name;
|
117
|
-
var methodArguments = argument.arguments;
|
118
|
-
|
119
|
-
if (typeof object[methodName] === 'undefined') {
|
120
|
-
var type = Object.prototype.toString.call(object);
|
121
|
-
|
122
|
-
object =
|
123
|
-
{
|
124
|
-
error: "No such method '" + methodName + "'",
|
125
|
-
methodName: methodName,
|
126
|
-
receiverString: object.constructor.name,
|
127
|
-
receiverClass: type
|
128
|
-
};
|
129
|
-
|
130
|
-
break;
|
131
|
-
} else {
|
132
|
-
object = object[methodName].apply(object, methodArguments);
|
133
|
-
}
|
134
|
-
}
|
135
|
-
}
|
136
|
-
|
137
|
-
var exp = '%@'/* dynamic */,
|
138
|
-
queryType = '%@' /* dynamic */,
|
139
|
-
arguments = '%@' /* dynamic */,
|
140
|
-
nodes = null,
|
141
|
-
res = [],
|
142
|
-
i,N;
|
143
|
-
try
|
144
|
-
{
|
145
|
-
if (queryType==='xpath')
|
146
|
-
{
|
147
|
-
nodes = document.evaluate(exp, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
|
148
|
-
for (i=0,N=nodes.snapshotLength;i<N;i++)
|
149
|
-
{
|
150
|
-
res[i] = nodes.snapshotItem(i);
|
151
|
-
}
|
152
|
-
}
|
153
|
-
else
|
154
|
-
{
|
155
|
-
res = document.querySelectorAll(exp);
|
156
|
-
}
|
157
|
-
}
|
158
|
-
catch (e)
|
159
|
-
{
|
160
|
-
return JSON.stringify({error:'Exception while running query: '+exp, details:e.toString()})
|
161
|
-
}
|
162
|
-
|
163
|
-
if (arguments !== '%@') {
|
164
|
-
var length = res.length;
|
165
|
-
|
166
|
-
for (var i = 0; i < length; i++) {
|
167
|
-
res[i] = applyMethods(res[i], arguments);
|
168
|
-
}
|
169
|
-
}
|
170
|
-
|
171
|
-
return JSON.stringify(toJSON(res));
|
172
|
-
})();
|