calabash-android 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ 0.2.3:
2
+ The 0.2.2 gem was broken :(
3
+ Making a new release
4
+
1
5
  0.2.2:
2
6
  Fixed path problems with Ant on Windows.
3
7
 
@@ -1,6 +1,6 @@
1
1
  module Calabash
2
2
  module Android
3
- VERSION = "0.2.2"
4
- FRAMEWORK_VERSION = "0.2.2"
3
+ VERSION = "0.2.3"
4
+ FRAMEWORK_VERSION = "0.2.3"
5
5
  end
6
6
  end
@@ -0,0 +1,125 @@
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
+ res['rect'] = boundingBox;
28
+ res['rect'].center_x = boundingBox.left + Math.floor(boundingBox.width/2);
29
+ res['rect'].center_y = boundingBox.top + Math.floor(boundingBox.height/2);
30
+ }
31
+ res.nodeType = NODE_TYPES[object.nodeType] || res.nodeType + ' (Unexpected)';
32
+ res.nodeName = object.nodeName;
33
+ res.id = object.id || '';
34
+ res['class'] = object.className || '';
35
+ if (object.href)
36
+ {
37
+ res.href = object.href;
38
+ }
39
+ res.html = object.outerHTML || '';
40
+ res.textContent = object.textContent;
41
+ return res;
42
+ }
43
+ function toJSON(object)
44
+ {
45
+ var res, i, N, spanEl, parentEl;
46
+ if (typeof object==='undefined')
47
+ {
48
+ throw {message:'Calling toJSON with undefined'};
49
+ }
50
+ else if (object instanceof Text)
51
+ {
52
+ parentEl = object.parentElement;
53
+ if (parentEl)
54
+ {
55
+ spanEl = document.createElement("calabash");
56
+ spanEl.style.display = "inline";
57
+ spanEl.innerHTML = object.textContent;
58
+ parentEl.replaceChild(spanEl, object);
59
+ res = computeRectForNode(spanEl);
60
+ res.nodeType = NODE_TYPES[object.nodeType];
61
+ delete res.nodeName;
62
+ delete res.id;
63
+ delete res['class'];
64
+
65
+ parentEl.replaceChild(object,spanEl);
66
+ }
67
+ else
68
+ {
69
+ res = object;
70
+ }
71
+
72
+
73
+ }
74
+ else if (object instanceof Node)//TODO: support for frames!
75
+ {
76
+ res = computeRectForNode(object);
77
+ }
78
+ else if (object instanceof NodeList || //TODO: support for frames!
79
+ (typeof object=='object' && object &&
80
+ typeof object.length === 'number' &&
81
+ object.length > 0 //array like
82
+ && typeof object[0] !== 'undefined'))
83
+ {
84
+ res = [];
85
+ for (i=0,N=object.length;i<N;i++)
86
+ {
87
+ res[i] = toJSON(object[i]);
88
+ }
89
+ }
90
+ else
91
+ {
92
+ res = object;
93
+ }
94
+ return res;
95
+ }
96
+ ///TODO: no support for now frames
97
+ //idea would be map XPath across window.frames
98
+ //must take care of visibility questions
99
+
100
+ var exp = '%@'/* dynamic */,
101
+ queryType = '%@',
102
+ nodes = null,
103
+ res = [],
104
+ i,N;
105
+ try
106
+ {
107
+ if (queryType==='xpath')
108
+ {
109
+ nodes = document.evaluate(exp, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
110
+ for (i=0,N=nodes.snapshotLength;i<N;i++)
111
+ {
112
+ res[i] = nodes.snapshotItem(i);
113
+ }
114
+ }
115
+ else
116
+ {
117
+ res = document.querySelectorAll(exp);
118
+ }
119
+ }
120
+ catch (e)
121
+ {
122
+ return JSON.stringify({error:'Exception while running query: '+exp, details:e.toString()})
123
+ }
124
+ return JSON.stringify(toJSON(res));
125
+ })();
@@ -0,0 +1,133 @@
1
+ (function () {
2
+ function simulateKeyEvent(elem, character) {
3
+ var ch = character.charCodeAt(0);
4
+
5
+ var evt;
6
+ evt = document.createEvent('KeyboardEvent');
7
+ evt.initKeyboardEvent('keydown', true, true, window, 0, 0, 0, 0, 0, ch);
8
+ elem.dispatchEvent(evt);
9
+
10
+ evt = document.createEvent('KeyboardEvent');
11
+ evt.initKeyboardEvent('keyup', true, true, window, 0, 0, 0, 0, 0, ch);
12
+ elem.dispatchEvent(evt);
13
+ evt = document.createEvent('KeyboardEvent');
14
+ evt.initKeyboardEvent('keypress', true, true, window, 0, 0, 0, 0, 0, ch);
15
+ elem.dispatchEvent(evt);
16
+ }
17
+
18
+
19
+ function enterTextIntoInputField(elem, text) {
20
+ elem.value = "";
21
+ for (var i = 0; i < text.length; i++) {
22
+ var ch = text.charAt(i);
23
+ elem.value += ch;
24
+ simulateKeyEvent(elem, ch);
25
+ }
26
+ }
27
+
28
+
29
+ function fireHTMLEvent(elem, eventName) {
30
+ var evt = document.createEvent("HTMLEvents");
31
+ evt.initEvent(eventName, true, true );
32
+ return !elem.dispatchEvent(evt);
33
+ }
34
+
35
+ function selectInputField(elem) {
36
+ elem.click();
37
+ elem.focus();
38
+ }
39
+
40
+
41
+ function deselectInputField(elem) {
42
+ fireHTMLEvent(elem, 'change');
43
+ fireHTMLEvent(elem, 'blur');
44
+ }
45
+
46
+
47
+ /** David Mark's isHostMethod function,
48
+ * http://peter.michaux.ca/articles/feature-detection-state-of-the-art-browser-scripting
49
+ * Modified to use strict equality
50
+ */
51
+ function isHostMethod (object, property)
52
+ {
53
+ var t = typeof object[property];
54
+ return t==='function' ||
55
+ (!!(t==='object' && object[property])) ||
56
+ t==='unknown';
57
+ }
58
+ //http://www.w3.org/TR/DOM-Level-2-Core/core.html
59
+ var NODE_TYPES = {
60
+ /*ELEMENT_NODE : */ 1 : 'ELEMENT_NODE',
61
+ /*ATTRIBUTE_NODE : */ 2: 'ATTRIBUTE_NODE',
62
+ /*TEXT_NODE : */ 3 : 'TEXT_NODE',
63
+ /*DOCUMENT_NODE : */ 9 : 'DOCUMENT_NODE'
64
+ };
65
+
66
+ function toJSON(object)
67
+ {
68
+ var res, i, N;
69
+ if (typeof object==='undefined')
70
+ {
71
+ throw {message:'Calling toJSON with undefined'};
72
+ }
73
+ else if (object instanceof Node)//TODO: support for frames!
74
+ {
75
+ res = {}
76
+ if (isHostMethod(object,'getBoundingClientRect'))
77
+ {
78
+ res['rect'] = object.getBoundingClientRect();
79
+ }
80
+ res.nodeType = NODE_TYPES[object.nodeType] || res.nodeType + ' (Unexpected)';
81
+ res.nodeName = object.nodeName;
82
+ res.id = object.id || '';
83
+ res['class'] = object.className || '';
84
+ res.html = object.outerHTML || '';
85
+ res.nodeValue = object.nodeValue;
86
+ }
87
+ else if (object instanceof NodeList || //TODO: support for frames!
88
+ (typeof object=='object' && object &&
89
+ typeof object.length === 'number' &&
90
+ object.length > 0 //array like
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
+ ///TODO: no support for now frames
107
+ //idea would be map XPath across window.frames
108
+ //must take care of visibility questions
109
+
110
+ try
111
+ {
112
+ var exp = JSON.parse('%@')/* dynamic */,
113
+ el,
114
+ text = '%@',
115
+ i,N;
116
+
117
+ el=document.elementFromPoint(exp.rect.left, exp.rect.top);
118
+ if (/input/i.test(el.tagName))
119
+ {
120
+ selectInputField(el);
121
+ enterTextIntoInputField(el, text);
122
+ }
123
+ else
124
+ {
125
+
126
+ }
127
+ }
128
+ catch (e)
129
+ {
130
+ return JSON.stringify({error:'Exception while running query: '+exp, details:e.toString()})
131
+ }
132
+ return JSON.stringify(toJSON(el));
133
+ })();
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: calabash-android
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -603,6 +603,8 @@ files:
603
603
  - test-server/instrumentation-backend/src/sh/calaba/org/codehaus/jackson/util/TokenBuffer.java
604
604
  - test-server/instrumentation-backend/src/sh/calaba/org/codehaus/jackson/util/VersionUtil.java
605
605
  - test-server/instrumentation-backend/src/sh/calaba/org/codehaus/jackson/util/package-info.java
606
+ - test-server/calabash-js/src/calabash.js
607
+ - test-server/calabash-js/src/set_text.js
606
608
  homepage: http://github.com/calabash
607
609
  licenses: []
608
610
  post_install_message: