forked from selendroid/selendroid.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
native.html.haml
214 lines (205 loc) · 6.45 KB
/
native.html.haml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
---
layout: base
title: Testing native Apps
author: Dominik Dary
---
.container-fluid
.row-fluid
.span3
#sidebar
%ul.nav.nav-tabs.nav-stacked
%li
%a{:href=>'#switchContext'} Switching to native context
%li
%a{:href=>'#findElements'} Finding Elements
%li
%a{:href=>'#id'} by Id
%li
%a{:href=>'#name'} by Name
%li
%a{:href=>'#linkText'} by Link Text
%li
%a{:href=>'#partialLinkText'} by partial Link Text
%li
%a{:href=>'#clazz'} by Class
%li
%a{:href=>'#tagName'} by Tag Name
%li
%a{:href=>'#xpath'} by XPath
%li
%a{:href=>'#elementInteractions'} Interact with Elements
%li
%a{:href=>'#specialKeys'} Special Keys
.span9
%h1 Interacting with Native Elements
%h2 Demo Video
%div.elastic-video <iframe width="420" height="315" src="http://www.youtube.com/embed/074BnGV0mS0?rel=0" frameborder="0" allowfullscreen></iframe>
%h2#switchContext Switch to the <em>native</em> context
%h3 Ruby:
%pre
%code.ruby
driver.switch_to.window('NATIVE_APP')
%h3 Java:
%pre
%code.java
driver.switchTo().window("NATIVE_APP");
%p When a selendroid test session is started, by default the native mode is activated.
%h2 Supported Element Locators
%dl
%dt Id
%dd Finds the element by Id.
%dt name
%dd Finds the element by content description (accessibility label).
%dt link text
%dd Finds the element by text.
%dt partial link text
%dd Finds the element by partial text.
%dt class
%dd Finds the element by full class name (e.g. android.widget.Button).
%dt xpath
%dd Finds the element by a xpath expression.
%dt tag name
%dd Finds the element by tag name.
%h2#findElements Native locator examples
%p Sample app view hierarchy in the inspector:
%img{:src=>"images/uiHierarchy.png"}
%h3#id By Id
%p Means the id that is described in the layout xml file of the corresponding activity.
%h4 Ruby:
%pre
%code.ruby
driver.find_element(:id,'buttonTest')
%h4 Java:
%pre
%code.Java
driver.findElement(By.id("buttonTest"));
%h3#name By Name
%p Is mapped to the accessibility label (content description) of the view element.
%h4 Ruby:
%pre
%code.ruby
driver.find_element(:name,'buttonTestCD')
%h4 Java:
%pre
%code.java
driver.findElement(By.name("buttonTestCD"));
%h3#linkText By Link text
%p Mapped to the displayed text of the element.
%h4 Ruby:
%pre
%code.ruby
driver.find_element(:link_text,'EN Button')
%h4 Java:
%pre
%code.java
driver.findElement(By.linkText("EN Button"));
%h3#partialLinkText By Partial Link Text
%p Mapped to the displayed text of the element.
%h4 Ruby:
%pre
%code.ruby
driver.find_element(:partial_link_text,'EN Butto')
%h4 Java:
%pre
%code.java
driver.findElement(By.partialLinkText("EN Butto"));
%h3.clazz By Class
%p Mapped to the ui element class of the view.
%h4 Ruby:
%pre
%code.ruby
driver.find_element(:class_name,'android.widget.Button')
%h4 Java:
%pre
%code.java
driver.findElement(By.className("android.widget.Button"));
%h3#tagName By Tag Name
%p Mapped to the simple name of the ui element class of the view.
%h4 Ruby:
%pre
%code.ruby
driver.find_element(:tag_name,'Button')
%h4 Java:
%pre
%code.java
driver.findElement(By.tagName("Button"));
%h3.xpath By XPath
%p XPath is the language used for locating nodes in an XML document. XPath extends beyond (as well as supporting) the simple methods of locating by id or name attributes, and opens up all sorts of new possibilities such as locating the third Button on the activity.
%h4 Ruby:
%pre
%code.ruby
driver.find_element(:xpath,"//Button[@id='buttonTest']")
%h4 Java:
%pre
%code.java
driver.findElement(By.xpath("//Button[@id='buttonTest']"));
%h2#elementInteractions Supported Element Interactions
%ul
%li Get Text
%li Click
%li Send Keys
%li Get Attribute of Element
%li Clear
%li Is Selected
%li Is Displayed
%li Is Enabled
%li Get Size
%li Get Location
%h2#specialKeys Interacting with the App using special keys
%p Selendroid offers you to interact with the app using some special keys e.g. like the Android menu button.
%h4 Ruby:
%pre
%code.ruby
driver.keyboard.send_keys("\uE102")
%h4 Java:
%pre
%code.java
= preserve do
:escaped
/* When using SelendroidDriver */
new Actions(driver).sendKeys(SelendroidKeys.MENU).perform();
%h4 Python:
%pre
%code.python
= preserve do
:escaped
from selenium.webdriver.common.action_chains import ActionChains;
""" Instantiate the driver like: driver = driver=webdriver.Remote( ... ); """
chain = ActionChains(driver);
""" Send search key"""
chain.send_keys(u'\ue103').perform();
%h3 Overview about available keys
%p The original list is documented in the interface: <a href="https://github.com/selendroid/selendroid/blob/master/selendroid-client/src/main/java/io/selendroid/SelendroidKeys.java">SelendroidKeys</a>
%dl.dl-horizontal
%dt KEY
%dd Unicode Character
%dt ALT_LEFT
%dd \uE00A
%dt DEL
%dd \uE017
%dt DPAD_DOWN
%dd \uE017
%dt DPAD_LEFT
%dd \uE012
%dt DPAD_RIGHT
%dd \uE014
%dt DPAD_UP
%dd \uE013
%dt ENTER
%dd \uE007
%dt SHIFT_LEFT
%dd \uE008
%dt BACK
%dd \uE100
%dt ANDROID_HOME
%dd \uE101
%dt MENU
%dd \uE102
%dt SEARCH
%dd \uE103
%dt SYM
%dd \uE104
%dt ALT_RIGHT
%dd \uE105
%dt SHIFT_RIGHT
%dd \uE106